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

Darknet support #38

Open
pcuenca opened this issue Sep 29, 2018 · 2 comments
Open

Darknet support #38

pcuenca opened this issue Sep 29, 2018 · 2 comments

Comments

@pcuenca
Copy link

pcuenca commented Sep 29, 2018

Thanks a lot for this, guys, it works great for quick tests of various models.

I wonder if you have considered extending the backend to also support Darknet. I know there are various conversion tools to Keras or TensorFlow, but I'd rather drop the native model files and use the darknet library instead of having to go through additional steps.

If you don't mind me doing it, I can take an initial look at how such an extension could work.

Congratulations anyway for your work!

pcuenca added a commit to pcuenca/dl-objectdetector that referenced this issue Oct 1, 2018
pcuenca added a commit to pcuenca/dl-objectdetector that referenced this issue Oct 1, 2018
Not intended for general use. Please, keep in mind the following important known issues:
- Detections are still extremely slow. The main reason is that the image supplied to Darknet is created by iterating through the Python numpy array.
- Labels are assumed to be Coco.
- Labels are read from data files copied from the Darknet distribution, and then supplied to the darknet library. However, the GUI still uses the same data files used throughout the project. We should reuse those files instead of keeping separate copies.
- Some hardcoded paths and values.

To test YOLOv3-tiny, please follow these steps:

0. Download and compile Darknet to obtain libdarknet.so.
1. Copy yolov3-tiny.cfg from the Darknet distribution into Net/Darknet.
2. Download yolov3-tiny.weights and place it into Net/Darknet.
3. Update your DYLD_LIBRARY_PATH to include the directory where libdarknet.so resides.
4. Run the objectdector as usual, using the yml configuration file in this revision.

Other models are possible. The corresponding darknet weights and configuration files must be placed in the Net/Darknet directory. They must have the same name (except for the extension), which must in turn match the Model name defined in the YAML configuration file.

I plan to work on speed next. As mentioned above, libdarknet requires an image structure that is manually built from a Python numpy array. I tried to supply a pointer to the underlying Python array instead, but I didn't know how to make it work using ctypes. I'm concerned that the byte ordering will differ anyway. It would be trivial to create a public helper function in libdarknet, but I don't want to depend on patched versions of Darknet.

Credits
- All data files have been taken from the Darknet distribution.
- The darknet.py file was copied from the Darknet distribution, but it includes modifications to trigger detection from a numpy image instead  of a file.

Part of JdeRobot#38
pcuenca added a commit to pcuenca/dl-objectdetector that referenced this issue Oct 1, 2018
… of iterating.

Speed is much faster, as expected.

Part of JdeRobot#38
@jmplaza
Copy link
Member

jmplaza commented Oct 1, 2018

Great @pcuenca ! Your contributions in this topic are more than welcome.

It was on the roadmap, to extend the supported neural networks frameworks in ObjectDetector. Maybe the main challenge is to integrate Darknet support, which is C++ code, into Python code of ObjectDetector. We solved the opposite (use Python frameworks from C++ code) in DetectionSuite.

Thanks for your contributions, they will be very useful.

@pcuenca
Copy link
Author

pcuenca commented Oct 1, 2018

That's great news!

The Python -> Darknet integration is already working in Pull Request #39, which I submitted before. I need to improve a few things (dataset configuration, mostly), but that branch can already be used for testing. I used YOLOv3-tiny as an example, and it seems to work fine. If you have any comments, questions or suggestions, please let me know.

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