Yolo scripts

folder detection images
https://groups.google.com/forum/?nomobile=true#!topic/darknet/w60i9rlxx8w

ls /home/siddiquemu/Desktop/Homography/stitching/cam8/*.png > \ /home/siddiquemu/Desktop/Homography/stitching/cam8/cam8list.txt cd /home/siddiquemu/Desktop/Homography/stitching/cam8 declare -i var=10000 for path in $(cat camlist.txt) do #echo $path cd ../ cd /home/siddiquemu/darknet ./darknet detect cfg/yolo.cfg yolo.weights -thresh 0.25 $path echo $path #Copy result from darknet root to anaother folder with original name cp /home/siddiquemu/darknet/predictions.png \ /home/siddiquemu/Desktop/yoloResult/cam8/$var.png var=$var+1
 * 1) !/bin/bash
 * 2) cd /home/siddique/Desktop

Solved it through python.darknet or darknet.py, you can get it from pjreddie github link for darknet. Git clone it and keep GPU = 1 (If you need to run with GPU) in Makefile

Then run make in this folder (cd darknet). After successful make, try this:

import python.darknet import os, sys import numpy as np from PIL import Image import matplotlib.pyplot as plt import matplotlib.patches as patches

net = python.darknet.load_net(b"config/yolo-obj.cfg",b"backup/yolo-obj_4100.weights",0) meta = python.darknet.load_meta(b"config/obj.data")

folder = "test_images/" files = os.listdir(folder)

for f in files: if f.endswith(".jpg") or f.endswith(".jpeg") or f.endswith(".png"): print (f) path = bytes(os.path.join(folder, f), encoding="utf-8") r = python.darknet.detect(net, meta, path) print(r) name = r[0][0] predict = r[0][1] x = r[0][2][0] y = r[0][2][1] w = r[0][2][2] z = r[0][2][3] x_max = (2*x+w)/2 x_min = (2*x-w)/2 y_min = (2*y-z)/2 y_max = (2*y+z)/2 print(x_min, y_min, x_max, y_max) image = Image.open(path) cropped = image.crop((x_min, y_min+20, x_max, y_max)) saving_path = "crop_images/"+f save_file = open(saving_path, 'w') cropped.save(saving_path) save_file.close This will return cropped images based on predicted coordinates P.S: Use GPU for faster results or else it takes at least for seconds for one detection even though weights were being loaded only once

Hope this helps

links
Yolo