私的AI研究会 > RevYOLOv5_3
物体検出の応用として車のナンバープレート識別を検討してみる
update └─workspace_pylearn ├─number │ ├─test_data │ └─test_data_result └─yolov5 ├─data │ ├─janken4_dataset 修正データ │ ├─mask_dataset 修正データ │ ├─nm_dataset ※1 学習用データセット │ ├─ts_dataset 修正データ │ └─vd_dataset ※1 学習用データセット └─runs └─train ├─nm_yolov5s_ep100 ※2 学習結果 ├─nm_yolov5s_ep30 ※2 ├─nm_yolov5s_ep50 ※2 └─vd_yolov5s_ep100 ※2※1 以下のプロジェクトの『データセットの準備』を行った結果のデータセット
train: data/vd_dataset/train/images val: data/vd_dataset/valid/images test: data/vd_dataset/test/images nc: 2 names: ['licence', 'licenseplate'] roboflow: workspace: image-processing-u647q project: vehicle-detection-639on version: 7 license: CC BY 4.0 url: https://universe.roboflow.com/image-processing-u647q/vehicle-detection-639on/dataset/7
(py_learn) python train.py --epochs 100 --data data/vd_dataset/vd_data.yaml --weights yolov5s.pt --name vd_yolov5s_ep100・GPU を使用しない場合は以下のコマンドを実行する
(py_learn) python train.py --epochs 100 --data data/vd_dataset/vd_data.yaml --weights yolov5s.pt --name vd_yolov5s_ep100 --device cpu
(py_learn) python train.py --epochs 100 --data data/vd_dataset/vd_data.yaml --weights yolov5s.pt --name vd_yolov5s_ep100 : Epoch GPU_mem box_loss obj_loss cls_loss Instances Size 99/99 4.17G 0.01894 0.006213 0.000583 12 640: 100%|██████████| 34/34 [00:02<00:00, 12. Class Images Instances P R mAP50 mAP50-95: 100%|██████████| 5/5 [00:00<0 all 136 155 0.544 0.5 0.468 0.242 100 epochs completed in 0.107 hours. Optimizer stripped from runs\train\vd_yolov5s_ep100\weights\last.pt, 14.4MB Optimizer stripped from runs\train\vd_yolov5s_ep100\weights\best.pt, 14.4MB Validating runs\train\vd_yolov5s_ep100\weights\best.pt... Fusing layers... Model summary: 157 layers, 7015519 parameters, 0 gradients, 15.8 GFLOPs Class Images Instances P R mAP50 mAP50-95: 100%|██████████| 5/5 [00:01<0 all 136 155 0.476 0.53 0.472 0.26 licence 136 132 0.681 0.712 0.635 0.333 licenseplate 136 23 0.27 0.348 0.31 0.187 Results saved to runs\train\vd_yolov5s_ep100
ナンバー ナンバープレート・「vd_names」英語ファイル
licence licenseplate
(py_learn) python detect2.py --weights runs/train/vd_yolov5s_ep100/weights/best.pt --source ../number/test_data/・実行ログ(結果は「runs/detect/exp*」*は順次更新)
(py_learn) python detect2.py --weights runs/train/vd_yolov5s_ep100/weights/best.pt --source ../number/test_data/ detect2: weights=['runs/train/vd_yolov5s_ep100/weights/best.pt'], source=../number/test_data/, data=data\coco128.yaml, imgsz=[640, 640], conf_thres=0.25, iou_thres=0.45, max_det=1000, device=, view_img=False, save_txt=False, save_csv=False, save_conf=False, save_crop=False, nosave=False, classes=None, agnostic_nms=False, augment=False, visualize=False, update=False, project=runs\detect, name=exp, exist_ok=False, line_thickness=3, hide_labels=False, hide_conf=False, half=False, dnn=False, vid_stride=1 YOLOv5 v7.0-294-gdb125a20 Python-3.11.8 torch-2.2.1+cu121 CUDA:0 (NVIDIA GeForce RTX 4070 Ti, 12282MiB) Fusing layers... Model summary: 157 layers, 7015519 parameters, 0 gradients, 15.8 GFLOPs Speed: 0.2ms pre-process, 5.4ms inference, 1.2ms NMS per image at shape (1, 3, 640, 640) Results saved to runs\detect\exp43
(py_learn) python detect3_yolov5.py -m runs/train/vd_yolov5s_ep100/weights/best.pt -i ../number/test_data/japan69.jpg -l ./data/vd_dataset/vd_names_jp・実行ログ
(py_learn) python detect3_yolov5.py -m runs/train/vd_yolov5s_ep100/weights/best.pt -i ../number/test_data/japan69.jpg -l ./data/vd_dataset/vd_names_jp Starting.. Object detection+ YoloV5 Ver. 0.08: Starting application... OpenCV virsion : 4.9.0 - Image File : ../number/test_data/japan69.jpg - YOLO v5 : ultralytics/yolov5 - Pretrained : runs/train/vd_yolov5s_ep100/weights/best.pt - Confidence lv: 0.25 - Label file : ./data/vd_dataset/vd_names_jp - Program Title: y - Speed flag : y - Processed out: non - Use device : cuda:0 - Log Level : 3 Using cache found in C:\Users\izuts/.cache\torch\hub\ultralytics_yolov5_master YOLOv5 2024-4-9 Python-3.11.8 torch-2.2.1+cu121 CUDA:0 (NVIDIA GeForce RTX 4070 Ti, 12282MiB) Fusing layers... Model summary: 157 layers, 7015519 parameters, 0 gradients, 15.8 GFLOPs Adding AutoShape... FPS average: 8.90 Finished.
収録文字 半角の1234567890、ひらがなの全て(お、し、へ、ん、及び、TRMフォントに収録してある文字を除く)、金、高、口、山、士、沢、知、徳、島、奈、富、福、良 欧文大文字の全て、小文字の枠にABCEHKLMTV(沖縄に配慮して、Yは表示せず)カタカナの枠に「ツクバ」→「つくば」※2 TrmFontJB.ttf TRMフォント JB
このフォントは自動車登録番号票の大板(大きいナンバープレート)の文字*1に似せたものです。 上段数字(分類番号1・2・8・選択番号などの3)/下段数字(一連指定番号0~9 ハイフン 点)/下段ひらがなの一部(あ・い・う・を・か・き・く・け・こ・せ)を収録、事業者用大型車両の模型に適しています。
(py_learn) cd /anaconda_win/workspace_pylearn/number/ (py_learn) python number_gen.py・生成したナンバープレートの例
mkdir -p nm_dataset/train/images mkdir -p nm_dataset/val/images mkdir -p nm_dataset/train/labels mkdir -p nm_dataset/val/labels・作成結果
(py_learn) tree /anaconda_win/workspace_pylearn/number ├─nm_dataset │ ├─train │ │ ├─images │ │ └─labels │ └─val │ ├─images │ └─labels
move dataset_f/labels/*1.txt nm_dataset/val/labels move dataset_f/labels/*5.txt nm_dataset/val/labels move dataset_f/images/*1.jpg nm_dataset/val/images move dataset_f/images/*5.jpg nm_dataset/val/images・学習用は残りのファイルを移動{8000-1600 = 6400個)
move dataset_f/labels/*.txt nm_dataset/train/labels move dataset_f/images/*.jpg nm_dataset/train/images
(py_learn) python train.py --data data/nm_dataset/nm_dataset.yaml --weights yolov5s.pt --epochs 30 --name nm_yolov5s_ep50
(py_learn) python train.py --data data/nm_dataset/nm_dataset.yaml --weights yolov5s.pt --epochs 50 --name nm_yolov5s_ep50
(py_learn) python train.py --data data/nm_dataset/nm_dataset.yaml --weights yolov5s.pt --epochs 100 --name nm_yolov5s_ep50
(py_learn) python detect3_yolov5.py -m ./runs/train/vd_yolov5s_ep100/weights/best.pt -ms ./runs/train/nm_yolov5s_ep50/weights/best.pt -l ./data/nm_dataset/vd_names_jp -i ../number/test_data/japan79.jpg --log 0・実行ログ
(py_learn) python detect3_yolov5.py -m ./runs/train/vd_yolov5s_ep100/weights/best.pt -ms ./runs/train/nm_yolov5s_ep50/weights/best.pt -l ./data/nm_dataset/vd_names_jp -i ../number/test_data/japan79.jpg --log 0 Starting.. Object detection+ YoloV5 Ver. 0.08: Starting application... OpenCV virsion : 4.9.0 - Image File : ../number/test_data/japan79.jpg - YOLO v5 : ultralytics/yolov5 - Pretrained : ./runs/train/vd_yolov5s_ep100/weights/best.pt - Pretrained 2 : ./runs/train/nm_yolov5s_ep50/weights/best.pt - Confidence lv: 0.25 - Label file : ./data/nm_dataset/vd_names_jp - Program Title: y - Speed flag : y - Processed out: non - Use device : cuda:0 - Log Level : 0 Using cache found in C:\Users\izuts/.cache\torch\hub\ultralytics_yolov5_master YOLOv5 2024-4-9 Python-3.11.8 torch-2.2.1+cu121 CUDA:0 (NVIDIA GeForce RTX 4070 Ti, 12282MiB) Fusing layers... Model summary: 157 layers, 7015519 parameters, 0 gradients, 15.8 GFLOPs Adding AutoShape... Using cache found in C:\Users\izuts/.cache\torch\hub\ultralytics_yolov5_master YOLOv5 2024-4-9 Python-3.11.8 torch-2.2.1+cu121 CUDA:0 (NVIDIA GeForce RTX 4070 Ti, 12282MiB) Fusing layers... Model summary: 157 layers, 7182733 parameters, 0 gradients, 16.3 GFLOPs Adding AutoShape... ** Bounding Box: [[ 117.31 68.326 463.6 223.57 0.85471 0] [ 185.14 145 247.09 238.57 0.98435 11] [ 237.82 146.53 309.99 238.75 0.97927 6] [ 334.89 149.99 398.25 241.71 0.97658 7] [ 395.26 148.3 456.66 245.42 0.96122 6] [ 311.43 83.831 349.9 137.64 0.90122 9] [ 351.6 84.356 392 136.87 0.86674 11] [ 350.22 85.405 391.93 136.08 0.47585 7]] (117, 68)-(463, 223) ナンバー: 0.85 (185, 144)-(247, 238) 9: 0.98 (237, 146)-(309, 238) 4: 0.98 (334, 149)-(398, 241) 5: 0.98 (395, 148)-(456, 245) 4: 0.96 (311, 83)-(349, 137) 7: 0.90 (351, 84)-(392, 136) 9: 0.87 (350, 85)-(391, 136) 5: 0.48 FPS average: 6.90 Finished.
(py_learn) python detect3_number.py --log 0・実行ログ
(py_learn) python detect3_number.py --log 0 Starting.. Number plate detection YOLOv5 Ver. 0.08: Starting application... OpenCV virsion : 4.9.0 - Image File : ../number/test_data/japan78.jpg - YOLO v5 : ultralytics/yolov5 - Pretrained : ./runs/train/vd_yolov5s_ep100/weights/best.pt - Pretrained 2 : ./runs/train/nm_yolov5s_ep50/weights/best.pt - Confidence lv: 0.25 - Label file : ./data/nm_dataset/vd_names_jp - Program Title: y - Speed flag : y - Processed out: non - Use device : cuda:0 - Log Level : 0 Using cache found in C:\Users\izuts/.cache\torch\hub\ultralytics_yolov5_master YOLOv5 2024-4-9 Python-3.11.8 torch-2.2.1+cu121 CUDA:0 (NVIDIA GeForce RTX 4070 Ti, 12282MiB) Fusing layers... Model summary: 157 layers, 7015519 parameters, 0 gradients, 15.8 GFLOPs Adding AutoShape... Using cache found in C:\Users\izuts/.cache\torch\hub\ultralytics_yolov5_master YOLOv5 2024-4-9 Python-3.11.8 torch-2.2.1+cu121 CUDA:0 (NVIDIA GeForce RTX 4070 Ti, 12282MiB) Fusing layers... Model summary: 157 layers, 7182733 parameters, 0 gradients, 16.3 GFLOPs Adding AutoShape... ** プレートラベル: ['ナンバー', 'ナンバープレート', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'あ', 'い', 'う', 'え', 'か', 'き', 'く', 'け', 'こ', 'さ', 'す', 'せ', 'そ', 'た', 'ち', 'つ', 'て', 'と', 'な', 'に', 'ぬ', 'ね', 'の', 'は', 'ひ', 'ふ', 'ほ', 'ま', 'み', 'む', 'め', 'も', 'や', 'ゆ', 'よ', 'ら', 'り', 'る', 'れ', 'ろ', 'わ', 'を', '京都', 'なにわ', '大阪', '和泉', '堺', '奈良', '和歌山', '神戸', '徳島', '香川', '愛媛', '千葉'] ** Bounding Box: [[ 61.591 38.322 510.12 262.66 0.4888 0] [ 352.12 59.349 392.61 129.97 0.98521 2] [ 315.72 59.296 354.99 131.48 0.98443 3] [ 391.33 60.289 431.3 129.43 0.98215 2] [ 344.3 148.63 433.98 289.92 0.9785 7] [ 426.44 146.62 513.85 303.11 0.96134 10] [ 84.134 152.66 159.09 231.37 0.58646 22] [ 1.3103 181.38 54.892 325.32 0.57503 60] [ 156.16 49.026 321.75 166.41 0.35428 55]] Y** 最小値 を昇順にソートX: [[ 61.591 38.322 510.12 262.66 0.4888 0] [ 156.16 49.026 321.75 166.41 0.35428 55] [ 315.72 59.296 354.99 131.48 0.98443 3] [ 352.12 59.349 392.61 129.97 0.98521 2] [ 391.33 60.289 431.3 129.43 0.98215 2] [ 426.44 146.62 513.85 303.11 0.96134 10] [ 344.3 148.63 433.98 289.92 0.9785 7] [ 84.134 152.66 159.09 231.37 0.58646 22] [ 1.3103 181.38 54.892 325.32 0.57503 60]] ** 上下を分割する場所: bbox = (61.59,38.32)-(510.12,262.66) ylimit = 106.30 index = 5 ** ナンバープレートの上部: [[ 61.591 38.322 510.12 262.66 0.4888 0] [ 156.16 49.026 321.75 166.41 0.35428 55] [ 315.72 59.296 354.99 131.48 0.98443 3] [ 352.12 59.349 392.61 129.97 0.98521 2] [ 391.33 60.289 431.3 129.43 0.98215 2]] ** ナンバープレートの下部: [[ 426.44 146.62 513.85 303.11 0.96134 10] [ 344.3 148.63 433.98 289.92 0.9785 7] [ 84.134 152.66 159.09 231.37 0.58646 22] [ 1.3103 181.38 54.892 325.32 0.57503 60]] ** 上部 X最小値) を昇順にソート: [[ 61.591 38.322 510.12 262.66 0.4888 0] [ 156.16 49.026 321.75 166.41 0.35428 55] [ 315.72 59.296 354.99 131.48 0.98443 3] [ 352.12 59.349 392.61 129.97 0.98521 2] [ 391.33 60.289 431.3 129.43 0.98215 2]] ** 下部 X最小値) を昇順にソート: [[ 1.3103 181.38 54.892 325.32 0.57503 60] [ 84.134 152.66 159.09 231.37 0.58646 22] [ 344.3 148.63 433.98 289.92 0.9785 7] [ 426.44 146.62 513.85 303.11 0.96134 10]] ** 上部下部を一つにする: [[ 61.591 38.322 510.12 262.66 0.4888 0] [ 156.16 49.026 321.75 166.41 0.35428 55] [ 315.72 59.296 354.99 131.48 0.98443 3] [ 352.12 59.349 392.61 129.97 0.98521 2] [ 391.33 60.289 431.3 129.43 0.98215 2] [ 1.3103 181.38 54.892 325.32 0.57503 60] [ 84.134 152.66 159.09 231.37 0.58646 22] [ 344.3 148.63 433.98 289.92 0.9785 7] [ 426.44 146.62 513.85 303.11 0.96134 10]] ** ナンバープレート解析結果: なにわ100 す58 FPS average: 7.80 Finished.
(py_learn) python detect_number.py --log 0・実行ログ
(py_learn) python detect_number.py --log 0 Starting.. Number plate detection Ver. 0.09: Starting application... OpenCV virsion : 4.9.0 - Image File : ../number/test_data/japan74.jpg - YOLO v5 : ultralytics/yolov5 - Pretrained : ./runs/train/vd_yolov5s_ep100/weights/best.pt - Pretrained 2 : ./runs/train/nm_yolov5s_ep50/weights/best.pt - Confidence lv: 0.4 - Label file : ./data/nm_dataset/names_jp - Program Title: y - Speed flag : y - Processed out: non - Use device : cuda:0 - Log Level : 0 Using cache found in C:\Users\izuts/.cache\torch\hub\ultralytics_yolov5_master YOLOv5 2024-4-9 Python-3.11.8 torch-2.2.1+cu121 CUDA:0 (NVIDIA GeForce RTX 4070 Ti, 12282MiB) Fusing layers... Model summary: 157 layers, 7015519 parameters, 0 gradients, 15.8 GFLOPs Adding AutoShape... ** プレートラベル: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'あ', 'い', 'う', 'え', 'か', 'き', 'く', 'け', 'こ', 'さ', 'す', 'せ', 'そ', 'た', 'ち', 'つ', 'て', 'と', 'な', 'に', 'ぬ', 'ね', 'の', 'は', 'ひ', 'ふ', 'ほ', 'ま', 'み', 'む', 'め', 'も', 'や', 'ゆ', 'よ', 'ら', 'り', 'る', 'れ', 'ろ', 'わ', 'を', '京都', 'なにわ', '大阪', '和泉', '堺', '奈良', '和歌山', '神戸', '徳島', '香川', '愛媛', '千葉'] Using cache found in C:\Users\izuts/.cache\torch\hub\ultralytics_yolov5_master YOLOv5 2024-4-9 Python-3.11.8 torch-2.2.1+cu121 CUDA:0 (NVIDIA GeForce RTX 4070 Ti, 12282MiB) Fusing layers... Model summary: 157 layers, 7182733 parameters, 0 gradients, 16.3 GFLOPs Adding AutoShape... ** プレートの Bounding Box: [[ 168.33 60.04 414.33 173.39 0.85431 0]] ** プレート画像 Bounding Box: [[ 174.72 13.63 194.84 47.704 0.98788 0] [ 155.33 12.984 175.65 47.85 0.98763 0] [ 136.1 12.444 156.45 47.14 0.98613 3] [ 92.386 54.675 140.81 113 0.98496 0] [ 56.594 53.658 97.797 113 0.98449 7] [ 153.8 56.805 193.96 113 0.98116 4] [ 193.16 57.049 234.76 113 0.98103 5] [ 21.854 59.884 55.78 93.946 0.58157 30] [ 57.435 5.9446 138.67 45.611 0.57542 53] [ 193.21 0 243.2 11.105 0.41337 2] [ 61.161 10.435 133.51 45.012 0.38094 54]] Y** 最小値 を昇順にソートX: [[ 193.21 0 243.2 11.105 0.41337 2] [ 57.435 5.9446 138.67 45.611 0.57542 53] [ 61.161 10.435 133.51 45.012 0.38094 54] [ 136.1 12.444 156.45 47.14 0.98613 3] [ 155.33 12.984 175.65 47.85 0.98763 0] [ 174.72 13.63 194.84 47.704 0.98788 0] [ 56.594 53.658 97.797 113 0.98449 7] [ 92.386 54.675 140.81 113 0.98496 0] [ 153.8 56.805 193.96 113 0.98116 4] [ 193.16 57.049 234.76 113 0.98103 5] [ 21.854 59.884 55.78 93.946 0.58157 30]] ** 上下を分割する場所: bbox = (0.00,0.00)-(246.00,113.00) ylimit = 34.24 index = 6 ** ナンバープレートの上部: [[ 193.21 0 243.2 11.105 0.41337 2] [ 57.435 5.9446 138.67 45.611 0.57542 53] [ 61.161 10.435 133.51 45.012 0.38094 54] [ 136.1 12.444 156.45 47.14 0.98613 3] [ 155.33 12.984 175.65 47.85 0.98763 0] [ 174.72 13.63 194.84 47.704 0.98788 0]] ** ナンバープレートの下部: [[ 56.594 53.658 97.797 113 0.98449 7] [ 92.386 54.675 140.81 113 0.98496 0] [ 153.8 56.805 193.96 113 0.98116 4] [ 193.16 57.049 234.76 113 0.98103 5] [ 21.854 59.884 55.78 93.946 0.58157 30]] ** 上部 X最小値) を昇順にソート: [[ 57.435 5.9446 138.67 45.611 0.57542 53] [ 61.161 10.435 133.51 45.012 0.38094 54] [ 136.1 12.444 156.45 47.14 0.98613 3] [ 155.33 12.984 175.65 47.85 0.98763 0] [ 174.72 13.63 194.84 47.704 0.98788 0] [ 193.21 0 243.2 11.105 0.41337 2]] ** 下部 X最小値) を昇順にソート: [[ 21.854 59.884 55.78 93.946 0.58157 30] [ 56.594 53.658 97.797 113 0.98449 7] [ 92.386 54.675 140.81 113 0.98496 0] [ 153.8 56.805 193.96 113 0.98116 4] [ 193.16 57.049 234.76 113 0.98103 5]] ** 上部下部を一つにする: [[ 57.435 5.9446 138.67 45.611 0.57542 53] [ 61.161 10.435 133.51 45.012 0.38094 54] [ 136.1 12.444 156.45 47.14 0.98613 3] [ 155.33 12.984 175.65 47.85 0.98763 0] [ 174.72 13.63 194.84 47.704 0.98788 0] [ 193.21 0 243.2 11.105 0.41337 2] [ 21.854 59.884 55.78 93.946 0.58157 30] [ 56.594 53.658 97.797 113 0.98449 7] [ 92.386 54.675 140.81 113 0.98496 0] [ 153.8 56.805 193.96 113 0.98116 4] [ 193.16 57.049 234.76 113 0.98103 5]] ** ナンバープレート解析結果: なにわ300 ぬ7045 FPS average: 5.90 Finished.
・ハイパーパラメータ
・「roboflow」のMask Wearing Datasetを使用
・学習用データセット作成