はじめに
以下のサイトを見てTensorFlow Object Detection APIをWindowsで使ってみようと思います。
TensorFlow Object Detection APIは、TensorFlowを利用して、画像に写っている物体を検出するためのフレームワークです。
インストール手順・実行方法は、Samurai Blog様のブログが素晴らしい記事を書いていますので、そちらを参考にするといいと思います。
(ただし、注意点にも記載しているTensorFlowのバージョンには注意)
https://www.sejuku.net/blog/56695
注意点
TensorFlowのバージョンはv1.12以上である必要があります。かなり新しいTensorFlowバージョンでなければ動かないため、注意が必要です。(2019年4月28日時点)
古いTensorflow Versionでは、以下のように正しく動きません。
ImportError Traceback (most recent call last) <ipython-input-1-34f5cdda911a> in <module> 18 19 if StrictVersion(tf.__version__) < StrictVersion('1.12.0'): ---> 20 raise ImportError('Please upgrade your TensorFlow installation to v1.12.*.') ImportError: Please upgrade your TensorFlow installation to v1.12.*.
本記事では
以下の記事を見ながら作業を進めていきます。
TensorFlow Object Detection APIをWindowsで使ってみた - Qiita
Protobufのコンパイルができない問題については、以下のサイトに解決策が書かれています。
python - protoc object_detection/protos/*.proto: No such file or directory - Stack Overflow
for /f %i in ('dir /b object_detection\protos\*.proto') do protoc object_detection\protos\%i --python_out=.
(tensorflow_gpu) C:\Users\uv2ut\Jupyter_Project_GPU\TensorFlow_Object_Detection_API\models-master\research>python object_detection/builders/model_builder_test.py ......C:\Users\uv2ut\Anaconda3\envs\tensorflow_gpu\lib\site-packages\numpy\lib\type_check.py:546: DeprecationWarning: np.asscalar(a) is deprecated since NumPy v1.16, use a.item() instead 'a.item() instead', DeprecationWarning, stacklevel=1) .C:\Users\uv2ut\Anaconda3\envs\tensorflow_gpu\lib\site-packages\tensorflow\python\util\tf_inspect.py:55: DeprecationWarning: inspect.getargspec() is deprecated since Python 3.0, use inspect.signature() or inspect.getfullargspec() if d.decorator_argspec is not None), _inspect.getargspec(target)) ......... ---------------------------------------------------------------------- Ran 16 tests in 0.092s OK
早速使ってみる
サンプルノートブックファイルは以下にあります。
(任意のフォルダー)\research\object_detection\object_detection_tutorial.ipynb
新たな写真を追加して判定させたい場合
上記のサンプルノートブックファイルが参照する画像ファイルは以下のフォルダーにあります。
(任意のフォルダー)\research\object_detection\test_images
私の環境下では、以下のファイルにサンプルコードの画像ファイルがありました。
C:\Users\uv2ut\obj-detect\models-master\research\object_detection\test_images
参考リンク
[侍エンジニア塾] [TensorFlow] WindowsでObject Detection APIを試そう
【物体認識】TensorflowのObject Detection APIをWindows ローカルでやるとハマる所【ラジコン自動運転】