forked from pjreddie/darknet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OK SHOULD I START WORKING ON CVPR OR WHAT?
- Loading branch information
Showing
12 changed files
with
992 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Stupid python path shit. | ||
# Instead just add darknet.py to somewhere in your python path | ||
# OK actually that might not be a great idea, idk, work in progress | ||
# Use at your own risk. or don't, i don't care | ||
|
||
from scipy.misc import imread | ||
import cv2 | ||
|
||
def array_to_image(arr): | ||
arr = arr.transpose(2,0,1) | ||
c = arr.shape[0] | ||
h = arr.shape[1] | ||
w = arr.shape[2] | ||
arr = (arr/255.0).flatten() | ||
data = dn.c_array(dn.c_float, arr) | ||
im = dn.IMAGE(w,h,c,data) | ||
return im | ||
|
||
def detect2(net, meta, image, thresh=.5, hier_thresh=.5, nms=.45): | ||
boxes = dn.make_boxes(net) | ||
probs = dn.make_probs(net) | ||
num = dn.num_boxes(net) | ||
dn.network_detect(net, image, thresh, hier_thresh, nms, boxes, probs) | ||
res = [] | ||
for j in range(num): | ||
for i in range(meta.classes): | ||
if probs[j][i] > 0: | ||
res.append((meta.names[i], probs[j][i], (boxes[j].x, boxes[j].y, boxes[j].w, boxes[j].h))) | ||
res = sorted(res, key=lambda x: -x[1]) | ||
dn.free_ptrs(dn.cast(probs, dn.POINTER(dn.c_void_p)), num) | ||
return res | ||
|
||
import sys, os | ||
sys.path.append(os.path.join(os.getcwd(),'python/')) | ||
|
||
import darknet as dn | ||
|
||
# Darknet | ||
net = dn.load_net("cfg/tiny-yolo.cfg", "tiny-yolo.weights", 0) | ||
meta = dn.load_meta("cfg/coco.data") | ||
r = dn.detect(net, meta, "data/dog.jpg") | ||
print r | ||
|
||
# scipy | ||
arr= imread('data/dog.jpg') | ||
im = array_to_image(arr) | ||
r = detect2(net, meta, im) | ||
print r | ||
|
||
# OpenCV | ||
arr = cv2.imread('data/dog.jpg') | ||
im = array_to_image(arr) | ||
dn.rgbgr_image(im) | ||
r = detect2(net, meta, im) | ||
print r | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.