You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 4.0 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # YOLOv3 Example
  2. ## Description
  3. YOLOv3 network based on ResNet-18, with support for training and evaluation.
  4. ## Requirements
  5. - Install [MindSpore](https://www.mindspore.cn/install/en).
  6. - Dataset
  7. We use coco2017 as training dataset.
  8. 1. The directory structure is as follows:
  9. > ```
  10. > .
  11. > ├── annotations # annotation jsons
  12. > ├── train2017 # train dataset
  13. > └── val2017 # infer dataset
  14. > ```
  15. 2. Organize the dataset infomation into a TXT file, each row in the file is as follows:
  16. ```
  17. train2017/0000001.jpg 0,259,401,459,7 35,28,324,201,2 0,30,59,80,2
  18. ```
  19. Each row is an image annotation which split by space, the first column is a relative path of image, the others are box and class infomations of the format [xmin,ymin,xmax,ymax,class]. `dataset.py` is the parsing script, we read image from an image path joined by the `image_dir`(dataset directory) and the relative path in `anno_path`(the TXT file path), `image_dir` and `anno_path` are external inputs.
  20. ## Running the Example
  21. ### Training
  22. To train the model, run `train.py` with the dataset `image_dir`, `anno_path` and `mindrecord_dir`. If the `mindrecord_dir` is empty, it wil generate [mindrecord](https://www.mindspore.cn/tutorial/en/master/use/data_preparation/converting_datasets.html) file by `image_dir` and `anno_path`(the absolute image path is joined by the `image_dir` and the relative path in `anno_path`). **Note if `mindrecord_dir` isn't empty, it will use `mindrecord_dir` rather than `image_dir` and `anno_path`.**
  23. - Stand alone mode
  24. ```
  25. sh run_standalone_train.sh 0 50 ./Mindrecord_train ./dataset ./dataset/train.txt
  26. ```
  27. The input variables are device id, epoch size, mindrecord directory path, dataset directory path and train TXT file path.
  28. - Distributed mode
  29. ```
  30. sh run_distribute_train.sh 8 150 /data/Mindrecord_train /data /data/train.txt /data/hccl.json
  31. ```
  32. The input variables are device numbers, epoch size, mindrecord directory path, dataset directory path, train TXT file path and [hccl json configuration file](https://www.mindspore.cn/tutorial/en/master/advanced_use/distributed_training.html). **It is better to use absolute path.**
  33. You will get the loss value and time of each step as following:
  34. ```
  35. epoch: 145 step: 156, loss is 12.202981
  36. epoch time: 25599.22742843628, per step time: 164.0976117207454
  37. epoch: 146 step: 156, loss is 16.91706
  38. epoch time: 23199.971675872803, per step time: 148.7177671530308
  39. epoch: 147 step: 156, loss is 13.04007
  40. epoch time: 23801.95164680481, per step time: 152.57661312054364
  41. epoch: 148 step: 156, loss is 10.431475
  42. epoch time: 23634.241580963135, per step time: 151.50154859591754
  43. epoch: 149 step: 156, loss is 14.665991
  44. epoch time: 24118.8325881958, per step time: 154.60790120638333
  45. epoch: 150 step: 156, loss is 10.779521
  46. epoch time: 25319.57221031189, per step time: 162.30495006610187
  47. ```
  48. Note the results is two-classification(person and face) used our own annotations with coco2017, you can change `num_classes` in `config.py` to train your dataset. And we will suport 80 classifications in coco2017 the near future.
  49. ### Evaluation
  50. To eval, run `eval.py` with the dataset `image_dir`, `anno_path`(eval txt), `mindrecord_dir` and `ckpt_path`. `ckpt_path` is the path of [checkpoint](https://www.mindspore.cn/tutorial/en/master/use/saving_and_loading_model_parameters.html) file.
  51. ```
  52. sh run_eval.sh 0 yolo.ckpt ./Mindrecord_eval ./dataset ./dataset/eval.txt
  53. ```
  54. The input variables are device id, checkpoint path, mindrecord directory path, dataset directory path and train TXT file path.
  55. You will get the precision and recall value of each class:
  56. ```
  57. class 0 precision is 88.18%, recall is 66.00%
  58. class 1 precision is 85.34%, recall is 79.13%
  59. ```
  60. Note the precision and recall values are results of two-classification(person and face) used our own annotations with coco2017.