9
14

More than 1 year has passed since last update.

YOLOv5を使ってりんごのリアルタイム成熟度判断システムを作ってみた。

Last updated at Posted at 2022-02-16

はじめに

本記事ではYOLOv5という物体検出アルゴリズムを用いてりんごの成熟度を判断する(分類する)AIを作ってみたというお話です。画像や動画、カメラからの入力データに対し、りんごの成熟度を瞬時に判断してくれるAIを作ってみました。実際の収穫作業の際に使うには画像でしか動かないアルゴリズムでなく、リアルタイムに動作するAIにしたくYOLOを活用して取り組んでみました。動作イメージは以下の通りです。

画像

111_55.png

動画

ezgif-1-182f889551.gif

リアルタイム

ezgif-1-13ec6e9431.gif

この記事は「YOLOv5を使って何か面白いことに取り組んでみたい!」、「YOLOv5を実際に動かしてみたい!」と思う方に向けて書いてみました。玄人の方には退屈な記事かもしれません。

目次

  • 物体検出とは
  • YOLOv5とは
  • 検出対象物
  • 画像集め
  • 分類方法
  • 教師データ作り
  • 実装
  • おわりに

物体検出とは

物体検出とは動画像内の中から特定の物体が存在するかどうかを検出し、存在する場合には各物体の位置と範囲を推論する技術のことです。自動運転や検温システムなどに使われている技術ですね。イメージ画像は以下の通りです。
image8-2.jpg

YOLOv5とは

まず、YOLO(You Only Look Once)についてですが、これはRedmon(2016)により提案された深層学習を活用した物体検出アルゴリズムです。詳しいアルゴリズムに関しての説明は省きますが、他の物体検出アルゴリズムと異なる特徴としてメリットデメリットを簡単に以下に記載します。

メリット

  • 処理が高速でリアルタイムに物体検出が可能
  • 背景の誤検出に強い

デメリット

  • 小さい物体の検出が不得意
  • 最先端のアルゴリズムと比べると若干精度が劣る

YOLOv5は2020年6月9日にGlenn Jocherによりリリースされた2022年2月16日現在YOLOの最新アルゴリズムです。今までのYOLOよりも認識精度が高くなっているようです。

検出対象物「サンふじ」

今回はりんごの「サンふじ」を対象に成熟度判断システムを作ってみることにします。というのも家族にリンゴ農家がおり、そこで育てているので、画像データを集めやすいというのが理由です。ちなみに「サンふじ」とは「ふじ」という日本でリンゴ生産量50%以上を誇る最もメジャーな品種のうち無袋栽培(袋をかぶせず栽培する)で作られたもののことを言います。以下サンふじの収穫間際の画像です。111_55.png

画像集め

YOLOを使って物体検出モデルを作るのにはそれなりに画像を集める必要があります。未成熟から成熟までの様々な成熟度のりんごの画像を集めるために8月~11月までの期間で、様々な光条件画像でりんごの画像を集めるために朝~夕方、曇り・晴れなど条件を変え画像を収集しました。効率よく画像を集めるために手元のスマホ(iPhoneX)で動画としてりんごを撮影し、プログラムで動画から画像を切り出すことで手早く大量の画像を集めました。使用したプログラムは以下に記載します。このプログラムの参考はこちらです。

import cv2
import numpy as np

def m_slice(path, dir, step, extension):
    movie = cv2.VideoCapture(path)                  # 動画の読み込み
    Fs = int(movie.get(cv2.CAP_PROP_FRAME_COUNT))   # 動画の全フレーム数を計算
    path_head = dir + '\out_'                       
    ext_index = np.arange(0, Fs, step)              # 静止画を抽出する間隔

    for i in range(Fs - 1):                         
        flag, frame = movie.read()                  
        check = i == ext_index                      
        if flag == True:
            if True in check:
                if i < 10:
                    path_out = path_head + '0000' + str(i) + extension
                elif i < 100:
                    path_out = path_head + '000' + str(i) + extension
                elif i < 1000:
                    path_out = path_head + '00' + str(i) + extension
                elif i < 10000:
                    path_out = path_head + '0' + str(i) + extension
                else:
                    path_out = path_head + str(i) + extension
                cv2.imwrite(path_out, frame)
            else:
                pass
        else:
            pass
    return

m_slice('動画へのパス', '保存するフォルダへのパス', 20, '.png')

こんな感じで効率よく画像を集めてました。その後データ量が多いことが発覚しました。まあiPhoneXの画質が思っていたより良かった(解像度:1920×1080)ことが原因ですね。これを縦横ともに1/3することにしました。以下にそのプログラムを記載します。

import cv2
import glob

files = glob.glob("画像が保存されているフォルダへのパス")

for i, file in enumerate(files):
    img = cv2.imread(file)
    height = img.shape[0]
    width = img.shape[1]
    img_reshape = cv2.resize(img, (int(width/3), int(height/3)))
    img_path = "保存したいフォルダへのパス" + "/reshape{}.png".format(i)
    cv2.imwrite(img_path,img_reshape)

これで画像を一括でダウンサイズすることができました。そしてこの後使えなさそうな画像を手動で削除していきました。使えない画像というのはりんごが写っていない画像やブレがひどい画像、暗すぎてりんご成熟度が判別できない画像、カビや腐食などがひどい画像などです。これでひとまずYOLOを作成するための画像集めは終了です。

分類方法

成熟度に応じてりんごを分類する方法なのですが、今回は農林水産省果実試験場が提供している「ふじ 表面色カラーチャート」に沿って目視で分類をしました。(なので教師データに多少の間違いがある可能性がありますが...)このカラーチャートに沿って各りんごの成熟度をlevel1~level6までに分類している様子が以下の通りです。
image.png
こんな感じで集めたリンゴ画像に対し教師データを作っていきます。

教師データ作り

YOLOで物体検出モデルを作るにはアノテーションファイルと呼ばれる教師データが必要です。なので作ります。[物体のクラス 中心のx座標 中心のy座標 width height]が記載されたtxtファイルを各画像につき用意します。おそらくこれが最も骨の折れる作業となります。このtxtファイルの作り方についてですがLabelImgというアノテーションソフトを活用しました。これを活用し、画像一枚一枚にアノテーションファイルを作ります。

まず、LabelImgからwindows_v1.8.1.zipというフォルダをダウンロードし、zipファイルを解凍します。その後、/windows_v1.8.1/data/predefined_classes.txtファイルを開き編集します。元は

dog
person
cat
tv
car
meatballs
marinara sauce
tomato soup
chicken noodle soup
french onion soup
chicken breast
ribs
pulled pork
hamburger
cavity

となっていると思いますが、これを検出したいクラスの名前に変えます。今回はりんごの生育度6つなので、

level1
level2
level3
level4
level5
level6

とします。その後、labelImg.exeを開きます。そしてソフト左のOpen Dirボタンを押し、りんご画像が保存されているフォルダを開きます。ソフト左のChange Save Dirボタンを押し、同じディレクトリが指定されていることを確認します(異なる場合ディレクトリを同じにしてください)。

次にソフト左の中央のボタンがPascalVOCもしくはYOLOになっているになっていると思うのでこれをYOLOにします(PascalVOCのままだとtxtではなくxmlで保存されてしまいます)。これであとは左のCreate\nRectBoxボタンを押してどんどん画像中の物体のラベル付けをしていきましょう!

labelImg.png

こんな感じで画像一枚一枚に対しラベルを付けていきます。大変です...

実装

手持ちのGPU非搭載のPCではYOLOを作るのは厳しいだろうと思い、Google Colaboratory ProのGPU環境で学習を行いました。(おそらくGoogle ColaboratoryのGPU環境でも動かせます。)実装したコードを記載していきます。

その前にYOLOv5を動作させるためのフォルダを作っていきます。名前はringoとしておきます。ringo以下にtrain,test,valのフォルダとringo.yamlというファイルを作りました。ringo.yamlというファイルには以下の内容を記載しました。yamlファイルとはYOLOv5を動かす際の設定ファイルのことですね。

#train,test,valのパスを指定している。
train: /content/drive/My Drive/ringo/train
val: /content/drive/My Drive/ringo/val
test: /content/drive/My Drive/ringo/test

# 検出するクラスの数
nc: 6

# 検出する各クラスの名前
names: ["level1", "level2", "level3", "level4", "level5", "level6"]

これで設定はできました。train,test,valのフォルダに今まで集めた画像とアノテーションファイルを適当に分割して入れていきます。私は以下の通りにプログラムを作り、train,test,valに分割して入れました。

import glob
import os
import random
import shutil
import numpy as np

def split_data(folder,savefolder,train_rate,val_rate):
    imgs = glob.glob(os.path.join(folder,"*.png"))
    txts = glob.glob(os.path.join(folder,"*.txt"))

    imgs_index = np.array(range(len(imgs)))
    imgs_index_shuffle = np.random.permutation(imgs_index) #適当にシャッフルする
    n = len(imgs)
    train_n = int(n * train_rate)
    val_n = int(n * val_rate)
    test_n = n - train_n - val_n
    print(train_n,test_n,val_n)

    for i, index  in enumerate(imgs_index_shuffle):
        img_path = imgs[index] 
        txt_path = txts[index]
        img_name = img_path.split("\\")[1]
        txt_name = txt_path.split("\\")[1]
        print(img_name,txt_path)
        if i < train_n:
            shutil.copyfile(img_path, savefolder + f"/train/{img_name}")
            shutil.copyfile(txt_path, savefolder + f"/train/{txt_name}")
        elif train_n <= i < train_n + val_n:
            shutil.copyfile(img_path, savefolder + f"/val/{img_name}")
            shutil.copyfile(txt_path, savefolder + f"/val/{txt_name}")
        else:
            shutil.copyfile(img_path, savefolder + f"/test/{img_name}")
            shutil.copyfile(txt_path, savefolder + f"/test/{txt_name}")

split_data("pngとtxtが入っているフォルダ","./ringo",0.7,0.1)

このプログラムではtrain:val:test=7:1:2に分割していますが、引数を調節すれば割合の変更は可能です。

これでringoというフォルダにtrain,test,valという画像とアノテーションデータが入ったフォルダ、ringo.yamlという設定ファイルを作ることができました。

画像データが少なめだったのでtrainデータの拡張(Data Augumentation)を行いました。Data Augumentationには回転・移動・反転など様々ありますが、今回は画像反転(左右・上下・左右上下)を行いました。(ちなみに反転処理は画像の対称性を考慮する必要のない場合のみ有効です。りんごは枝の上側にも実がなることもあるので今回は上下反転も大丈夫だと判断しました。)実装したプログラムは以下の通りです。

import shutil
import cv2

folder = "./ringo/train"
pngnames = glob.glob(folder + "/*png")
txtnames = glob.glob(folder + "/*txt")

for i in range(len(pngnames)):
    full_pngname = pngnames[i]
    full_txtname = txtnames[i]
    pngname = full_pngname.split("\\")[1]
    txtname = full_txtname.split("\\")[1]
    print(pngname)
    img = cv2.imread(full_pngname)
    img_flip_ud = cv2.flip(img, 0)
    cv2.imwrite("./ringo/train/"+"joge_"+pngname, img_flip_ud)
    img_flip_lr = cv2.flip(img, 1)
    cv2.imwrite("./ringo/train/"+"sayu_"+pngname, img_flip_lr)
    img_flip_ud_lr = cv2.flip(img, -1)
    cv2.imwrite("./ringo/train/"+"jogesayu_"+pngname, img_flip_ud_lr)
    with open(full_txtname) as f:
        anns = f.readlines()
        print(anns)
        sayu_ann_list = []
        joge_ann_list = []
        jogesayu_ann_list = []
        for ann in anns:
            ann = ann[:-1]
            cat = ann[0]
            center_x = ann.split(" ")[1]
            center_y = ann.split(" ")[2]
            width = ann.split(" ")[3]
            height = ann.split(" ")[4]
            sayu_center_x = 1 - float(center_x)
            sayu_center_y = float(center_y)
            joge_center_x = float(center_x)
            joge_center_y = 1 - float(center_y)
            jogesayu_center_x = 1 - float(center_x)
            jogesayu_center_y = 1 - float(center_y)
            sayu_ann_list.append(cat+" "+str(sayu_center_x)+" "+str(sayu_center_y)+" "+str(width)+" "+str(height))
            joge_ann_list.append(cat+" "+str(joge_center_x)+" "+str(joge_center_y)+" "+str(width)+" "+str(height))
            jogesayu_ann_list.append(cat+" "+str(jogesayu_center_x)+" "+str(jogesayu_center_y)+" "+str(width)+" "+str(height))
    with open("./ringo/train/"+"sayu_"+txtname, mode='w') as f:
        for sayu_ann in sayu_ann_list:
            f.write(sayu_ann+"\n")
    with open("./ringo/train/"+"joge_"+txtname, mode='w') as f:
        for joge_ann in joge_ann_list:
            f.write(joge_ann+"\n")
    with open("./ringo/train/"+"jogesayu_"+txtname, mode='w') as f:
        for jogesayu_ann in jogesayu_ann_list:
            f.write(jogesayu_ann+"\n")
print(folder,"完了")

これでtrainデータを4倍に増やすことができました。

いよいよ実装に取り掛かります。
その前に、YOLOv5をダウンロードしてGoogle ColaboratoryのMyDrive直下に置いときます。また、ringoフォルダもMyDrive直下に置いときます。画像が大量にあるとアップロードに時間がかかるかもしれません。そしてGoogle Colaboratoryでipynbファイルを作り実装していきます。

#環境構築をする
!pip install -r /content/drive/MyDrive/yolov5/requirements.txt
#カレントディレクトリを移動
%cd /content/drive/MyDrive/yolov5
#いざ学習!!
!python train.py --batch 32 --epochs 80 --data '/content/drive/My Drive/ringo/ringo.yaml' --name ringo
train: weights=yolov5s.pt, cfg=, data=/content/drive/My Drive/20211218_ringo/ringo.yaml, hyp=data/hyps/hyp.scratch.yaml, epochs=80, batch_size=32, img_size=[640, 640], rect=False, resume=False, nosave=False, notest=False, noautoanchor=False, evolve=None, bucket=, cache_images=False, image_weights=False, device=, multi_scale=False, single_cls=False, adam=False, sync_bn=False, workers=8, project=runs/train, entity=None, name=ringo, exist_ok=False, quad=False, linear_lr=False, label_smoothing=0.0, upload_dataset=False, bbox_interval=-1, save_period=-1, artifact_alias=latest, local_rank=-1
github: skipping check (not a git repository), for updates see https://github.com/ultralytics/yolov5
YOLOv5 🚀 2022-1-5 torch 1.10.0+cu111 CUDA:0 (Tesla T4, 15109.75MB)

hyperparameters: lr0=0.01, lrf=0.2, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=0.05, cls=0.5, cls_pw=1.0, obj=1.0, obj_pw=1.0, iou_t=0.2, anchor_t=4.0, fl_gamma=0.0, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, mosaic=1.0, mixup=0.0, copy_paste=0.0
tensorboard: Start with 'tensorboard --logdir runs/train', view at http://localhost:6006/
wandb: Install Weights & Biases for YOLOv5 logging with 'pip install wandb' (recommended)
Overriding model.yaml nc=80 with nc=6

                 from  n    params  module                                  arguments                     
  0                -1  1      3520  models.common.Focus                     [3, 32, 3]                    
  1                -1  1     18560  models.common.Conv                      [32, 64, 3, 2]                
  2                -1  1     18816  models.common.C3                        [64, 64, 1]                   
  3                -1  1     73984  models.common.Conv                      [64, 128, 3, 2]               
  4                -1  1    156928  models.common.C3                        [128, 128, 3]                 
  5                -1  1    295424  models.common.Conv                      [128, 256, 3, 2]              
  6                -1  1    625152  models.common.C3                        [256, 256, 3]                 
  7                -1  1   1180672  models.common.Conv                      [256, 512, 3, 2]              
  8                -1  1    656896  models.common.SPP                       [512, 512, [5, 9, 13]]        
  9                -1  1   1182720  models.common.C3                        [512, 512, 1, False]          
 10                -1  1    131584  models.common.Conv                      [512, 256, 1, 1]              
 11                -1  1         0  torch.nn.modules.upsampling.Upsample    [None, 2, 'nearest']          
 12           [-1, 6]  1         0  models.common.Concat                    [1]                           
 13                -1  1    361984  models.common.C3                        [512, 256, 1, False]          
 14                -1  1     33024  models.common.Conv                      [256, 128, 1, 1]              
 15                -1  1         0  torch.nn.modules.upsampling.Upsample    [None, 2, 'nearest']          
 16           [-1, 4]  1         0  models.common.Concat                    [1]                           
 17                -1  1     90880  models.common.C3                        [256, 128, 1, False]          
 18                -1  1    147712  models.common.Conv                      [128, 128, 3, 2]              
 19          [-1, 14]  1         0  models.common.Concat                    [1]                           
 20                -1  1    296448  models.common.C3                        [256, 256, 1, False]          
 21                -1  1    590336  models.common.Conv                      [256, 256, 3, 2]              
 22          [-1, 10]  1         0  models.common.Concat                    [1]                           
 23                -1  1   1182720  models.common.C3                        [512, 512, 1, False]          
 24      [17, 20, 23]  1     29667  models.yolo.Detect                      [6, [[10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373, 326]], [128, 256, 512]]
/usr/local/lib/python3.7/dist-packages/torch/functional.py:445: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at  ../aten/src/ATen/native/TensorShape.cpp:2157.)
  return _VF.meshgrid(tensors, **kwargs)  # type: ignore[attr-defined]
Model Summary: 283 layers, 7077027 parameters, 7077027 gradients, 16.4 GFLOPs

Transferred 356/362 items from yolov5s.pt
Scaled weight_decay = 0.0005
Optimizer groups: 62 .bias, 62 conv.weight, 59 other
albumentations: version 1.0.2 required by YOLOv5, but version 0.1.12 is currently installed
train: Scanning '/content/drive/My Drive/20211218_ringo/train' images and labels...3326 found, 0 missing, 0 empty, 0 corrupted: 100% 3326/3326 [02:17<00:00, 24.27it/s] 
train: New cache created: /content/drive/My Drive/20211218_ringo/train.cache
val: Scanning '/content/drive/My Drive/20211218_ringo/val' images and labels...1426 found, 0 missing, 0 empty, 0 corrupted: 100% 1426/1426 [01:04<00:00, 22.24it/s]
val: New cache created: /content/drive/My Drive/20211218_ringo/val.cache
Plotting labels... 

autoanchor: Analyzing anchors... anchors/target = 4.37, Best Possible Recall (BPR) = 1.0000
Image sizes 640 train, 640 test
Using 2 dataloader workers
Logging results to runs/train/ringo5
Starting training for 80 epochs...

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
      0/79     6.76G    0.0674   0.02536     0.053    0.1458        66       640: 100% 104/104 [02:13<00:00,  1.29s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.37it/s]
                 all       1426       1444       0.22      0.466      0.221      0.107

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
      1/79     7.16G   0.03995   0.01531   0.04688    0.1021        50       640: 100% 104/104 [02:07<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.36it/s]
                 all       1426       1444      0.231      0.724        0.3      0.195

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
      2/79     7.16G   0.03637   0.01269    0.0404   0.08946        78       640: 100% 104/104 [02:07<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.37it/s]
                 all       1426       1444      0.386      0.777      0.467      0.355

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
      3/79     7.16G   0.03263   0.01161   0.03417   0.07841        63       640: 100% 104/104 [02:07<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.32it/s]
                 all       1426       1444      0.553      0.819       0.67      0.535

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
      4/79     7.16G   0.03422   0.01122   0.03003   0.07547        56       640: 100% 104/104 [02:07<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.39it/s]
                 all       1426       1444      0.568      0.832      0.744      0.519

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
      5/79     7.16G   0.03559   0.01082    0.0279    0.0743        46       640: 100% 104/104 [02:07<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.39it/s]
                 all       1426       1444      0.615      0.798      0.688      0.533

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
      6/79     7.16G   0.03313   0.01088   0.02662   0.07063        60       640: 100% 104/104 [02:07<00:00,  1.22s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.34it/s]
                 all       1426       1444      0.712      0.797      0.773      0.654

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
      7/79     7.16G   0.03092   0.01053   0.02638   0.06783        63       640: 100% 104/104 [02:07<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.38it/s]
                 all       1426       1444      0.488      0.686      0.573      0.477

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
      8/79     7.16G   0.02965   0.01064   0.02573   0.06602        56       640: 100% 104/104 [02:07<00:00,  1.22s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.34it/s]
                 all       1426       1444      0.536      0.781      0.624      0.484

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
      9/79     7.16G   0.02822   0.01065   0.02596   0.06482        50       640: 100% 104/104 [02:08<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.37it/s]
                 all       1426       1444      0.563      0.738      0.648      0.554

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     10/79     7.16G   0.02588   0.01054   0.02648   0.06289        52       640: 100% 104/104 [02:08<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.37it/s]
                 all       1426       1444      0.644      0.788      0.719       0.59

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     11/79     7.16G   0.02512   0.01053   0.02467   0.06032        52       640: 100% 104/104 [02:08<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.37it/s]
                 all       1426       1444      0.688      0.755      0.734      0.639

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     12/79     7.16G   0.02343   0.01013   0.02327   0.05683        47       640: 100% 104/104 [02:07<00:00,  1.22s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.39it/s]
                 all       1426       1444      0.691      0.734       0.73      0.627

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     13/79     7.16G   0.02273  0.009827   0.02361   0.05617        58       640: 100% 104/104 [02:08<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.37it/s]
                 all       1426       1444      0.737      0.832        0.8      0.726

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     14/79     7.16G   0.02283   0.00976   0.02289   0.05548        59       640: 100% 104/104 [02:07<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.38it/s]
                 all       1426       1444      0.735      0.787      0.792      0.688

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     15/79     7.16G    0.0212  0.009737   0.02207   0.05301        53       640: 100% 104/104 [02:07<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.33it/s]
                 all       1426       1444      0.785      0.856      0.842      0.736

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     16/79     7.16G   0.02045  0.009858   0.02118   0.05149        59       640: 100% 104/104 [02:08<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.37it/s]
                 all       1426       1444      0.728      0.815      0.812      0.717

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     17/79     7.16G   0.01988  0.009515   0.02128   0.05067        52       640: 100% 104/104 [02:08<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.36it/s]
                 all       1426       1444      0.668      0.759      0.721      0.642

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     18/79     7.16G   0.02008  0.009256   0.02006    0.0494        51       640: 100% 104/104 [02:07<00:00,  1.22s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.34it/s]
                 all       1426       1444      0.772      0.858      0.838       0.76

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     19/79     7.16G   0.01986  0.009512   0.02012   0.04949        56       640: 100% 104/104 [02:08<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.36it/s]
                 all       1426       1444      0.712      0.763      0.774      0.707

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     20/79     7.16G   0.01925  0.009208   0.02021   0.04866        54       640: 100% 104/104 [02:07<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.36it/s]
                 all       1426       1444      0.793      0.853      0.864      0.798

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     21/79     7.16G   0.01893  0.009197   0.01853   0.04666        52       640: 100% 104/104 [02:08<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.37it/s]
                 all       1426       1444      0.755      0.813      0.827      0.758

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     22/79     7.16G   0.01893   0.00931   0.01829   0.04653        53       640: 100% 104/104 [02:08<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.35it/s]
                 all       1426       1444      0.801      0.823      0.844      0.774

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     23/79     7.16G   0.01788  0.009119   0.01738   0.04438        68       640: 100% 104/104 [02:07<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.36it/s]
                 all       1426       1444      0.793      0.849      0.864      0.798

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     24/79     7.16G   0.01779  0.009273   0.01808   0.04515        57       640: 100% 104/104 [02:08<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.35it/s]
                 all       1426       1444      0.754      0.849      0.854      0.797

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     25/79     7.16G   0.01777  0.009148   0.01771   0.04462        45       640: 100% 104/104 [02:07<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.36it/s]
                 all       1426       1444      0.692      0.766      0.791       0.73

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     26/79     7.16G   0.01813  0.009277   0.01793   0.04534        50       640: 100% 104/104 [02:08<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.36it/s]
                 all       1426       1444      0.756      0.787      0.809      0.738

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     27/79     7.16G   0.01774  0.008989   0.01771   0.04444        58       640: 100% 104/104 [02:08<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.34it/s]
                 all       1426       1444      0.813      0.851      0.881       0.82

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     28/79     7.16G   0.01761  0.009046   0.01746   0.04411        45       640: 100% 104/104 [02:08<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.38it/s]
                 all       1426       1444      0.787      0.852      0.863      0.805

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     29/79     7.16G   0.01736   0.00892    0.0166   0.04288        51       640: 100% 104/104 [02:08<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.32it/s]
                 all       1426       1444      0.836       0.86      0.888      0.828

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     30/79     7.16G    0.0165  0.008665   0.01588   0.04105        60       640: 100% 104/104 [02:08<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.37it/s]
                 all       1426       1444      0.822       0.86      0.883      0.831

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     31/79     7.16G   0.01677  0.008796   0.01647   0.04205        46       640: 100% 104/104 [02:08<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.37it/s]
                 all       1426       1444      0.772      0.812      0.846      0.786

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     32/79     7.16G   0.01639  0.008776   0.01677   0.04194        58       640: 100% 104/104 [02:08<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.35it/s]
                 all       1426       1444      0.785      0.786      0.833      0.784

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     33/79     7.16G   0.01651  0.008932   0.01588   0.04132        41       640: 100% 104/104 [02:09<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.37it/s]
                 all       1426       1444      0.846      0.849      0.893      0.835

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     34/79     7.16G   0.01668   0.00878   0.01539   0.04085        54       640: 100% 104/104 [02:08<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.34it/s]
                 all       1426       1444      0.827      0.817      0.872      0.817

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     35/79     7.16G   0.01528  0.008394    0.0144   0.03807        62       640: 100% 104/104 [02:08<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.31it/s]
                 all       1426       1444      0.861      0.865      0.906      0.853

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     36/79     7.16G   0.01532  0.008595   0.01425   0.03817        54       640: 100% 104/104 [02:09<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.34it/s]
                 all       1426       1444      0.834      0.882      0.889      0.836

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     37/79     7.16G   0.01513  0.008451   0.01422    0.0378        57       640: 100% 104/104 [02:08<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.34it/s]
                 all       1426       1444      0.791      0.857       0.87      0.827

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     38/79     7.16G   0.01547  0.008579   0.01446   0.03851        46       640: 100% 104/104 [02:08<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.33it/s]
                 all       1426       1444      0.863      0.883      0.911      0.867

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     39/79     7.16G   0.01534  0.008562   0.01507   0.03897        46       640: 100% 104/104 [02:08<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.32it/s]
                 all       1426       1444      0.793      0.826      0.861      0.812

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     40/79     7.16G   0.01503   0.00851   0.01475   0.03829        51       640: 100% 104/104 [02:08<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.39it/s]
                 all       1426       1444      0.861      0.873      0.895       0.85

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     41/79     7.16G   0.01498  0.008566   0.01305    0.0366        54       640: 100% 104/104 [02:07<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.32it/s]
                 all       1426       1444       0.87      0.873      0.904      0.861

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     42/79     7.16G   0.01486  0.008323   0.01417   0.03735        56       640: 100% 104/104 [02:08<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.36it/s]
                 all       1426       1444      0.839      0.852      0.901      0.862

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     43/79     7.16G   0.01456  0.008135   0.01297   0.03567        57       640: 100% 104/104 [02:09<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.39it/s]
                 all       1426       1444      0.858      0.861      0.901      0.857

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     44/79     7.16G   0.01438  0.008177   0.01233   0.03489        54       640: 100% 104/104 [02:08<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.34it/s]
                 all       1426       1444      0.893      0.872      0.921      0.883

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     45/79     7.16G   0.01426  0.008135   0.01365   0.03605        52       640: 100% 104/104 [02:08<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.36it/s]
                 all       1426       1444      0.817       0.83      0.874      0.829

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     46/79     7.16G   0.01424  0.008106   0.01254   0.03489        50       640: 100% 104/104 [02:08<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.34it/s]
                 all       1426       1444      0.884      0.896      0.916      0.875

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     47/79     7.16G   0.01381  0.007972   0.01213   0.03391        47       640: 100% 104/104 [02:08<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.33it/s]
                 all       1426       1444      0.832      0.858      0.898      0.845

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     48/79     7.16G    0.0139  0.008343   0.01204   0.03428        50       640: 100% 104/104 [02:08<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.33it/s]
                 all       1426       1444      0.895      0.885      0.925      0.882

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     49/79     7.16G   0.01345  0.008011    0.0122   0.03367        50       640: 100% 104/104 [02:08<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.33it/s]
                 all       1426       1444      0.905      0.905      0.934      0.893

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     50/79     7.16G   0.01436  0.007994   0.01128   0.03363        64       640: 100% 104/104 [02:08<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.36it/s]
                 all       1426       1444      0.915      0.899      0.931      0.894

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     51/79     7.16G   0.01342  0.007906   0.01144   0.03277        50       640: 100% 104/104 [02:09<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.36it/s]
                 all       1426       1444      0.856      0.865      0.899      0.858

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     52/79     7.16G   0.01337  0.007967   0.01128   0.03261        52       640: 100% 104/104 [02:09<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.35it/s]
                 all       1426       1444      0.877       0.88      0.924      0.887

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     53/79     7.16G   0.01227  0.007657  0.009903   0.02983        58       640: 100% 104/104 [02:08<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.34it/s]
                 all       1426       1444      0.888      0.896      0.919      0.882

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     54/79     7.16G   0.01354  0.008044   0.01134   0.03292        53       640: 100% 104/104 [02:09<00:00,  1.25s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.36it/s]
                 all       1426       1444      0.884      0.902      0.919      0.886

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     55/79     7.16G   0.01301   0.00753   0.01049   0.03103        53       640: 100% 104/104 [02:08<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.34it/s]
                 all       1426       1444      0.914       0.89      0.939      0.899

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     56/79     7.16G    0.0127  0.007756   0.01073   0.03119        54       640: 100% 104/104 [02:08<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.35it/s]
                 all       1426       1444      0.882      0.917      0.931      0.894

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     57/79     7.16G   0.01224  0.007684  0.009956   0.02988        68       640: 100% 104/104 [02:08<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.34it/s]
                 all       1426       1444      0.898      0.914      0.927      0.893

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     58/79     7.16G   0.01272  0.007729   0.01029   0.03073        54       640: 100% 104/104 [02:08<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.36it/s]
                 all       1426       1444      0.899      0.923      0.936      0.901

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     59/79     7.16G   0.01245  0.007784  0.009965    0.0302        57       640: 100% 104/104 [02:08<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.32it/s]
                 all       1426       1444      0.905      0.901      0.937      0.906

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     60/79     7.16G   0.01255  0.007615   0.01035   0.03052        50       640: 100% 104/104 [02:08<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.35it/s]
                 all       1426       1444      0.895      0.912      0.941      0.907

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     61/79     7.16G   0.01203  0.007687  0.009785    0.0295        56       640: 100% 104/104 [02:08<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.34it/s]
                 all       1426       1444       0.91        0.9      0.927      0.891

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     62/79     7.16G   0.01238  0.007606  0.009322   0.02931        53       640: 100% 104/104 [02:08<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.33it/s]
                 all       1426       1444       0.93      0.898      0.944      0.909

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     63/79     7.16G   0.01182  0.007661  0.009607   0.02908        52       640: 100% 104/104 [02:09<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.38it/s]
                 all       1426       1444       0.92       0.91      0.939      0.905

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     64/79     7.16G   0.01259  0.007573  0.009872   0.03003        47       640: 100% 104/104 [02:08<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.36it/s]
                 all       1426       1444      0.908      0.903      0.936      0.902

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     65/79     7.16G   0.01199  0.007558  0.008924   0.02847        56       640: 100% 104/104 [02:08<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.36it/s]
                 all       1426       1444      0.914      0.901      0.938      0.905

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     66/79     7.16G   0.01161  0.007485  0.008896   0.02799        63       640: 100% 104/104 [02:08<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.34it/s]
                 all       1426       1444      0.911      0.905      0.942      0.909

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     67/79     7.16G   0.01187  0.007443  0.008926   0.02824        59       640: 100% 104/104 [02:08<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.33it/s]
                 all       1426       1444      0.928       0.93      0.946      0.915

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     68/79     7.16G   0.01158  0.007501  0.009095   0.02818        50       640: 100% 104/104 [02:08<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.32it/s]
                 all       1426       1444      0.907      0.926      0.945      0.909

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     69/79     7.16G   0.01223  0.007519  0.008881   0.02863        50       640: 100% 104/104 [02:09<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.31it/s]
                 all       1426       1444      0.924       0.93      0.948      0.916

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     70/79     7.16G   0.01172  0.007522  0.009445   0.02869        57       640: 100% 104/104 [02:08<00:00,  1.23s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.35it/s]
                 all       1426       1444      0.927      0.912      0.942      0.912

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     71/79     7.16G   0.01126  0.007415  0.008218   0.02689        58       640: 100% 104/104 [02:09<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.34it/s]
                 all       1426       1444      0.927       0.91      0.944      0.913

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     72/79     7.16G   0.01153  0.007292  0.009586   0.02841        45       640: 100% 104/104 [02:08<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.35it/s]
                 all       1426       1444      0.917      0.893      0.931      0.899

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     73/79     7.16G   0.01145  0.007383  0.009001   0.02783        50       640: 100% 104/104 [02:09<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.34it/s]
                 all       1426       1444      0.921      0.927      0.943      0.911

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     74/79     7.16G   0.01172  0.007423  0.008916   0.02806        57       640: 100% 104/104 [02:09<00:00,  1.25s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.34it/s]
                 all       1426       1444      0.925      0.919      0.948      0.916

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     75/79     7.16G   0.01126  0.007487   0.00857   0.02732        60       640: 100% 104/104 [02:10<00:00,  1.25s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.32it/s]
                 all       1426       1444      0.927      0.904       0.94      0.912

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     76/79     7.16G   0.01134  0.007448  0.008344   0.02713        40       640: 100% 104/104 [02:10<00:00,  1.25s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.34it/s]
                 all       1426       1444       0.91      0.915      0.945      0.915

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     77/79     7.16G    0.0112  0.007364  0.008533    0.0271        55       640: 100% 104/104 [02:10<00:00,  1.25s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:16<00:00,  1.37it/s]
                 all       1426       1444      0.931      0.921      0.948      0.921

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     78/79     7.16G   0.01093  0.007415  0.008031   0.02637        75       640: 100% 104/104 [02:09<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:17<00:00,  1.34it/s]
                 all       1426       1444       0.92      0.905      0.943      0.914

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
     79/79     7.16G   0.01121  0.007504  0.008478   0.02719        56       640: 100% 104/104 [02:09<00:00,  1.24s/it]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100% 23/23 [00:19<00:00,  1.19it/s]
                 all       1426       1444      0.918      0.909      0.944      0.912
              level1       1426        247      0.817      0.745      0.829      0.767
              level2       1426        241      0.875      0.938      0.936      0.912
              level3       1426        242      0.911      0.872       0.94      0.913
              level4       1426        223      0.937      0.937      0.973      0.943
              level5       1426        229      0.987      0.968      0.994      0.965
              level6       1426        262      0.981      0.993      0.995      0.972
80 epochs completed in 3.266 hours.

Optimizer stripped from runs/train/ringo5/weights/last.pt, 14.4MB
Optimizer stripped from runs/train/ringo5/weights/best.pt, 14.4MB

結構時間もかかるかと思います。valファイルを作っておいたことで実行の最後にどれくらいの精度で検出することができているのかわかります。

次に各種指標Precision,Recall,mAPなどの各種指標の出力を見てみます。
以下のコマンドを入力数するとGoogle Colaboratoryのoutput欄に出力されます。

%load_ext tensorboard
%tensorboard --logdir runs

output
leaderboard.png

一応その結果も/content/drive/MyDrive/yolov5/runs/train/ringo/のフォルダにまとめられています。result.pngを以下に出力しておきます。
results.png
様々な指標が一覧にまとめられており、非常にわかりやすいですね。

次にテストデータも使って成熟度分類の詳細の精度(物体検出の精度)を見てみたいと思います。Google ColaboratoryのMyDrive/yolov5直下にこちらのGithubに記載されているtest.pyファイルを置きます。そして以下のコマンドを実行するとテストデータの予測精度を確認することができます。

#テストデータを用いて精度の検証
!python test.py --data /content/drive/MyDrive/ringo/ringo.yaml --weights runs/train/ringo/weights/best.pt

検出精度は/content/drive/MyDrive/yolov5/runs/test/exp/confusion_matrix.pngとかに入っていると思います。その混合行列を以下に示します。
image.png

各成熟度において同成熟度が最も予測精度が高くなっています。また、間違えていても±1の範囲内、もしくは未検出であったため、的外れな成熟度判断をしていないといえるのではないかと思います。

では実際のりんごの画像や動画やカメラを用いて成熟度分類をやってみます。モデル自体はGoogle ColaboratoryのGPU環境により作ったので後はローカルPCでも大丈夫なのでローカルPCで動作させることにします。まずMyDriveにあるYOLOv5をローカルPCにダウンロードします。

コマンドプロンプトを開き、YOLOv5のディレクトリまで移動します

cd "YOLOv5のディレクトリのパス"

環境構築をします。

pip install -r requirements.txt

これで実際に動かす際の準備はできました。実際に動かしてみます。

画像の場合

python detect.py --weights runs/train/ringo/weights/best.pt --source 画像へのパス(クオーテーションで囲む必要なし)   

出力111_97.png

動画の場合

python detect.py --weights runs/train/ringo/weights/best.pt --source 動画へのパス(クオーテーションで囲む必要なし)   

ezgif-1-182f889551.gif

PCカメラの場合

python detect.py --weights runs/train/ringo/weights/best.pt --source 0   

ezgif-1-13ec6e9431.gif

このような形で動かすことができます。

終わりに

以上でYOLOv5を用いたりんごのリアルタイム成熟度分析システムの構築は終わりです。興味があれば是非試してみてください。なかなかの精度でりんごの成熟度を分類することができたのではないかと思います。閲覧ありがとうございました。

9
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
14