Skip to content

Commit

Permalink
Change weights path, update README.md, clear code
Browse files Browse the repository at this point in the history
  • Loading branch information
culdo committed Apr 2, 2022
1 parent 9336760 commit 1fb12c8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 49 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.idea/
*.egg-info/
*.mp4
__pycache__/
__pycache__/
*.dll
build/
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,29 @@ Use with [python-OP3](https://github.com/culdo/python-OP3)
* Object size threshold and class filtering
* MJPEG streaming for YOLO+SiamMask result on port 8091
* Auto labeling powered by YOLO+SiamMask.
# Requirement
* CUDA Toolkit 10.1 + cuDNN 7.6.5 or you can download those dll in Releases
* Ubuntu 18.04 or 16.04
* Ubuntu 16.04 need compiled opencv for unicode labels on result image
* Put this project in same directory as [darknet](https://github.com/AlexeyAB/darknet)
# Requirements
* Compiled OpenCV with python wrapper and TrueType contrib module

You can download below files in [Releases](https://github.com/culdo/darknet_video/releases), and unzip to project root:
* Compiled darknet yolo_cpp_dll.dll
* CUDA Toolkit 10.1 + cuDNN 7.6.5
* the darknet weight you want to use (ex: yolov4.weight)
## Development Installation
`pip3 install --user -e .`
## Usage
```
from darknet_python.run_detector import ThreadingDetector
# First argument same as cv2.captureVideo() argument, here we use web camera.
# If not pass config_path, loading config of basename of weights by default.
# By default loading meta file of coco.data.
# By default, it load meta file of coco.data.
ThreadingDetector(0, weights_path='yolov3.weights')
```
You can find additional examples on `test/test_darknet.py`.

## Pyinstaller
You can use pyinstaller to generate standalone executable
```
pyinstaller -F --add-binary "../lib;lib" --add-data "../darknet_video/cfg;darknet_video/cfg" --add-data "../darknet_video/data;darknet_video/data" --add-data "../weights;weights" .\test_darknet.py
```
## Labeling assisted by YOLO-SiamMask
Automating labeling use native detection ability of YOLO and SiamMask.
### To-do list
Expand Down
4 changes: 2 additions & 2 deletions darknet_video/core/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class YOLODetector:
def __init__(self, stream, weights_path,
config_path=None, meta_path=None, meta_file="coco.data",
show_gui=False, is_tracking=False, darknet_dir="../../darknet",
show_gui=False, is_tracking=False, darknet_dir="..",
is_stream_result=False, is_labeling=False, only_tracking=False,
autoplay=1, is_write_path=True, data_name=None,
label_empty=False, label_subset=1, only_one=False, labels_map=(),
Expand Down Expand Up @@ -116,7 +116,7 @@ def _check_path(self):
if os.path.dirname(self.config_path) == "":
self.config_path = os.path.join(package_dir, "cfg", self.config_path)

self.weights_path = os.path.join(self.darknet_dir, self.weights_path)
self.weights_path = os.path.join(self.darknet_dir, "weights", self.weights_path)
print(self.weights_path)

if not os.path.exists(self.config_path):
Expand Down
44 changes: 5 additions & 39 deletions test/test_darknet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,21 @@
from darknet_video.utils.get_yt import get_yt_vid


def coco_yolo(url, weights, meta_file="coco_cht.data",show_gui=True, **kwargs):
def coco_yolo(url, weights, meta_file="coco_cht.data", show_gui=True, **kwargs):
ThreadingDetector(url,
weights_path=weights,
meta_file=meta_file,
show_gui=show_gui,
**kwargs)


def hands_yolo(url, weights, **kwargs):
ThreadingDetector(url,
weights_path=weights,
meta_file="hands.data",
config_path="yolov4-hands.cfg",
**kwargs)


def hand_yolo(url, weights, **kwargs):
ThreadingDetector(url,
weights_path=weights,
meta_file="hand.data",
config_path="cross-hands.cfg",
**kwargs)


def mango_yolo(url, weights, **kwargs):
ThreadingDetector(url,
weights_path=weights,
meta_file="mango.data",
config_path=mango_config,
**kwargs)


if __name__ == '__main__':

v4_weights = "bin/yolov4.weights"
v4tiny_weights = "bin/yolov4-tiny.weights"
v3tiny_weights = "bin/yolov3-tiny.weights"
enet_weights = "bin/enet-coco.weights"
# hand_video = "/home/lab-pc1/nptu/lab/ip_cam/videos/hands/0.mp4"
mango_img = "mango_dev/*.jpg"
mango_weights = "backup/yolov4-mango_bak.weights"
mango_config = "enet-mango.cfg"
mango_data = "mango.data"
hand_num = -1
label_subset = 1
v4_weights = "yolov4.weights"
v4tiny_weights = "yolov4-tiny.weights"
v3tiny_weights = "yolov3-tiny.weights"
enet_weights = "enet-coco.weights"
labeling = False
hands_video = "/home/lab-pc1/nptu/lab/videos/hands/hover/hand_%s-%s.mp4" % (hand_num, label_subset)
hands_weights = "backup/yolov4-hands_best.weights"
hand_weights = "bin/cross-hands.weights"

phone_ip = "http://192.168.13.246:8080/video"
yt_video = get_yt_vid("https://www.youtube.com/watch?v=9XPBNaLXzPo")
Expand Down

0 comments on commit 1fb12c8

Please sign in to comment.