Object Detection (demo)

bbkyoo·2021년 9월 30일
0

Detection

목록 보기
3/4
!pip install mmcv-full
Collecting mmcv-full
  Downloading mmcv-full-1.3.14.tar.gz (324 kB)
     |████████████████████████████████| 324 kB 5.0 MB/s 
[?25hCollecting addict
  Downloading addict-2.4.0-py3-none-any.whl (3.8 kB)
Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from mmcv-full) (1.19.5)
Requirement already satisfied: packaging in /usr/local/lib/python3.7/dist-packages (from mmcv-full) (21.0)
Requirement already satisfied: Pillow in /usr/local/lib/python3.7/dist-packages (from mmcv-full) (7.1.2)
Requirement already satisfied: pyyaml in /usr/local/lib/python3.7/dist-packages (from mmcv-full) (3.13)
Collecting yapf
  Downloading yapf-0.31.0-py2.py3-none-any.whl (185 kB)
     |████████████████████████████████| 185 kB 65.2 MB/s 
[?25hRequirement already satisfied: pyparsing>=2.0.2 in /usr/local/lib/python3.7/dist-packages (from packaging->mmcv-full) (2.4.7)
Building wheels for collected packages: mmcv-full
  Building wheel for mmcv-full (setup.py) ... [?25l[?25hdone
  Created wheel for mmcv-full: filename=mmcv_full-1.3.14-cp37-cp37m-linux_x86_64.whl size=31616700 sha256=3f13fd68ba90bf5561b8a06cd4533e13506bf40f5655a7d8373910230cfa39d7
  Stored in directory: /root/.cache/pip/wheels/5e/54/62/69c99dc3c9937bca64126f81cbe315ae6c8e6e98c43fa7392d
Successfully built mmcv-full
Installing collected packages: yapf, addict, mmcv-full
Successfully installed addict-2.4.0 mmcv-full-1.3.14 yapf-0.31.0
!git clone https://github.com/open-mmlab/mmdetection.git
Cloning into 'mmdetection'...
remote: Enumerating objects: 21083, done.
remote: Counting objects: 100% (67/67), done.
remote: Compressing objects: 100% (62/62), done.
remote: Total 21083 (delta 13), reused 42 (delta 5), pack-reused 21016
Receiving objects: 100% (21083/21083), 24.83 MiB | 38.06 MiB/s, done.
Resolving deltas: 100% (14713/14713), done.
%cd mmdetection
/content/mmdetection
!python setup.py install
!ls
CITATION.cff  docs	   mmdet	    README_zh-CN.md   setup.cfg
configs       docs_zh-CN   model-index.yml  requirements      setup.py
demo	      LICENSE	   pytest.ini	    requirements.txt  tests
docker	      MANIFEST.in  README.md	    resources	      tools
!mkdir checkpoints
!wget -O /content/mmdetection/checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
--2021-09-29 03:14:33--  https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
Resolving download.openmmlab.com (download.openmmlab.com)... 47.252.96.35
Connecting to download.openmmlab.com (download.openmmlab.com)|47.252.96.35|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 167287506 (160M) [application/octet-stream]
Saving to: ‘/content/mmdetection/checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth’

/content/mmdetectio 100%[===================>] 159.54M  7.89MB/s    in 21s     

2021-09-29 03:14:55 (7.75 MB/s) - ‘/content/mmdetection/checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth’ saved [167287506/167287506]
!ls -la ./checkpoints/
total 163376
drwxr-xr-x  2 root root      4096 Sep 29 03:14 .
drwxr-xr-x 19 root root      4096 Sep 29 03:12 ..
-rw-r--r--  1 root root 167287506 Aug 28  2020 faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
from mmdet.apis import init_detector, inference_detector, show_result_pyplot
config_file = '/content/mmdetection/configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'
checkpoint_file = '/content/mmdetection/checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'
model = init_detector(config_file, checkpoint_file, device='cuda:0')
/usr/local/lib/python3.7/dist-packages/mmdet-2.17.0-py3.7.egg/mmdet/core/anchor/builder.py:17: UserWarning: ``build_anchor_generator`` would be deprecated soon, please use ``build_prior_generator`` 
  '``build_anchor_generator`` would be deprecated soon, please use '


Use load_from_local loader
%cd mmdetection/
img = 'demo/demo.jpg'
result = inference_detector(model, img)
/content/mmdetection


/usr/local/lib/python3.7/dist-packages/torch/nn/functional.py:718: UserWarning: Named tensors and all their associated APIs are an experimental feature and subject to change. Please do not use them for anything important until they are released as stable. (Triggered internally at  /pytorch/c10/core/TensorImpl.h:1156.)
  return torch.max_pool2d(input, kernel_size, stride, padding, dilation, ceil_mode)
/usr/local/lib/python3.7/dist-packages/mmdet-2.17.0-py3.7.egg/mmdet/core/anchor/anchor_generator.py:324: UserWarning: ``grid_anchors`` would be deprecated soon. Please use ``grid_priors`` 
  warnings.warn('``grid_anchors`` would be deprecated soon. '
/usr/local/lib/python3.7/dist-packages/mmdet-2.17.0-py3.7.egg/mmdet/core/anchor/anchor_generator.py:361: UserWarning: ``single_level_grid_anchors`` would be deprecated soon. Please use ``single_level_grid_priors`` 
  '``single_level_grid_anchors`` would be deprecated soon. '
type(result)
list
len(result)
80
result[1]
array([], shape=(0, 5), dtype=float32)
show_result_pyplot(model, img, result, score_thr=0.6)

result[2]
array([[6.09650024e+02, 1.13805901e+02, 6.34511658e+02, 1.36951904e+02,
        9.88766015e-01],
       [4.81773712e+02, 1.10480995e+02, 5.22459717e+02, 1.30407104e+02,
        9.87157285e-01],
       [1.01821303e+00, 1.12144722e+02, 6.04374390e+01, 1.44173752e+02,
        9.83206093e-01],
       [2.94623749e+02, 1.17035233e+02, 3.78022675e+02, 1.50550873e+02,
        9.71326888e-01],
       [3.96328979e+02, 1.11203323e+02, 4.32490540e+02, 1.32729263e+02,
        9.67802048e-01],
       [5.90976318e+02, 1.10802658e+02, 6.15401917e+02, 1.26493553e+02,
        9.59414959e-01],
       [2.67582001e+02, 1.05686005e+02, 3.28818756e+02, 1.28226547e+02,
        9.59253430e-01],
       [1.66856735e+02, 1.08006599e+02, 2.19100693e+02, 1.40194809e+02,
        9.56841230e-01],
       [1.89769592e+02, 1.09801109e+02, 3.00310822e+02, 1.53781891e+02,
        9.51012254e-01],
       [4.29822510e+02, 1.05655380e+02, 4.82741547e+02, 1.32376724e+02,
        9.45850074e-01],
       [5.55000916e+02, 1.09784981e+02, 5.92761780e+02, 1.27808495e+02,
        9.43992496e-01],
       [5.96790390e+01, 9.31828003e+01, 8.34545517e+01, 1.06242912e+02,
        9.33143973e-01],
       [9.78446579e+01, 8.96542969e+01, 1.18172356e+02, 1.01011108e+02,
        8.66324425e-01],
       [1.43899002e+02, 9.61869888e+01, 1.64599808e+02, 1.04979256e+02,
        8.26784194e-01],
       [8.55894165e+01, 8.99445801e+01, 9.88920822e+01, 9.85285416e+01,
        7.53480315e-01],
       [9.78282623e+01, 9.07443695e+01, 1.10298058e+02, 9.97373276e+01,
        7.16600299e-01],
       [2.23579224e+02, 9.85184631e+01, 2.49845108e+02, 1.07509857e+02,
        6.00782573e-01],
       [1.68928635e+02, 9.59468994e+01, 1.82843445e+02, 1.05694962e+02,
        5.91999710e-01],
       [1.35021347e+02, 9.08739395e+01, 1.50607025e+02, 1.02798874e+02,
        5.54030299e-01],
       [0.00000000e+00, 1.11521957e+02, 1.45326672e+01, 1.25850281e+02,
        5.43520391e-01],
       [5.53896606e+02, 1.16170540e+02, 5.62602295e+02, 1.26390923e+02,
        4.76758391e-01],
       [3.75809753e+02, 1.19579056e+02, 3.82376495e+02, 1.32113892e+02,
        4.61192340e-01],
       [1.37924118e+02, 9.37975311e+01, 1.54497177e+02, 1.04659683e+02,
        4.00998443e-01],
       [5.55009033e+02, 1.10952698e+02, 5.74925659e+02, 1.26912033e+02,
        3.43850523e-01],
       [5.54043152e+02, 1.00959076e+02, 5.61297913e+02, 1.10927711e+02,
        2.87964016e-01],
       [6.14741028e+02, 1.01987068e+02, 6.35481628e+02, 1.12593704e+02,
        2.61201501e-01],
       [5.70760315e+02, 1.09679382e+02, 5.90286133e+02, 1.27248878e+02,
        2.58405149e-01],
       [4.78543103e-01, 1.11568169e+02, 2.25040894e+01, 1.42623535e+02,
        2.56050467e-01],
       [3.75093140e+02, 1.11696442e+02, 4.20536804e+02, 1.33691055e+02,
        2.55963445e-01],
       [2.62747253e+02, 1.07565620e+02, 3.26765930e+02, 1.43925293e+02,
        2.09969312e-01],
       [7.91312561e+01, 9.03788834e+01, 1.00247879e+02, 1.01080872e+02,
        2.03961387e-01],
       [6.09313477e+02, 1.13308517e+02, 6.25961975e+02, 1.25342506e+02,
        1.97424501e-01],
       [1.35304840e+02, 9.23771439e+01, 1.64080185e+02, 1.04992455e+02,
        1.49972677e-01],
       [6.73540573e+01, 8.85008087e+01, 8.29853516e+01, 9.73942108e+01,
        1.48384705e-01],
       [5.40852417e+02, 1.13848946e+02, 5.61855530e+02, 1.26198776e+02,
        1.47629276e-01],
       [3.51735046e+02, 1.09432648e+02, 4.39310089e+02, 1.34819733e+02,
        1.41735703e-01],
       [9.63179092e+01, 8.98780594e+01, 1.53287766e+02, 1.01776367e+02,
        1.32708862e-01],
       [4.54495049e+01, 1.17444977e+02, 6.18955803e+01, 1.44275055e+02,
        1.25890508e-01],
       [6.06407532e+02, 1.12215973e+02, 6.18935669e+02, 1.24957237e+02,
        1.10721856e-01],
       [1.02152626e+02, 9.36143646e+01, 1.41081863e+02, 1.01598961e+02,
        8.13645124e-02],
       [3.98364838e+02, 1.12081459e+02, 4.09389862e+02, 1.32897766e+02,
        7.64545947e-02],
       [5.39245911e+02, 1.12394836e+02, 5.48756714e+02, 1.21964462e+02,
        7.32634217e-02],
       [6.09156555e+02, 1.04017464e+02, 6.35472107e+02, 1.26777184e+02,
        6.47422373e-02],
       [3.75894713e+00, 9.85745163e+01, 7.45848389e+01, 1.35155014e+02,
        6.32169396e-02],
       [1.68166473e+02, 9.14260483e+01, 2.20303146e+02, 1.07955681e+02,
        5.16179651e-02],
       [7.09723892e+01, 9.02684860e+01, 1.05398132e+02, 1.03825508e+02,
        5.15382327e-02]], dtype=float32)
                    {0:'person',1:'bicycle',2:'car',3:'motorbike',4:'aeroplane',5:'bus',6:'train',7:'truck',8:'boat',9:'traffic light',10:'fire hydrant',
                    11:'stop sign',12:'parking meter',13:'bench',14:'bird',15:'cat',16:'dog',17:'horse',18:'sheep',19:'cow',20:'elephant',
                    21:'bear',22:'zebra',23:'giraffe',24:'backpack',25:'umbrella',26:'handbag',27:'tie',28:'suitcase',29:'frisbee',30:'skis',
                    31:'snowboard',32:'sports ball',33:'kite',34:'baseball bat',35:'baseball glove',36:'skateboard',37:'surfboard',38:'tennis racket',39:'bottle',40:'wine glass',
                    41:'cup',42:'fork',43:'knife',44:'spoon',45:'bowl',46:'banana',47:'apple',48:'sandwich',49:'orange',50:'broccoli',
                    51:'carrot',52:'hot dog',53:'pizza',54:'donut',55:'cake',56:'chair',57:'sofa',58:'pottedplant',59:'bed',60:'diningtable',
                    61:'toilet',62:'tvmonitor',63:'laptop',64:'mouse',65:'remote',66:'keyboard',67:'cell phone',68:'microwave',69:'oven',70:'toaster',
                    71:'sink',72:'refrigerator',73:'book',74:'clock',75:'vase',76:'scissors',77:'teddy bear',78:'hair drier',79:'toothbrush' }
profile
어제보다 오늘 더 성장하는 개발자!

0개의 댓글