i am beginner with yolo. i wanted to ask that how can we use the output of yolo in a python script. like while running the webcam i want to print detected sports ball and exit yolo video output as soon as the webcam detects a sports ball. in general i wanted to make the changes with what we can output while running yolo.
Yolo does have a python interface,
https://github.com/pjreddie/darknet/blob/master/python/darknet.py
Hope that helps
@true-source
i tried running that but it throws me the following error:
Traceback (most recent call last):
File "/home/laksh/darknet/python/darknet.py", line 48, in
lib = CDLL("libdarknet.so", RTLD_GLOBAL)
File "/usr/lib/python2.7/ctypes/__init__.py", line 362, in __init__
self._handle = _dlopen(self._name, mode)
OSError: libdarknet.so: cannot open shared object file: No such file or directory
[Finished in 0.6s with exit code 1]
[shell_cmd: python -u "/home/laksh/darknet/python/darknet.py"]
[dir: /home/laksh/darknet/python]
[path: /home/laksh/bin:/home/laksh/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin]
you have to "make" darknet at first and generate the libdarknet.so and darknet(executable file) files. Change directory to your darknet folder in terminal and type in "make".
The libdarknet.so should be placed at python script working directory, or modify https://github.com/pjreddie/darknet/blob/f6d861736038da22c9eb0739dca84003c5a5e275/python/darknet.py#L48
to your libdarknet.so absolute path.
@true-source @sharowyeh i did make darknet before running to these errors. After changing to the absolute path of libdarknet.so it did got rid me of the above error but now it shows me that :
*Loading weights from yolov2.weights...Couldn't open file: yolov2.weights*
nd the error message is as follows:
layer filters size input output
0 conv 32 3 x 3 / 1 416 x 416 x 3 -> 416 x 416 x 32 0.299 BFLOPs
1 max 2 x 2 / 2 416 x 416 x 32 -> 208 x 208 x 32
2 conv 64 3 x 3 / 1 208 x 208 x 32 -> 208 x 208 x 64 1.595 BFLOPs
3 max 2 x 2 / 2 208 x 208 x 64 -> 104 x 104 x 64
4 conv 128 3 x 3 / 1 104 x 104 x 64 -> 104 x 104 x 128 1.595 BFLOPs
5 conv 64 1 x 1 / 1 104 x 104 x 128 -> 104 x 104 x 64 0.177 BFLOPs
6 conv 128 3 x 3 / 1 104 x 104 x 64 -> 104 x 104 x 128 1.595 BFLOPs
7 max 2 x 2 / 2 104 x 104 x 128 -> 52 x 52 x 128
8 conv 256 3 x 3 / 1 52 x 52 x 128 -> 52 x 52 x 256 1.595 BFLOPs
9 conv 128 1 x 1 / 1 52 x 52 x 256 -> 52 x 52 x 128 0.177 BFLOPs
10 conv 256 3 x 3 / 1 52 x 52 x 128 -> 52 x 52 x 256 1.595 BFLOPs
11 max 2 x 2 / 2 52 x 52 x 256 -> 26 x 26 x 256
12 conv 512 3 x 3 / 1 26 x 26 x 256 -> 26 x 26 x 512 1.595 BFLOPs
13 conv 256 1 x 1 / 1 26 x 26 x 512 -> 26 x 26 x 256 0.177 BFLOPs
14 conv 512 3 x 3 / 1 26 x 26 x 256 -> 26 x 26 x 512 1.595 BFLOPs
15 conv 256 1 x 1 / 1 26 x 26 x 512 -> 26 x 26 x 256 0.177 BFLOPs
16 conv 512 3 x 3 / 1 26 x 26 x 256 -> 26 x 26 x 512 1.595 BFLOPs
17 max 2 x 2 / 2 26 x 26 x 512 -> 13 x 13 x 512
18 conv 1024 3 x 3 / 1 13 x 13 x 512 -> 13 x 13 x1024 1.595 BFLOPs
19 conv 512 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 512 0.177 BFLOPs
20 conv 1024 3 x 3 / 1 13 x 13 x 512 -> 13 x 13 x1024 1.595 BFLOPs
21 conv 512 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 512 0.177 BFLOPs
22 conv 1024 3 x 3 / 1 13 x 13 x 512 -> 13 x 13 x1024 1.595 BFLOPs
23 conv 1024 3 x 3 / 1 13 x 13 x1024 -> 13 x 13 x1024 3.190 BFLOPs
24 conv 1024 3 x 3 / 1 13 x 13 x1024 -> 13 x 13 x1024 3.190 BFLOPs
25 route 16
26 conv 64 1 x 1 / 1 26 x 26 x 512 -> 26 x 26 x 64 0.044 BFLOPs
27 reorg / 2 26 x 26 x 64 -> 13 x 13 x 256
28 route 27 24
29 conv 1024 3 x 3 / 1 13 x 13 x1280 -> 13 x 13 x1024 3.987 BFLOPs
30 conv 425 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 425 0.147 BFLOPs
31 detection
mask_scale: Using default '1.000000'
Loading weights from yolov2.weights...Couldn't open file: yolov2.weights
[Finished in 3.2s]
The path of weights file is related to working directory too.
@sharowyeh Thanks actually the problem was that i was trying to run the pyhton script from the text editor (Sublime) and their were files which had to be automatically opened and i could not specify their address. but the problem was solved if we run the python file through terminal..
Now i am trying to run the video by webcam using this python file. the changes i have made to the file are adding import numpy as np, import cv2 as the header files and cap = cv2.VideoCapture(0). My main function looks like::
if __name__ == "__main__":
net = load_net("cfg/yolov3.cfg", "yolov3.weights", 0)
meta = load_meta("cfg/coco.data")
while(True):
ret, frame = cap.read()
cv2.imshow('frame',frame)
r = detect(net, meta, frame)
cv2.imwrite('check.jpg',frame)
r = detect(net, meta, 'check.jpg')
print r
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
But it gives me error::
(python:4740): Gtk-ERROR **: GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in the same process is not supported
Trace/breakpoint trap (core dumped)
did u resolve this issue?
read my answer here.
you will understood how to use it in python
with the result data you can combine with another script...
Yolo does have a python interface,
https://github.com/pjreddie/darknet/blob/master/python/darknet.py
Hope that helps
@cjpurackal Your link is not work
Yolo does have a python interface,
https://github.com/pjreddie/darknet/blob/master/python/darknet.py
Hope that helps@cjpurackal Your link is not work
The link is this (I think): https://github.com/pjreddie/darknet/blob/master/python/darknet.py
I read the instructions above, where in the code am i able to extract the counting Objects (total objects and per class) inside image.c or darknet.h. I want to assign an object and then write those data to sent them by lora modul