ざっくばらんメモ_23:Detectron

FAIR Detectronのトライ

Facebook Researchが最近公開したCaffe2ベースの画像認識ライブラリDetectronを試す。
主なインストール手順はGitHubに公開。
環境はaws p2.xlarge, ubuntu 16.04、conda environmentを利用。
インストール環境を整えるにあたって要求環境がpython2であることに注意する。

まずCaffe2ベースなのでこのページに則ってインストールを行う。
インストールは地味に時間がかかる。
ここで現在caffe2はcuda8.0のみサポートなので気を付ける。
またDetectronはCudnn6.0でテストされているので、合わせておくのが無難。
またインストール時はsource deactivateでconda環境から抜けておいた方がライブラリリンクの問題を回避できて無難。
無事インストールを終えるてテストコードを走らせようとするとエラーが出た。

RuntimeError: module compiled against API version 0xc but this version of numpy is 0xb

この問題はpip install -U numpyで解決できた。

これで準備ができたので、COCO API、Detectronをcloneしインストール。ここまで来るとスムーズ。
続いてpretrainモデルを用いたinferenceを行ってみる。
簡単に動くでもスクリプトがあるのでそれを走らせるとpretrain済のMask RCNNがダウンロードされてきてすぐに適用され結果が返ってくるので とてもシンプルであった。
特に処理時間がちゃんと出力されてくるのがリアルタイムを意識したcaffe2らしくて良い

python2 tools/infer_simple.py \
    --cfg configs/12_2017_baselines/e2e_mask_rcnn_R-101-FPN_2x.yaml \
    --output-dir /tmp/detectron-visualizations \
    --image-ext jpg \
    --wts https://s3-us-west-2.amazonaws.com/detectron/35861858/12_2017_baselines/e2e_mask_rcnn_R-101-FPN_2x.yaml.02_32_51.SgT4y1cO/output/train/coco_2014_train:coco_2014_valminusminival/generalized_rcnn/model_final.pkl \
    demo
E0205 04:16:35.846588 29047 init_intrinsics_check.cc:54] CPU feature avx is present on your machine, but the Caffe2 binary is not compiled with it. It means you may not get the full speed of your CPU.
E0205 04:16:35.846622 29047 init_intrinsics_check.cc:54] CPU feature avx2 is present on your machine, but the Caffe2 binary is not compiled with it. It means you may not get the full speed of your CPU.
E0205 04:16:35.846634 29047 init_intrinsics_check.cc:54] CPU feature fma is present on your machine, but the Caffe2 binary is not compiled with it. It means you may not get the full speed of your CPU.
INFO io.py:  67: Downloading remote file https://s3-us-west-2.amazonaws.com/detectron/ImageNetPretrained/MSRA/R-101.pkl to /tmp/detectron-download-cache/ImageNetPretrained/MSRA/R-101.pkl
  [============================================================] 100.0% of 170.2MB file  
INFO io.py:  67: Downloading remote file https://s3-us-west-2.amazonaws.com/detectron/35861858/12_2017_baselines/e2e_mask_rcnn_R-101-FPN_2x.yaml.02_32_51.SgT4y1cO/output/train/coco_2014_train:coco_2014_valminusminival/generalized_rcnn/model_final.pkl to /tmp/detectron-download-cache/35861858/12_2017_baselines/e2e_mask_rcnn_R-101-FPN_2x.yaml.02_32_51.SgT4y1cO/output/train/coco_2
014_train:coco_2014_valminusminival/generalized_rcnn/model_final.pkl
  [============================================================] 100.0% of 490.5MB file  
WARNING cnn.py:  40: [====DEPRECATE WARNING====]: you are creating an object from CNNModelHelper class which will be deprecated soon. Please use ModelHelper object with brew module. For more information, please refer to caffe2.ai and python/brew.py, python/brew_test.py for more information.
INFO net.py:  57: Loading weights from: /tmp/detectron-download-cache/35861858/12_2017_baselines/e2e_mask_rcnn_R-101-FPN_2x.yaml.02_32_51.SgT4y1cO/output/train/coco_2014_train:coco_2014_valminusminival/generalized_rcnn/model_final.pkl
I0205 04:16:54.497457 29047 net_dag_utils.cc:118] Operator graph pruning prior to chain compute took: 0.000261409 secs
I0205 04:16:54.497767 29047 net_dag.cc:61] Number of parallel execution chains 63 Number of operators = 402
I0205 04:16:54.527851 29047 net_dag_utils.cc:118] Operator graph pruning prior to chain compute took: 0.000224148 secs
I0205 04:16:54.528105 29047 net_dag.cc:61] Number of parallel execution chains 30 Number of operators = 358
I0205 04:16:54.530202 29047 net_dag_utils.cc:118] Operator graph pruning prior to chain compute took: 1.6249e-05 secs
I0205 04:16:54.530248 29047 net_dag.cc:61] Number of parallel execution chains 5 Number of operators = 18
INFO infer_simple.py: 111: Processing demo/24274813513_0cfd2ce6d0_k.jpg -> /tmp/detectron-visualizations/24274813513_0cfd2ce6d0_k.jpg.pdf
INFO infer_simple.py: 119: Inference time: 2.566s
INFO infer_simple.py: 121:  | im_detect_bbox: 2.504s
INFO infer_simple.py: 121:  | misc_mask: 0.026s
INFO infer_simple.py: 121:  | im_detect_mask: 0.033s
INFO infer_simple.py: 121:  | misc_bbox: 0.004s
INFO infer_simple.py: 124:  \ Note: inference on the first image will be slower than the rest (caches and auto-tuning need to warm up)
INFO infer_simple.py: 111: Processing demo/15673749081_767a7fa63a_k.jpg -> /tmp/detectron-visualizations/15673749081_767a7fa63a_k.jpg.pdf
INFO infer_simple.py: 119: Inference time: 0.640s
INFO infer_simple.py: 121:  | im_detect_bbox: 0.470s
INFO infer_simple.py: 121:  | misc_mask: 0.082s
INFO infer_simple.py: 121:  | im_detect_mask: 0.084s
INFO infer_simple.py: 121:  | misc_bbox: 0.004s
INFO infer_simple.py: 111: Processing demo/34501842524_3c858b3080_k.jpg -> /tmp/detectron-visualizations/34501842524_3c858b3080_k.jpg.pdf
INFO infer_simple.py: 119: Inference time: 0.518s
...