ここでの Python, TensorFlow のバージョン:
Python 3.7.3
TensorFlow 1.14.0
仮想環境 venv で作業:
~ $ source ./venv/bin/activate
Tensorflow-YOLOv3 をダウンロード (所要時間 :1分30秒ほど):
(venv) $ git clone https://github.com/neuralassembly/Tensorflow-YOLOv3
カーレントディレクトリ (ここではユーザのホームディレクトリ) に,Tensorflow-YOLOv3 が作成されている。
カーレントディレクトリを,Tensorflow-YOLOv3 に:
(venv) $ cd Tensorflow-YOLOv3
(venv) $ ls -la
-rw-r--r-- 1 pi pi 5600 May 4 16:10 convert_weights.py
drwxr-xr-x 2 pi pi 4096 May 4 16:10 core
drwxr-xr-x 4 pi pi 4096 May 4 16:10 data
drwxr-xr-x 2 pi pi 4096 May 4 16:10 detections
-rw-r--r-- 1 pi pi 3654 May 4 16:10 detect.py
drwxr-xr-x 8 pi pi 4096 May 4 16:10 .git
-rw-r--r-- 1 pi pi 1203 May 4 16:10 .gitignore
-rw-r--r-- 1 pi pi 1068 May 4 16:10 LICENSE
-rw-r--r-- 1 pi pi 225 May 4 16:10 Makefile
-rw-r--r-- 1 pi pi 2367 May 4 16:10 README.md
-rw-r--r-- 1 pi pi 71 May 4 16:10 requirements.txt
-rw-r--r-- 1 pi pi 353 May 4 16:10 setup.py
drwxr-xr-x 2 pi pi 4096 May 4 16:10 weights
(venv) $ ls -la weights
-rw-r--r-- 1 pi pi 30 May 4 16:10 .gitignore
Tiny YOLO用のパラメーターファイル yolov3-tiny.weights をダウンロード (35MB, 所要時間40秒ほど) :
(venv) $ curl https://pjreddie.com/media/files/yolov3-tiny.weights > \
./weights/yolov3-tiny.weights
(venv) $ ls -la weights
-rw-r--r-- 1 pi pi 30 May 4 16:10 .gitignore
-rw-r--r-- 1 pi pi 35434956 May 4 16:16 yolov3-tiny.weights
ファイル変換:
(venv) $ python convert_weights.py --tiny
2021-05-04 17:01:34.426535:
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.
2021-05-04 17:02:03.350698:
W tensorflow/core/framework/cpu_allocator_impl.cc:81]
Allocation of 18874368 exceeds 10% of system memory.
2021-05-04 17:02:03.825876:
W tensorflow/core/framework/cpu_allocator_impl.cc:81]
Allocation of 18874368 exceeds 10% of system memory.
2021-05-04 17:02:04.129119:
W tensorflow/core/framework/cpu_allocator_impl.cc:81]
Allocation of 18874368 exceeds 10% of system memory.
2021-05-04 17:02:04.654812:
W tensorflow/core/framework/cpu_allocator_impl.cc:81]
Allocation of 18874368 exceeds 10% of system memory.
2021-05-04 17:02:05.846688:
W tensorflow/core/framework/cpu_allocator_impl.cc:81]
Allocation of 18874368 exceeds 10% of system memory.
Model Saved at "./weights/model-tiny.ckpt"
金丸隆志「Raspberry Pi ではじめる機械学習 補足情報」に,
「大量の WARNING が出ますが、変換は適切に行われますので気にする必要はありません」
とある。
ただし,この変換が成るようにするために,結果として,numpy と h5py のバージョンをつぎのように下げることとなった:
numpy : 1.20.2 → 1.16.2
h5py : 3.2.1 → 2.10.0
これに至った経緯
ファイル変換の結果,ディレクトリ Tensorflow-YOLOv3/weights はつぎのファイル構成となる:
(venv) pi@raspi:~/Tensorflow-YOLOv3 $ ls -la weights
total 104660
drwxr-xr-x 2 pi pi 4096 May 4 17:02 .
drwxr-xr-x 7 pi pi 4096 May 4 16:10 ..
-rw-r--r-- 1 pi pi 87 May 4 17:02 checkpoint
-rw-r--r-- 1 pi pi 30 May 4 16:10 .gitignore
-rw-r--r-- 1 pi pi 35434936 May 4 17:02 model-tiny.ckpt.data-00000-of-00001
-rw-r--r-- 1 pi pi 2254 May 4 17:02 model-tiny.ckpt.index
-rw-r--r-- 1 pi pi 36271425 May 4 17:02 model-tiny.ckpt.meta
-rw-r--r-- 1 pi pi 35434956 May 4 16:16 yolov3-tiny.weights
|