Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run yolo_main.py on video #11

Open
jshankar opened this issue Nov 8, 2016 · 1 comment
Open

Run yolo_main.py on video #11

jshankar opened this issue Nov 8, 2016 · 1 comment

Comments

@jshankar
Copy link

jshankar commented Nov 8, 2016

I modified yolo_main.py to work on video instead of image as follows . It doesn't however work.Is there anything else I need to change ?

net = caffe.Net(model_filename, weight_filename, caffe.TEST)
transformer = caffe.io.Transformer({'data': net.blobs['data'].data.shape})
transformer.set_transpose('data', (2,0,1))
transformer.set_channel_swap('data', (2,1,0))
cap = cv2.VideoCapture(video_filename);

ret, img = cap.read();
while(ret):
inputs = img
out = net.forward_all(data=np.asarray([transformer.preprocess('data', inputs)]))
print out.iteritems()
img_cv = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
results = interpret_output(out['result'][0], img.shape[1], img.shape[0])
show_results(img_cv,results, img.shape[1], img.shape[0])
cv2.waitKey(10000)
ret, img = cap.read()
end = datetime.now()

@Banus
Copy link

Banus commented Nov 27, 2016

YOLO expects inputs in the range [0,1] while the OpenCV img has range [0, 255]. The function caffe.io.load_image takes already care of that by calling skimage.img_as_float.
You need simply to rescale the OpenCV image by adding the following option to the transformer:

transformer.set_raw_scale('data', 1.0 / 255.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants