공부 기록
Object Detection(1001_day5) - yolov3 본문
In [1]:
!git clone https://github.com/ultralytics/yolov3 # clone repo
%cd yolov3
%pip install -qr requirements.txt # install dependencies
import torch
from IPython.display import Image, clear_output # to display images
clear_output()
print(f"Setup complete. Using torch {torch.__version__} ({torch.cuda.get_device_properties(0).name if torch.cuda.is_available() else 'CPU'})")
Setup complete. Using torch 1.9.0+cu102 (Tesla K80)
Pretrained model 다운로드¶
In [2]:
!python detect.py --weights yolov3.pt --img 640 --conf 0.25 --source data/images/
Image(filename='runs/detect/exp/zidane.jpg', width=600)
Namespace(agnostic_nms=False, augment=False, classes=None, conf_thres=0.25, device='', exist_ok=False, hide_conf=False, hide_labels=False, img_size=640, iou_thres=0.45, line_thickness=3, max_det=1000, name='exp', nosave=False, project='runs/detect', save_conf=False, save_crop=False, save_txt=False, source='data/images/', update=False, view_img=False, weights=['yolov3.pt']) YOLOv3 🚀 v9.5.0-13-g1be3170 torch 1.9.0+cu102 CUDA:0 (Tesla K80, 11441.1875MB) Downloading https://github.com/ultralytics/yolov3/releases/download/v9.5.0/yolov3.pt to yolov3.pt... 100% 118M/118M [00:02<00:00, 49.2MB/s] Fusing layers... Model Summary: 261 layers, 61922845 parameters, 0 gradients image 1/2 /content/yolov3/data/images/bus.jpg: 640x480 4 persons, 1 bus, Done. (0.156s) image 2/2 /content/yolov3/data/images/zidane.jpg: 384x640 2 persons, 3 ties, Done. (0.104s) Results saved to runs/detect/exp Done. (0.582s)
Out[2]:
In [ ]:
!python detect.py --weights yolov3.pt --img 640 --conf 0.25 --source data/images/car_chasing1_Trim.mp4
In [15]:
%pwd
Out[15]:
'/content/yolov3'
In [16]:
# Download COCO128
torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/releases/download/v1.0/coco128.zip', 'tmp.zip')
!unzip -q tmp.zip -d ../ && rm tmp.zip
In [18]:
# Train YOLOv3 on COCO128 for 3 epochs
!python train.py --img 640 --batch 8 --epochs 3 --data coco128.yaml --weights yolov3.pt --nosave --cache
github: up to date with https://github.com/ultralytics/yolov3 ✅ YOLOv3 🚀 v9.5.0-13-g1be3170 torch 1.9.0+cu102 CUDA:0 (Tesla K80, 11441.1875MB) Namespace(adam=False, artifact_alias='latest', batch_size=8, bbox_interval=-1, bucket='', cache_images=True, cfg='', data='./data/coco128.yaml', device='', entity=None, epochs=3, evolve=False, exist_ok=False, global_rank=-1, hyp='data/hyp.scratch.yaml', image_weights=False, img_size=[640, 640], label_smoothing=0.0, linear_lr=False, local_rank=-1, multi_scale=False, name='exp', noautoanchor=False, nosave=True, notest=False, project='runs/train', quad=False, rect=False, resume=False, save_dir='runs/train/exp2', save_period=-1, single_cls=False, sync_bn=False, total_batch_size=8, upload_dataset=False, weights='yolov3.pt', workers=8, world_size=1) tensorboard: Start with 'tensorboard --logdir runs/train', view at http://localhost:6006/ 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 wandb: Install Weights & Biases for YOLOv3 logging with 'pip install wandb' (recommended) from n params module arguments 0 -1 1 928 models.common.Conv [3, 32, 3, 1] 1 -1 1 18560 models.common.Conv [32, 64, 3, 2] 2 -1 1 20672 models.common.Bottleneck [64, 64] 3 -1 1 73984 models.common.Conv [64, 128, 3, 2] 4 -1 2 164608 models.common.Bottleneck [128, 128] 5 -1 1 295424 models.common.Conv [128, 256, 3, 2] 6 -1 8 2627584 models.common.Bottleneck [256, 256] 7 -1 1 1180672 models.common.Conv [256, 512, 3, 2] 8 -1 8 10498048 models.common.Bottleneck [512, 512] 9 -1 1 4720640 models.common.Conv [512, 1024, 3, 2] 10 -1 4 20983808 models.common.Bottleneck [1024, 1024] 11 -1 1 5245952 models.common.Bottleneck [1024, 1024, False] 12 -1 1 525312 models.common.Conv [1024, 512, [1, 1]] 13 -1 1 4720640 models.common.Conv [512, 1024, 3, 1] 14 -1 1 525312 models.common.Conv [1024, 512, 1, 1] 15 -1 1 4720640 models.common.Conv [512, 1024, 3, 1] 16 -2 1 131584 models.common.Conv [512, 256, 1, 1] 17 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest'] 18 [-1, 8] 1 0 models.common.Concat [1] 19 -1 1 1377792 models.common.Bottleneck [768, 512, False] 20 -1 1 1312256 models.common.Bottleneck [512, 512, False] 21 -1 1 131584 models.common.Conv [512, 256, 1, 1] 22 -1 1 1180672 models.common.Conv [256, 512, 3, 1] 23 -2 1 33024 models.common.Conv [256, 128, 1, 1] 24 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest'] 25 [-1, 6] 1 0 models.common.Concat [1] 26 -1 1 344832 models.common.Bottleneck [384, 256, False] 27 -1 2 656896 models.common.Bottleneck [256, 256, False] 28 [27, 22, 15] 1 457725 models.yolo.Detect [80, [[10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373, 326]], [256, 512, 1024]] Model Summary: 333 layers, 61949149 parameters, 61949149 gradients, 156.4 GFLOPS Transferred 440/440 items from yolov3.pt Scaled weight_decay = 0.0005 Optimizer groups: 75 .bias, 75 conv.weight, 72 other train: Scanning '../coco128/labels/train2017.cache' images and labels... 128 found, 0 missing, 2 empty, 0 corrupted: 100% 128/128 [00:00<?, ?it/s] train: Caching images (0.1GB): 100% 128/128 [00:00<00:00, 255.81it/s] val: Scanning '../coco128/labels/train2017.cache' images and labels... 128 found, 0 missing, 2 empty, 0 corrupted: 100% 128/128 [00:00<?, ?it/s] val: Caching images (0.1GB): 100% 128/128 [00:00<00:00, 156.65it/s] [W pthreadpool-cpp.cc:90] Warning: Leaking Caffe2 thread-pool after fork. (function pthreadpool) [W pthreadpool-cpp.cc:90] Warning: Leaking Caffe2 thread-pool after fork. (function pthreadpool) Plotting labels... autoanchor: Analyzing anchors... anchors/target = 4.26, Best Possible Recall (BPR) = 0.9946 Image sizes 640 train, 640 test Using 2 dataloader workers Logging results to runs/train/exp2 Starting training for 3 epochs... Epoch gpu_mem box obj cls total labels img_size 0/2 7.31G 0.02774 0.02394 0.007242 0.05892 111 640: 0% 0/16 [00:10<?, ?it/s]/usr/local/lib/python3.7/dist-packages/torch/jit/_trace.py:730: UserWarning: The input to trace is already a ScriptModule, tracing it is a no-op. Returning the object as is. "The input to trace is already a ScriptModule, tracing it is a no-op. Returning the object as is." 0/2 9.67G 0.02976 0.02503 0.008363 0.06316 68 640: 100% 16/16 [01:00<00:00, 3.75s/it] Class Images Labels P R mAP@.5 mAP@.5:.95: 100% 8/8 [00:27<00:00, 3.40s/it] all 128 929 0.802 0.662 0.788 0.541 Epoch gpu_mem box obj cls total labels img_size 1/2 9.51G 0.03084 0.02501 0.008131 0.06398 86 640: 100% 16/16 [00:31<00:00, 1.99s/it] Class Images Labels P R mAP@.5 mAP@.5:.95: 100% 8/8 [00:07<00:00, 1.03it/s] all 128 929 0.797 0.672 0.79 0.541 Epoch gpu_mem box obj cls total labels img_size 2/2 9.51G 0.02896 0.02226 0.01129 0.0625 121 640: 100% 16/16 [00:31<00:00, 1.99s/it] Class Images Labels P R mAP@.5 mAP@.5:.95: 100% 8/8 [00:09<00:00, 1.13s/it] all 128 929 0.805 0.673 0.796 0.541 3 epochs completed in 0.050 hours. Optimizer stripped from runs/train/exp2/weights/last.pt, 124.2MB Optimizer stripped from runs/train/exp2/weights/best.pt, 124.2MB
In [3]:
from IPython.display import Image
In [7]:
Image("./test1.PNG", width=700)
Out[7]:
In [8]:
Image("./test2.PNG", width=700)
Out[8]:
In [ ]:
'playdata' 카테고리의 다른 글
11/11_오토인코더를 활용한 이상데이터 찾기 - MNIST dataset.ipynb (0) | 2021.11.11 |
---|---|
10/07 - 2019 주유소 판매가격 dataset (0) | 2021.10.07 |
Object Detection(0930_day4) - Oxford pet dataset (0) | 2021.09.30 |
Object Detection(0929_day3) - kitti tiny dataset (0) | 2021.09.29 |
Object Detection(0929_day3) - demo (0) | 2021.09.29 |
Comments