{"id":13435740,"url":"https://github.com/zhen8838/K210_Yolo_framework","last_synced_at":"2025-03-18T11:32:07.144Z","repository":{"id":36805551,"uuid":"196015434","full_name":"zhen8838/K210_Yolo_framework","owner":"zhen8838","description":"Yolo v3 framework base on tensorflow, support multiple models, multiple datasets, any number of output layers, any number of anchors, model prune, and portable model to K210 !","archived":false,"fork":false,"pushed_at":"2022-11-22T04:32:09.000Z","size":52623,"stargazers_count":249,"open_issues_count":28,"forks_count":73,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-10-27T18:59:01.733Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zhen8838.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-09T13:34:28.000Z","updated_at":"2024-09-28T18:44:31.000Z","dependencies_parsed_at":"2023-01-17T05:00:47.981Z","dependency_job_id":null,"html_url":"https://github.com/zhen8838/K210_Yolo_framework","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhen8838%2FK210_Yolo_framework","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhen8838%2FK210_Yolo_framework/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhen8838%2FK210_Yolo_framework/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhen8838%2FK210_Yolo_framework/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhen8838","download_url":"https://codeload.github.com/zhen8838/K210_Yolo_framework/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244211143,"owners_count":20416587,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T03:00:38.557Z","updated_at":"2025-03-18T11:32:02.133Z","avatar_url":"https://github.com/zhen8838.png","language":"C","funding_links":[],"categories":["C","有关K210学习和实例的github仓库枚举","Lighter and Deployment Frameworks","Applications"],"sub_categories":["各路网友大佬实例"],"readme":"[toc]\n\n# K210 YOLO V3 framework\n\nThis is a clear, extensible yolo v3 framework\n\n-   [x] Real-time display recall and precision\n-   [x] Easy to use with other datasets\n-   [x] Support multiple model backbones and expand more\n-   [x] Support n number of output layers and m anchors\n-   [x] Support model weight pruning\n-   [x] Portable model to kendryte [K210](https://kendryte.com/) chip\n# Training on Voc\n\n## Set Environment\n\nTesting in ubuntu 18.04, `Python 3.7.1`, Others in `requirements.txt`.\n\n## Prepare dataset\n\nfirst use [yolo](https://pjreddie.com/darknet/yolo/) scripts:\n\n```sh\nwget https://pjreddie.com/media/files/VOCtrainval_11-May-2012.tar\nwget https://pjreddie.com/media/files/VOCtrainval_06-Nov-2007.tar\nwget https://pjreddie.com/media/files/VOCtest_06-Nov-2007.tar\ntar xf VOCtrainval_11-May-2012.tar\ntar xf VOCtrainval_06-Nov-2007.tar\ntar xf VOCtest_06-Nov-2007.tar\nwget https://pjreddie.com/media/files/voc_label.py\npython3 voc_label.py\ncat 2007_train.txt 2007_val.txt 2012_*.txt \u003e train.txt\n```\n\nnow you have `train.txt`, then merge img path and annotation to one npy file:\n\n```sh\npython3 make_voc_list.py xxxx/train.txt data/voc_img_ann.npy\n```\n\n\n## Make anchors\n\nLoad the annotations generate anchors (`LOW` and `HIGH` depending on the distribution of dataset):\n```sh\nmake anchors DATASET=voc ANCNUM=3 LOW='.0 .0' HIGH='1. 1.'\n```\nWhen success you will see figure like this:\n![](asset/kmeans.png)\n\n**NOTE:** the kmeans result is random. when you get error , just rerun it.\n\nIf you want to use custom dataset, just write script and generate `data/{dataset_name}_img_ann.npy`, Then use `make anchors DATASET=dataset_name`. The more options please see with `python3 ./make_anchor_list.py -h`\n\nIf you want to change number of output layer, you should modify `OUTSIZE` in Makefile\n\n## Download pre-trian model\n\nYou **must** download the model weights you want to train because I load the pre-train weights by default. And put the files into `K210_Yolo_framework/data` directory. \n\n**My Demo use `yolo_mobilev1 0.75`**\n\n\n| `MODEL`       | `DEPTHMUL` | Url                                                                                | Url                                        |\n| ------------- | ---------- | ---------------------------------------------------------------------------------- | ------------------------------------------ |\n| yolo_mobilev1 | 0.5        | [google drive](https://drive.google.com/open?id=1SmuqIU1uCLRgaePve9HgCj-SvXJB7U-I) | [weiyun](https://share.weiyun.com/59nnvtW) |\n| yolo_mobilev1 | 0.75       | [google drive](https://drive.google.com/open?id=1BlH6va_plAEUnWBER6vij_Q_Gp8TFFaP) | [weiyun](https://share.weiyun.com/5FgNE0b) |\n| yolo_mobilev1 | 1.0        | [google drive](https://drive.google.com/open?id=1vIuylSVshJ47aJV3gmoYyqxQ5Rz9FAkA) | [weiyun](https://share.weiyun.com/516LqR7) |\n| yolo_mobilev2 | 0.5        | [google drive](https://drive.google.com/open?id=1qjpexl4dZLMtd0dX3QtoIHxXtidj993N) | [weiyun](https://share.weiyun.com/5BwaRTu) |\n| yolo_mobilev2 | 0.75       | [google drive](https://drive.google.com/open?id=1qSM5iQDicscSg0MYfZfiIEFGkc3Xtlt1) | [weiyun](https://share.weiyun.com/5RRMwob) |\n| yolo_mobilev2 | 1.0        | [google drive](https://drive.google.com/open?id=1Qms1BMVtT8DcXvBUFBTgTBtVxQc9r4BQ) | [weiyun](https://share.weiyun.com/5dUelqn) |\n| tiny_yolo     |            | [google drive](https://drive.google.com/open?id=1M1ZUAFJ93WzDaHOtaa8MX015HdoE85LM) | [weiyun](https://share.weiyun.com/5413QWx) |\n| yolo          |            | [google drive](https://drive.google.com/open?id=17eGV6DCaFQhVoxOuTUiwi7-v22DAwbXf) | [weiyun](https://share.weiyun.com/55g6zHl) |\n\n**NOTE:** The mobilenet is not original, I have **modified it** to fit k210\n\n## Train\n\nWhen you use mobilenet, you need to specify the `DEPTHMUL` parameter. You don't need set `DEPTHMUL` to use `tiny yolo` or `yolo`.\n\n1.  Set `MODEL` and `DEPTHMUL` to start training:\n\n    ```sh\n    make train MODEL=xxxx DEPTHMUL=xx MAXEP=10 ILR=0.001 DATASET=voc CLSNUM=20 IAA=False BATCH=16\n    ```\n\n    ![](asset/training.png)\n\n    **You can use `Ctrl+C` to stop training** , it will auto save weights and model in log dir.\n\n2.  Set `CKPT` to continue training:\n    \n    ```sh\n    make train MODEL=xxxx DEPTHMUL=xx MAXEP=10 ILR=0.0005 DATASET=voc CLSNUM=20 IAA=False BATCH=16 CKPT=log/xxxxxxxxx/yolo_model.h5\n    ```\n\n3.  Set `IAA` to enable data augment:\n    \n    ```sh\n    make train MODEL=xxxx DEPTHMUL=xx MAXEP=10 ILR=0.0001 DATASET=voc CLSNUM=20 IAA=True BATCH=16 CKPT=log/xxxxxxxxx/yolo_model.h5\n    ```\n\n4.  Use tensorboard:\n    \n    ```sh\n    tensorboard --logdir log\n    ```\n\n**NOTE:** The more options please see with `python3 ./keras_train.py -h`\n\n\n## Inference\n\n```sh\nmake inference MODEL=xxxx DEPTHMUL=xx CLSNUM=xx CKPT=log/xxxxxx/yolo_model.h5 IMG=data/people.jpg\n```\n\nYou can try with my model :\n\n```sh\nmake inference MODEL=yolo_mobilev1 DEPTHMUL=0.75 CKPT=asset/yolo_model.h5 IMG=data/people.jpg\n```\n![](asset/people_res.jpg) \n```sh\nmake inference MODEL=yolo_mobilev1 DEPTHMUL=0.75 CKPT=asset/yolo_model.h5 IMG=data/dog.jpg\n```\n\n![](asset/dog_res.jpg)\n\n**NOTE:** Since the anchor is randomly generated, your results will be **different from the above image**.You just need to load this model and continue training for a while. \n\nThe more options please see with `python3 ./keras_inference.py -h`\n\n\n## Prune Model\n    \n```sh\nmake train MODEL=xxxx MAXEP=1 ILR=0.0003 DATASET=voc CLSNUM=20 BATCH=16 PRUNE=True CKPT=log/xxxxxx/yolo_model.h5 END_EPOCH=1\n```\n\nWhen training finish, will save model as `log/xxxxxx/yolo_prune_model.h5`.\n\n\n## Freeze\n\n```sh\ntoco --output_file mobile_yolo.tflite --keras_model_file log/xxxxxx/yolo_model.h5\n```\nNow you have `mobile_yolo.tflite`\n\n\n## Convert Kmodel\n\nPlease refer [nncase v0.1.0-RC5](https://github.com/kendryte/nncase/tree/v0.1.0-rc5) [example](https://github.com/kendryte/nncase/tree/v0.1.0-rc5/examples/20classes_yolo)\n\n## Demo\n\nUse [kendryte-standalone-sdk v0.5.6](https://github.com/kendryte/kendryte-standalone-sdk/tree/V0.5.6)\n\n*   [KD233](https://kendryte.com/)\n\nUse [Kflash.py](https://github.com/kendryte/kflash.py) \n```sh\nkflash yolo3_frame_test_public/kfpkg/kpu_yolov3.kfpkg -B kd233 -p /dev/ttyUSB0 -b 2000000 -t\n```\n![](asset/k210_res.jpg)\n\n* [MAIXPY GO](https://wiki.sipeed.com/en/maix/board/go.html)\n\nUse [Kflash.py](https://github.com/kendryte/kflash.py) \n```sh\nkflash yolo3_frame_test_public_maixpy/kfpkg/kpu_yolov3.kfpkg -B goE -p /dev/ttyUSB1 -b 2000000 -t\n```\n\n![](asset/maixpy_res.jpg)\n\n**NOTE:** I just use [kendryte yolov2 demo code](https://github.com/kendryte/nncase/tree/master/examples/20classes_yolo/k210/kpu_20classes_example) to prove the validity of the model. \n\n![](asset/video_res.gif)\n\nIf you need `standard yolov3 region layer code`, you can buy with me.\n\n# Caution\n\n1.  Default parameter in `Makefile`\n2.  `OBJWEIGHT`,`NOOBJWEIGHT`,`WHWEIGHT` used to balance precision and recall\n3.  Default output two layers,if you want more output layers can modify `OUTSIZE`\n4.  If you want to use the **full yolo**, you need to modify the `IMGSIZE` and `OUTSIZE` in the Makefile to the original yolo parameters\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhen8838%2FK210_Yolo_framework","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhen8838%2FK210_Yolo_framework","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhen8838%2FK210_Yolo_framework/lists"}