A hierarchical detection method based on Yolov3, which can work on joint classification and detection dataset, such as COCO and NSFW. So that Yolo could detect coco categories and sexy or porn person simultaneously. (Tensorflow 1.x)
Python version: >=Python3.6
Packages:
- tensorflow >=1.13 (do not support Tensorflow2.0)
- opencv-python
- numpy
- pyyaml
if model weights is ready and basic code is cloned. Please edit configs/XXX.yaml, add your local model weights path to MODEL:MODEL_WEIGHTS:, such as "path/to/yolov3".
$ python tools/infer.py test_pic.jpg(or folder) --config-file configs/Yolov3_Coco.yaml --result-file data/demo_result
$ python tools/infer.py test_pic.jpg(or folder) --config-file configs/Yolov3_Joint_CocoAndNsfw.yaml --result-file data/demo_result
Two model weights are provided: common COCO model and Sexy&COCO model.
Common COCO weights is converted from author of Yolov3(pjreddie.com), Sexy&COCO weights are trained on image size of 416 * 416, so mAP is less than the former but close to Yolov3 paper's 416 image size model mAP.
Name | inference time(s/im) | category | AP@IoU=0.50:0.95 | AP@IoU=0.50 | AP@IoU=0.75 | download |
---|---|---|---|---|---|---|
COCO | 0.046 | 80 | 0.357 | 0.616 | 0.376 | model |
SexyCOCO | 0.047 | 83 | 0.309 | 0.551 | 0.308 | model |
Sexy Yolo support train your own detection dataset and also support joint classification and detection dataset.
The detection annotation's format must be same as COCO's format. Add training dataset photo folder and annotation file to config file and run:
$ python tools/train.py --config-file configs/Yolov3_Coco.yaml
As for classification dataset, put all the classification photos into each folder, the folder's name is catogory's name. Make your dataset folder structure as:
-
NSFW
-
-train
-
--neutral
-
--sexy
-
--porn
-
-val
-
--neutral
-
--sexy
-
--porn
Then run:
$ python tools/joint_json_creator.py path/to/NSFW
After dataset is ready, edit Yolov3_Joint_CocoAndNsfw.yaml with new dataset path. Run this start to train:
python tools/train.py --config-file configs/Yolov3_Joint_CocoAndNsfw.yaml
You can change config parameters by editing config file.
COCO dataset: http://cocodataset.org/
NSFW dataset: https://github.com/alex000kim/nsfw_data_scraper
CocoApi is needed, please install cocoapi first: https://github.com/cocodataset/cocoapi
Run this to evaluate your model:
$ python tools/eval_on_coco.py --config-file configs/Yolov3_Joint_CocoAndNsfw.yaml
- please see the blog Description and discussion