私的AI研究会 > 物体検出
$ sudo apt update
$ ls Desktop MagPi Programs Videos assistant-sdk-python env out.raw webiopi Documents Music Public Voice bluebacks googletest.sh raspberryai-mizutu-ec573de141fd.json wget Downloads Pictures Templates aispk.sh boot.sh mu_code stop.sh work $ git clone https://github.com/neuralassembly/Tensorflow-YOLOv3 Cloning into 'Tensorflow-YOLOv3'... remote: Enumerating objects: 11, done. remote: Counting objects: 100% (11/11), done. remote: Compressing objects: 100% (8/8), done. remote: Total 59 (delta 4), reused 9 (delta 3), pack-reused 48 Unpacking objects: 100% (59/59), done. Checking out files: 100% (28/28), done.
$ ls Desktop MagPi Programs Tensorflow-YOLOv3 aispk.sh boot.sh mu_code stop.sh work Documents Music Public Videos assistant-sdk-python env out.raw webiopi Downloads Pictures Templates Voice bluebacks googletest.sh raspberryai-mizutu-ec573de141fd.json wget
$ cd Tensorflow-YOLOv3 $ curl https://pjreddie.com/media/files/yolov3-tiny.weights > ./weights/yolov3-tiny.weights % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 33.7M 100 33.7M 0 0 263k 0 0:02:11 0:02:11 --:--:-- 283k $ python3 convert_weights.py --tiny 2020-09-22 10:53:26.673837: E tensorflow/core/platform/hadoop/hadoop_file_system.cc:132] HadoopFileSystem load error: libhdfs.so: cannot open shared object file: No such file or directory WARNING:tensorflow:From convert_weights.py:137: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead. WARNING:tensorflow:From /home/pi/Tensorflow-YOLOv3/core/yolo_tiny.py:76: The name tf.variable_scope is deprecated. Please use tf.compat.v1.variable_scope instead. WARNING:tensorflow:From /home/pi/Tensorflow-YOLOv3/core/layers.py:25: The name tf.layers.Conv2D is deprecated. Please use tf.compat.v1.layers.Conv2D instead. WARNING:tensorflow:From /home/pi/Tensorflow-YOLOv3/core/layers.py:34: The name tf.layers.BatchNormalization is deprecated. Please use tf.compat.v1.layers.BatchNormalization instead. WARNING:tensorflow:From /home/pi/Tensorflow-YOLOv3/core/layers.py:41: The name tf.layers.MaxPooling2D is deprecated. Please use tf.compat.v1.layers.MaxPooling2D instead. WARNING:tensorflow:From /home/pi/Tensorflow-YOLOv3/core/layers.py:97: The name tf.image.resize_nearest_neighbor is deprecated. Please use tf.compat.v1.image.resize_nearest_neighbor instead. WARNING:tensorflow:From convert_weights.py:139: The name tf.global_variables is deprecated. Please use tf.compat.v1.global_variables instead. Loading weights from "./weights/yolov3-tiny.weights" WARNING:tensorflow:From convert_weights.py:31: The name tf.assign is deprecated. Please use tf.compat.v1.assign instead. WARNING:tensorflow:From convert_weights.py:145: The name tf.train.Saver is deprecated. Please use tf.compat.v1.train.Saver instead. WARNING:tensorflow:From convert_weights.py:146: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead. Model Saved at "./weights/model-tiny.ckpt"※ 大量の WARNING が出るが変換できるので書籍に従って無視する。
$ curl https://pjreddie.com/media/files/yolov3.weights > ./weights/yolov3.weights % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 236M 100 236M 0 0 394k 0 0:10:14 0:10:14 --:--:-- 588k $ python3 convert_weights.py 2020-09-22 11:12:25.489257: E tensorflow/core/platform/hadoop/hadoop_file_system.cc:132] HadoopFileSystem load error: libhdfs.so: cannot open shared object file: No such file or directory WARNING:tensorflow:From convert_weights.py:137: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead. : WARNING:tensorflow:From convert_weights.py:146: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead. terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc 中止
$ sudo pip3 install tensorflow==1.13.1 Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple Collecting tensorflow==1.13.1 Downloading https://www.piwheels.org/simple/tensorflow/tensorflow-1.13.1-cp37-none-linux_armv7l.whl (93.2MB) 100% |████████████████████████████████| 93.2MB 4.9kB/s Requirement already satisfied: keras-preprocessing>=1.0.5 in /usr/local/lib/python3.7/dist-packages (from tensorflow==1.13.1) (1.1.2) : Successfully installed tensorboard-1.13.1 tensorflow-1.13.1
$ python3 convert_weights.py WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/tensorflow/__init__.py:98: The name tf.AUTO_REUSE is deprecated. Please use tf.compat.v1.AUTO_REUSE instead. WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/tensorflow/__init__.py:98: The name tf.AttrValue is deprecated. Please use tf.compat.v1.AttrValue instead. WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/tensorflow/__init__.py:98: The name tf.COMPILER_VERSION is deprecated. Please use tf.version.COMPILER_VERSION instead. WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/tensorflow/__init__.py:98: The name tf.CXX11_ABI_FLAG is deprecated. Please use tf.sysconfig.CXX11_ABI_FLAG instead. WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/tensorflow/__init__.py:98: The name tf.ConditionalAccumulator is deprecated. Please use tf.compat.v1.ConditionalAccumulator instead. WARNING:tensorflow:From /home/pi/Tensorflow-YOLOv3/core/layers.py:25: The name tf.layers.Conv2D is deprecated. Please use tf.compat.v1.layers.Conv2D instead. WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/tensorflow_estimator/python/estimator/api/_v1/estimator/__init__.py:10: The name tf.estimator.inputs is deprecated. Please use tf.compat.v1.estimator.inputs instead. WARNING:tensorflow:From /home/pi/Tensorflow-YOLOv3/core/layers.py:34: The name tf.layers.BatchNormalization is deprecated. Please use tf.compat.v1.layers.BatchNormalization instead. WARNING:tensorflow:From /home/pi/Tensorflow-YOLOv3/core/layers.py:97: The name tf.image.resize_nearest_neighbor is deprecated. Please use tf.compat.v1.image.resize_nearest_neighbor instead. WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/tensorflow_core/python/ops/array_ops.py:1340: add_dispatch_support.<locals>.wrapper (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version. Instructions for updating: Use tf.where in 2.0, which has the same broadcast rule as np.where Loading weights from "./weights/yolov3.weights" WARNING:tensorflow:From convert_weights.py:145: The name tf.train.Saver is deprecated. Please use tf.compat.v1.train.Saver instead. Model Saved at "./weights/model.ckpt"※ 同じく大量の WARNING が出るが変換完了する。
$ cd ~/Tensorflow-YOLOv3
$ python3 detect.py --tiny image 0.5 0.5 ./data/images/person.jpg : 途中のWARNINGエラーは無視 person 97.0% dog 92.2% dog 89.6% sheep 96.5% Image Saved at "./detections/image_output.jpg"結果は ./detections/image_output.png に保存される(ファイル名は毎回固定)→ 結果を「image_output_01.png」にリネーム
$ wget https://raw.githubusercontent.com/neuralassembly/raspi/master/desk-image.jpg --2020-09-22 11:30:42-- : 2020-09-22 11:30:43 (1.77 MB/s) - `desk-image.jpg' へ保存完了 [184309/184309]
$ python3 detect.py --tiny image 0.5 0.5 ./desk-image.jpg : 途中のWARNINGエラーは無視 cup 82.5% mouse 82.8% keyboard 88.4% Image Saved at "./detections/image_output.jpg"結果は ./detections/image_output.png → 結果を「image_output_02.png」にリネーム
$ python3 detect.py --tiny image 0.5 0.2 ./desk-image.jpg : 途中のWARNINGエラーは無視 cup 82.5% knife 22.4% mouse 82.8% keyboard 88.4% Image Saved at "./detections/image_output.jpg"結果は ./detections/image_output.png → 結果を「image_output_03.png」にリネーム
$ python3 detect.py image 0.5 0.5 ./data/images/person.jpg : 途中のWARNINGエラーは無視 person 100.0% dog 100.0% horse 99.9% Image Saved at "./detections/image_output.jpg"結果は ./detections/image_output.png → 結果を「image_output_04.png」にリネーム
$ python3 detect.py --tiny image 0.5 0.5 ./data/images/dog.jpg : car 96.8% truck 93.4% dog 79.8% Image Saved at "./detections/image_output.jpg ./detections/image_output.png → 「YOLOv3Tyny_output_dog.png」にリネーム~・eagle.jpg
$ python3 detect.py --tiny image 0.5 0.5 ./data/images/eagle.jpg : bird 69.2% Image Saved at "./detections/image_output.jpg" ./detections/image_output.png → 「YOLOv3Tyny_output_eagle.png」にリネーム~・giraffe.jpg
$ python3 detect.py --tiny image 0.5 0.5 ./data/images/giraffe.jpg : zebra 56.6% Image Saved at "./detections/image_output.jpg" ./detections/image_output.png → 「YOLOv3Tyny_output_giraffe.png」にリネーム~・horses.jpg
$ python3 detect.py --tiny image 0.5 0.5 ./data/images/horses.jpg : horse 95.2% horse 92.4% horse 79.5% horse 59.7% Image Saved at "./detections/image_output.jpg" ./detections/image_output.png → 「YOLOv3Tyny_output_horses.png」にリネーム~・kite.jpg
$ python3 detect.py --tiny image 0.5 0.5 ./data/images/kite.jpg : person 84.7% person 72.1% kite 87.1% Image Saved at "./detections/image_output.jpg" ./detections/image_output.png → 「YOLOv3Tyny_output_kite.png」にリネーム~
$ python3 detect.py --tiny video 0.5 0.5 ./data/videos/champs-elysees.mp4※ パラメータエラーとなって実行できず。(要調査)
$ cd ~/Tensorflow-YOLOv3 $ python3 detect.py --tiny webcam 0.5 0.5※ Pi4B では、1秒に複数回映像が更新され、2秒くらいの映像遅れがある。
次の段階へ向けて >>>