・2018/08/17
Raspberry Piで darkflowを動かしてリアルタイムでカメラ映像を画像物体検出する方法
(ラズパイで darkflowと Tensorflowを動かしてリアルタイムでカメラ映像の物体検出を行なってみる)
Tags: [Raspberry Pi], [電子工作], [ディープラーニング]
● Raspberry Piで darkflowを動かしてリアルタイムでカメラ映像を画像物体認識する方法
darkflowを動かすには Tensorflowと言う Machine Learning Frameworkを使用します。
● Raspberry Piで TensorFlowをコマンドラインで簡単にインストールする方法
・2018/08/14
【成功版】Raspberry Piに TensorFlow Deep Learning Frameworkをインストールする方法
ラズパイに TensorFlow Deep Learning Frameworkを入れて Google DeepDreamで悪夢を見る方法
●今回動かした Raspberry Pi Raspbian OSのバージョン
RASPBIAN STRETCH WITH DESKTOP
Version:June 2018
Release date: 2018-06-27
Kernel version: 4.14
pi@raspberrypi:~/pytorch $ uname -a
Linux raspberrypi 4.14.50-v7+ #1122 SMP Tue Jun 19 12:26:26 BST 2018 armv7l GNU/Linux
● Raspberry Piで darkflowを Gitからインストールする方法
thtrieu/darkflow
Translate darknet to tensorflow. Load trained weights, retrain/fine-tune using tensorflow, export constant graph def to mobile devices
Dependencies(darkflowに必要なもの)
Python3
tensorflow 1.0
numpy
opencv 3
●まずは TensorFlow
#
sudo apt-get update
# Raspberry Pi3 = linux_armv7l
# cp35 = Python 3.5
# Tensorflow - 1.10.0 @lhelontra lhelontra released this Aug 13, 2018
wget https://github.com/lhelontra/tensorflow-on-arm/releases/download/v1.10.0/tensorflow-1.10.0-cp35-none-linux_armv7l.whl
# install tensorflow-1.10.0-cp35-none-linux_armv7l.whl
sudo pip3 install tensorflow-1.10.0-cp35-none-linux_armv7l.whl
●そして darkflow
ImportError: No module named 'cv2'
sudo pip3 install opencv-python
# Successfully installed opencv-python-3.4.2.17
cd
git clone https://github.com/thtrieu/darkflow.git --depth 1
cd darkflow
python3 setup.py build_ext --inplace
pi@raspberrypi:~/darkflow $ python3 setup.py build_ext --inplace
Traceback (most recent call last):
File "setup.py", line 3, in <module>
from Cython.Build import cythonize
ImportError: No module named 'Cython'
# ---
Python 3が動作対象なので下記の pipは間違い(pipは Python 2用)
pip install .
pi@raspberrypi:~/darkflow $ pip install .
Processing /home/pi/darkflow
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-fjj9Rp-build/setup.py", line 3, in <module>
from Cython.Build import cythonize
ImportError: No module named Cython.Build
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-fjj9Rp-build/
# ---
pip3 install .
pi@raspberrypi:~/darkflow $ pip3 install .
Processing /home/pi/darkflow
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-wdiw8fdf-build/setup.py", line 3, in <module>
from Cython.Build import cythonize
ImportError: No module named 'Cython'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-wdiw8fdf-build/
# ImportError: No module named 'Cython'
pip3 install Cython
# Successfully installed Cython-0.28.5
pip3 install .
Original error was: libf77blas.so.3: cannot open shared object file: No such file or directory
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-yscpn0tr-build/
# Original error was: libf77blas.so.3: cannot open shared object file: No such file or directory
sudo apt-get -y install libatlas-base-dev
# Setting up libatlas-dev (3.10.3-1+rpi1) ...
# Setting up libatlas-base-dev (3.10.3-1+rpi1) ...
pip3 install .
pi@raspberrypi:~/darkflow $ pip3 install .
Processing /home/pi/darkflow
Installing collected packages: darkflow
Running setup.py install for darkflow ... done
Successfully installed darkflow-1.0.0
pi@raspberrypi:~/darkflow $ flow
-bash: flow: command not found
pi@raspberrypi:~/darkflow $ ./flow
Traceback (most recent call last):
File "./flow", line 4, in <module>
from darkflow.cli import cliHandler
File "/home/pi/darkflow/darkflow/cli.py", line 3, in <module>
from .net.build import TFNet
File "/home/pi/darkflow/darkflow/net/build.py", line 1, in <module>
import tensorflow as tf
ImportError: No module named tensorflow
pi@raspberrypi:~/darkflow $ cat ./flow
#! /usr/bin/env python
import sys
from darkflow.cli import cliHandler
cliHandler(sys.argv)
#! /usr/bin/env python
を
#! /usr/bin/env python3
に書き換える
pi@raspberrypi:~/darkflow $ cat ./flow
#! /usr/bin/env python3
import sys
from darkflow.cli import cliHandler
cliHandler(sys.argv)
pi@raspberrypi:~/darkflow $ ./flow
Traceback (most recent call last):
File "./flow", line 4, in <module>
from darkflow.cli import cliHandler
File "/home/pi/darkflow/darkflow/cli.py", line 3, in <module>
from .net.build import TFNet
File "/home/pi/darkflow/darkflow/net/build.py", line 3, in <module>
from . import help
File "/home/pi/darkflow/darkflow/net/help.py", line 9, in <module>
import cv2
File "/usr/local/lib/python3.5/dist-packages/cv2/__init__.py", line 3, in <module>
from .cv2 import *
ImportError: libjasper.so.1: cannot open shared object file: No such file or directory
# ImportError: libjasper.so.1: cannot open shared object file: No such file or directory
sudo apt-get -y install libjasper-dev
# Setting up libjasper1:armhf (1.900.1-debian1-2.4+deb8u1) ...
# Setting up libjasper-dev (1.900.1-debian1-2.4+deb8u1) ...
pi@raspberrypi:~/darkflow $ ./flow --h
Traceback (most recent call last):
File "./flow", line 4, in <module>
from darkflow.cli import cliHandler
File "/home/pi/darkflow/darkflow/cli.py", line 3, in <module>
from .net.build import TFNet
File "/home/pi/darkflow/darkflow/net/build.py", line 3, in <module>
from . import help
File "/home/pi/darkflow/darkflow/net/help.py", line 9, in <module>
import cv2
File "/usr/local/lib/python3.5/dist-packages/cv2/__init__.py", line 3, in <module>
from .cv2 import *
ImportError: libQtGui.so.4: cannot open shared object file: No such file or directory
# ImportError: libQtGui.so.4: cannot open shared object file: No such file or directory
sudo apt-get install libqtgui4
# Setting up libqtgui4:armhf (4:4.8.7+dfsg-11+rpi1) ...
pi@raspberrypi:~/darkflow $ ./flow --h
Traceback (most recent call last):
File "./flow", line 4, in <module>
from darkflow.cli import cliHandler
File "/home/pi/darkflow/darkflow/cli.py", line 3, in <module>
from .net.build import TFNet
File "/home/pi/darkflow/darkflow/net/build.py", line 3, in <module>
from . import help
File "/home/pi/darkflow/darkflow/net/help.py", line 9, in <module>
import cv2
File "/usr/local/lib/python3.5/dist-packages/cv2/__init__.py", line 3, in <module>
from .cv2 import *
ImportError: libQtTest.so.4: cannot open shared object file: No such file or directory
# ImportError: libQtTest.so.4: cannot open shared object file: No such file or directory
# pip3 install opencv-python
sudo apt-get -y install libqt4-test
# Setting up libqt4-test:armhf (4:4.8.7+dfsg-11+rpi1) ...
pi@raspberrypi:~/darkflow $ ./flow --h
Traceback (most recent call last):
File "./flow", line 4, in <module>
from darkflow.cli import cliHandler
File "/home/pi/darkflow/darkflow/cli.py", line 3, in <module>
from .net.build import TFNet
File "/home/pi/darkflow/darkflow/net/build.py", line 7, in <module>
from .framework import create_framework
File "/home/pi/darkflow/darkflow/net/framework.py", line 1, in <module>
from . import yolo
File "/home/pi/darkflow/darkflow/net/yolo/__init__.py", line 2, in <module>
from . import predict
File "/home/pi/darkflow/darkflow/net/yolo/predict.py", line 7, in <module>
from ...cython_utils.cy_yolo_findboxes import yolo_box_constructor
ImportError: No module named 'darkflow.cython_utils.cy_yolo_findboxes'
No module named cy_yolo_findboxes #168
https://github.com/thtrieu/darkflow/issues/168#issuecomment-302499117
I had this problem using the pip / pip3 install method. using Setup.py worked.
# ImportError: No module named 'darkflow.cython_utils.cy_yolo_findboxes'
# 下記のコマンドで darkflowをビルドする必要がある
# pip install .だと No module named 'darkflow.cython_utils.cy_yolo_findboxes'が発生する
python3 setup.py build_ext --inplace
pi@raspberrypi:~/darkflow $ ./flow
Parsing
Traceback (most recent call last):
File "./flow", line 6, in <module>
cliHandler(sys.argv)
File "/home/pi/darkflow/darkflow/cli.py", line 26, in cliHandler
tfnet = TFNet(FLAGS)
File "/home/pi/darkflow/darkflow/net/build.py", line 58, in __init__
darknet = Darknet(FLAGS)
File "/home/pi/darkflow/darkflow/dark/darknet.py", line 17, in __init__
src_parsed = self.parse_cfg(self.src_cfg, FLAGS)
File "/home/pi/darkflow/darkflow/dark/darknet.py", line 68, in parse_cfg
for i, info in enumerate(cfg_layers):
File "/home/pi/darkflow/darkflow/utils/process.py", line 66, in cfg_yielder
layers, meta = parser(model); yield meta;
File "/home/pi/darkflow/darkflow/utils/process.py", line 17, in parser
with open(model, 'rb') as f:
FileNotFoundError: [Errno 2] No such file or directory: ''
pi@raspberrypi:~/darkflow $ ./flow --help
Example usage: flow --imgdir sample_img/ --model cfg/yolo.cfg --load bin/yolo.weights
Arguments:
--config path to .cfg directory
--labels path to labels file
--annotation path to annotation directory
--momentum applicable for rmsprop and momentum optimizers
--lr learning rate
--gpuName GPU device name
--pbLoad path to .pb protobuf file (metaLoad must also be specified)
--saveVideo Records video from input video or camera
--imgdir path to testing directory with images
--demo demo on webcam
--json Outputs bounding box information in json format.
--load how to initialize the net? Either from .weights or a checkpoint, or even from scratch
--save save checkpoint every ? training examples
--gpu how much gpu (from 0.0 to 1.0)
--backup path to backup folder
--summary path to TensorBoard summaries directory
--batch batch size
--epoch number of epoch
--queue process demo in batch
--trainer training algorithm
--model configuration of choice
--threshold detection threshold
--keep Number of most recent training results to save
--verbalise say out loud while building graph
--dataset path to dataset directory
--metaLoad path to .meta file generated during --savepb that corresponds to .pb file
--train train the whole net
--binary path to .weights directory
--help, --h, -h show this super helpful message and exit
--savepb save net and weight to a .pb file
ImportError: No module named 'cv2'
sudo pip3 install opencv-python
# Successfully installed opencv-python-3.4.2.17
その後も dalkflowの罠が続々と、、、
pi@raspberrypi:~/darkflow $ ./flow --model cfg/yolo-new.cfg --load bin/yolo-new.weights --demo videofile.avi
Traceback (most recent call last):
File "./flow", line 6, in <module>
cliHandler(sys.argv)
File "/home/pi/darkflow/darkflow/cli.py", line 26, in cliHandler
tfnet = TFNet(FLAGS)
File "/home/pi/darkflow/darkflow/net/build.py", line 58, in __init__
darknet = Darknet(FLAGS)
File "/home/pi/darkflow/darkflow/dark/darknet.py", line 13, in __init__
self.get_weight_src(FLAGS)
File "/home/pi/darkflow/darkflow/dark/darknet.py", line 47, in get_weight_src
'{} not found'.format(FLAGS.load)
AssertionError: bin/yolo-new.weights not found
wget https://pjreddie.com/media/files/yolov2-tiny.weights
mv yolov2-tiny.weights ./bin/
wget https://github.com/pjreddie/darknet/raw/master/cfg/yolov2-tiny.cfg
mv yolov2-tiny.cfg ./cfg/
./flow --model cfg/yolov2-tiny.cfg --load bin/yolov2-tiny.weights --demo videofile.avi
./flow --model cfg/yolov2-tiny.cfg --load bin/yolov2-tiny.weights --demo camera
pi@raspberrypi:~/darkflow $ ./flow --model cfg/yolov2-tiny.cfg --load bin/yolov2-tiny.weights --demo videofile.avi
Parsing ./cfg/yolov2-tiny.cfg
Parsing cfg/yolov2-tiny.cfg
Loading bin/yolov2-tiny.weights ...
Traceback (most recent call last):
File "./flow", line 6, in <module>
cliHandler(sys.argv)
File "/home/pi/darkflow/darkflow/cli.py", line 26, in cliHandler
tfnet = TFNet(FLAGS)
File "/home/pi/darkflow/darkflow/net/build.py", line 58, in __init__
darknet = Darknet(FLAGS)
File "/home/pi/darkflow/darkflow/dark/darknet.py", line 27, in __init__
self.load_weights()
File "/home/pi/darkflow/darkflow/dark/darknet.py", line 82, in load_weights
wgts_loader = loader.create_loader(*args)
File "/home/pi/darkflow/darkflow/utils/loader.py", line 105, in create_loader
return load_type(path, cfg)
File "/home/pi/darkflow/darkflow/utils/loader.py", line 19, in __init__
self.load(*args)
File "/home/pi/darkflow/darkflow/utils/loader.py", line 77, in load
walker.offset, walker.size)
AssertionError: expect 44948596 bytes, found 44948600
https://github.com/thtrieu/darkflow/issues/802
AssertionError: expect 44948596 bytes, found 44948600 #802
https://sites.google.com/view/tensorflow-example-java-api/complete-guide-to-train-yolo/convert-darknet-weights-to-pb-file
Create frozen graph from DarkNet weights
The solution is very simple, let's modify the line self.offset = 16 in the ./darkflow/utils/loader.py file and replace with self.offset = 20.
nano ./darkflow/utils/loader.py
else:
self.size = os.path.getsize(path)# save the path
major, minor, revision, seen = np.memmap(path,
shape = (), mode = 'r', offset = 0,
dtype = '({})i4,'.format(4))
self.transpose = major > 1000 or minor > 1000
self.offset = 16
self.offset = 20
pi@raspberrypi:~/darkflow $ ./flow --model cfg/yolov2-tiny.cfg --load bin/yolov2-tiny.weights --demo camera
Parsing ./cfg/yolov2-tiny.cfg
Parsing cfg/yolov2-tiny.cfg
Loading bin/yolov2-tiny.weights ...
Successfully identified 44948600 bytes
Finished in 0.036969900131225586s
Traceback (most recent call last):
File "./flow", line 6, in <module>
cliHandler(sys.argv)
File "/home/pi/darkflow/darkflow/cli.py", line 26, in cliHandler
tfnet = TFNet(FLAGS)
File "/home/pi/darkflow/darkflow/net/build.py", line 64, in __init__
self.framework = create_framework(*args)
File "/home/pi/darkflow/darkflow/net/framework.py", line 59, in create_framework
return this(meta, FLAGS)
File "/home/pi/darkflow/darkflow/net/framework.py", line 15, in __init__
self.constructor(meta, FLAGS)
File "/home/pi/darkflow/darkflow/net/yolo/__init__.py", line 24, in constructor
).format(meta['model'])
AssertionError: labels.txt and cfg/yolov2-tiny.cfg indicate inconsistent class numbers
./flow --model cfg/tiny-yolo.cfg --load bin/tiny-yolo-voc.weights --demo camera
pi@raspberrypi:~/darkflow $ ./flow --model cfg/tiny-yolo.cfg --load bin/tiny-yolo-voc.weights --demo camera
Parsing ./cfg/tiny-yolo-voc.cfg
Parsing cfg/tiny-yolo.cfg
Loading bin/tiny-yolo-voc.weights ...
Traceback (most recent call last):
File "./flow", line 6, in <module>
cliHandler(sys.argv)
File "/home/pi/darkflow/darkflow/cli.py", line 26, in cliHandler
tfnet = TFNet(FLAGS)
File "/home/pi/darkflow/darkflow/net/build.py", line 58, in __init__
darknet = Darknet(FLAGS)
File "/home/pi/darkflow/darkflow/dark/darknet.py", line 27, in __init__
self.load_weights()
File "/home/pi/darkflow/darkflow/dark/darknet.py", line 82, in load_weights
wgts_loader = loader.create_loader(*args)
File "/home/pi/darkflow/darkflow/utils/loader.py", line 105, in create_loader
return load_type(path, cfg)
File "/home/pi/darkflow/darkflow/utils/loader.py", line 19, in __init__
self.load(*args)
File "/home/pi/darkflow/darkflow/utils/loader.py", line 70, in load
val = walker.walk(new.wsize[par])
File "/home/pi/darkflow/darkflow/utils/loader.py", line 127, in walk
'Over-read {}'.format(self.path)
AssertionError: Over-read bin/tiny-yolo-voc.weights
ls -l ./sample_img/
wget http://pjreddie.com/media/files/yolo.weights
mv yolo.weights ./bin/
python3
from darkflow.net.build import TFNet
import cv2
options = {"model": "cfg/yolo.cfg", "load": "bin/yolo.weights", "threshold": 0.1}
tfnet = TFNet(options)
imgcv = cv2.imread("./sample_img/sample_dog.jpg")
result = tfnet.return_predict(imgcv)
print(result)
pi@raspberrypi:~/darkflow $ python3
Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170124] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from darkflow.net.build import TFNet
>>> import cv2
>>>
>>> options = {"model": "cfg/yolo.cfg", "load": "bin/yolo.weights", "threshold": 0.1}
>>> tfnet = TFNet(options)
Parsing ./cfg/yolo.cfg
Parsing cfg/yolo.cfg
Loading bin/yolo.weights ...
Successfully identified 203934260 bytes
Finished in 0.07395124435424805s
Model has a coco model name, loading coco labels.
Building net ...
Source | Train? | Layer description | Output size
-------+--------+----------------------------------+---------------
| | input | (?, 608, 608, 3)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 608, 608, 32)
Load | Yep! | maxp 2x2p0_2 | (?, 304, 304, 32)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 304, 304, 64)
Load | Yep! | maxp 2x2p0_2 | (?, 152, 152, 64)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 152, 152, 128)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 152, 152, 64)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 152, 152, 128)
Load | Yep! | maxp 2x2p0_2 | (?, 76, 76, 128)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 76, 76, 256)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 76, 76, 128)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 76, 76, 256)
Load | Yep! | maxp 2x2p0_2 | (?, 38, 38, 256)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 38, 38, 512)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 38, 38, 256)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 38, 38, 512)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 38, 38, 256)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 38, 38, 512)
Load | Yep! | maxp 2x2p0_2 | (?, 19, 19, 512)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 19, 19, 1024)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 19, 19, 512)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 19, 19, 1024)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 19, 19, 512)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 19, 19, 1024)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 19, 19, 1024)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 19, 19, 1024)
Load | Yep! | concat [16] | (?, 38, 38, 512)
Load | Yep! | conv 1x1p0_1 +bnorm leaky | (?, 38, 38, 64)
Load | Yep! | local flatten 2x2 | (?, 19, 19, 256)
Load | Yep! | concat [27, 24] | (?, 19, 19, 1280)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 19, 19, 1024)
Load | Yep! | conv 1x1p0_1 linear | (?, 19, 19, 425)
-------+--------+----------------------------------+---------------
Running entirely on CPU
2018-08-17 09:24:23.160812: W tensorflow/core/framework/allocator.cc:108] Allocation of 4718592 exceeds 10% of system memory.
2018-08-17 09:24:23.181200: W tensorflow/core/framework/allocator.cc:108] Allocation of 4718592 exceeds 10% of system memory.
2018-08-17 09:24:23.197534: W tensorflow/core/framework/allocator.cc:108] Allocation of 4718592 exceeds 10% of system memory.
2018-08-17 09:24:23.213209: W tensorflow/core/framework/allocator.cc:108] Allocation of 18874368 exceeds 10% of system memory.
2018-08-17 09:24:23.276548: W tensorflow/core/framework/allocator.cc:108] Allocation of 18874368 exceeds 10% of system memory.
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
Aborted
https://github.com/digitalbrain79/pyyolo/blob/master/tiny-yolo.weights
wget https://github.com/digitalbrain79/pyyolo/raw/master/tiny-yolo.weights
mv tiny-yolo.weights ./bin/
flow --imgdir sample_img/ --model cfg/tiny-yolo.cfg --load bin/tiny-yolo.weights --json
python3
from darkflow.net.build import TFNet
import cv2
options = {"model": "cfg/tiny-yolo.cfg", "load": "bin/tiny-yolo.weights", "threshold": 0.1}
tfnet = TFNet(options)
imgcv = cv2.imread("./sample_img/sample_computer.jpg")
result = tfnet.return_predict(imgcv)
print(result)
quit()
pi@raspberrypi:~/darkflow $ python3
Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170124] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from darkflow.net.build import TFNet
>>> import cv2
>>>
>>> options = {"model": "cfg/tiny-yolo.cfg", "load": "bin/tiny-yolo.weights", "threshold": 0.1}
>>> tfnet = TFNet(options)
Parsing ./cfg/tiny-yolo.cfg
Parsing cfg/tiny-yolo.cfg
Loading bin/tiny-yolo.weights ...
Successfully identified 64701556 bytes
Finished in 0.03892922401428223s
Model has a coco model name, loading coco labels.
Building net ...
Source | Train? | Layer description | Output size
-------+--------+----------------------------------+---------------
| | input | (?, 416, 416, 3)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 416, 416, 16)
Load | Yep! | maxp 2x2p0_2 | (?, 208, 208, 16)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 208, 208, 32)
Load | Yep! | maxp 2x2p0_2 | (?, 104, 104, 32)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 104, 104, 64)
Load | Yep! | maxp 2x2p0_2 | (?, 52, 52, 64)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 52, 52, 128)
Load | Yep! | maxp 2x2p0_2 | (?, 26, 26, 128)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 26, 26, 256)
Load | Yep! | maxp 2x2p0_2 | (?, 13, 13, 256)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 13, 13, 512)
Load | Yep! | maxp 2x2p0_1 | (?, 13, 13, 512)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 13, 13, 1024)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 13, 13, 1024)
Load | Yep! | conv 1x1p0_1 linear | (?, 13, 13, 425)
-------+--------+----------------------------------+---------------
Running entirely on CPU
Finished in 20.76127004623413s
>>> imgcv = cv2.imread("./sample_img/sample_computer.jpg")
>>> result = tfnet.return_predict(imgcv)
>>> print(result)
[{'label': 'tvmonitor', 'confidence': 0.6699612, 'bottomright': {'x': 322, 'y': 282}, 'topleft': {'x': 169, 'y': 86}}, {'label': 'laptop', 'confidence': 0.11524013, 'bottomright': {'x': 440, 'y': 374}, 'topleft': {'x': 64, 'y': 80}}, {'label': 'keyboard', 'confidence': 0.37613666, 'bottomright': {'x': 392, 'y': 363}, 'topleft': {'x': 113, 'y': 247}}, {'label': 'keyboard', 'confidence': 0.11879382, 'bottomright': {'x': 363, 'y': 368}, 'topleft': {'x': 206, 'y': 291}}]
# ---
-rw-r--r-- 1 pi pi 64668 Aug 17 07:58 sample_computer.jpg
-rw-r--r-- 1 pi pi 163759 Aug 17 07:58 sample_dog.jpg
-rw-r--r-- 1 pi pi 141886 Aug 17 07:58 sample_eagle.jpg
-rw-r--r-- 1 pi pi 382965 Aug 17 07:58 sample_giraffe.jpg
-rw-r--r-- 1 pi pi 133495 Aug 17 07:58 sample_horses.jpg
-rw-r--r-- 1 pi pi 609407 Aug 17 07:58 sample_office.jpg
-rw-r--r-- 1 pi pi 113880 Aug 17 07:58 sample_person.jpg
-rw-r--r-- 1 pi pi 174515 Aug 17 07:58 sample_scream.jpg
# ---
imgcv = cv2.imread("./sample_img/sample_dog.jpg")
result = tfnet.return_predict(imgcv)
print(result)
>>> imgcv = cv2.imread("./sample_img/sample_dog.jpg")
>>> result = tfnet.return_predict(imgcv)
>>> print(result)
[{'label': 'person', 'confidence': 0.17641757, 'bottomright': {'x': 100, 'y': 117}, 'topleft': {'x': 66, 'y': 82}}, {'label': 'person', 'confidence': 0.11094771, 'bottomright': {'x': 755, 'y': 489}, 'topleft': {'x': 699, 'y': 7}}, {'label': 'bicycle', 'confidence': 0.5901893, 'bottomright': {'x': 598, 'y': 436}, 'topleft': {'x': 166, 'y': 211}}, {'label': 'car', 'confidence': 0.3197595, 'bottomright': {'x': 593, 'y': 161}, 'topleft': {'x': 433, 'y': 82}}, {'label': 'car', 'confidence': 0.22414212, 'bottomright': {'x': 724, 'y': 184}, 'topleft': {'x': 477, 'y': 94}}, {'label': 'truck', 'confidence': 0.2963257, 'bottomright': {'x': 673, 'y': 171}, 'topleft': {'x': 441, 'y': 78}}, {'label': 'dog', 'confidence': 0.83238864, 'bottomright': {'x': 338, 'y': 535}, 'topleft': {'x': 103, 'y': 222}}]
# ---
imgcv = cv2.imread("./sample_img/sample_eagle.jpg")
result = tfnet.return_predict(imgcv)
print(result)
>>> imgcv = cv2.imread("./sample_img/sample_eagle.jpg")
>>> result = tfnet.return_predict(imgcv)
>>> print(result)
[{'label': 'bird', 'confidence': 0.6817078, 'bottomright': {'x': 566, 'y': 461}, 'topleft': {'x': 212, 'y': 114}}]
# ---
imgcv = cv2.imread("./sample_img/sample_giraffe.jpg")
result = tfnet.return_predict(imgcv)
print(result)
>>> imgcv = cv2.imread("./sample_img/sample_giraffe.jpg")
>>> result = tfnet.return_predict(imgcv)
>>> print(result)
[{'label': 'zebra', 'confidence': 0.50122005, 'bottomright': {'x': 423, 'y': 459}, 'topleft': {'x': 290, 'y': 254}}, {'label': 'giraffe', 'confidence': 0.8112186, 'bottomright': {'x': 426, 'y': 399}, 'topleft': {'x': 154, 'y': 0}}]
# ---
imgcv = cv2.imread("./sample_img/sample_horses.jpg")
result = tfnet.return_predict(imgcv)
print(result)
>>> imgcv = cv2.imread("./sample_img/sample_horses.jpg")
>>> result = tfnet.return_predict(imgcv)
>>> print(result)
[{'label': 'horse', 'confidence': 0.22169317, 'bottomright': {'x': 163, 'y': 263}, 'topleft': {'x': 17, 'y': 166}}, {'label': 'cow', 'confidence': 0.21200436, 'bottomright': {'x': 591, 'y': 341}, 'topleft': {'x': 421, 'y': 201}}, {'label': 'horse', 'confidence': 0.74727803, 'bottomright': {'x': 292, 'y': 401}, 'topleft': {'x': 9, 'y': 187}}, {'label': 'horse', 'confidence': 0.6991626, 'bottomright': {'x': 595, 'y': 358}, 'topleft': {'x': 418, 'y': 206}}, {'label': 'cow', 'confidence': 0.40255636, 'bottomright': {'x': 435, 'y': 353}, 'topleft': {'x': 203, 'y': 181}}]
# ---
imgcv = cv2.imread("./sample_img/sample_office.jpg")
result = tfnet.return_predict(imgcv)
print(result)
>>> imgcv = cv2.imread("./sample_img/sample_office.jpg")
>>> result = tfnet.return_predict(imgcv)
>>> print(result)
[{'label': 'person', 'confidence': 0.2746053, 'bottomright': {'x': 813, 'y': 1586}, 'topleft': {'x': 416, 'y': 902}}, {'label': 'person', 'confidence': 0.30696627, 'bottomright': {'x': 963, 'y': 1579}, 'topleft': {'x': 619, 'y': 946}}, {'label': 'person', 'confidence': 0.4201445, 'bottomright': {'x': 3399, 'y': 1841}, 'topleft': {'x': 3079, 'y': 879}}, {'label': 'person', 'confidence': 0.5078407, 'bottomright': {'x': 3673, 'y': 1869}, 'topleft': {'x': 3342, 'y': 815}}, {'label': 'person', 'confidence': 0.110246345, 'bottomright': {'x': 4077, 'y': 1667}, 'topleft': {'x': 3648, 'y': 905}}, {'label': 'person', 'confidence': 0.44077504, 'bottomright': {'x': 3039, 'y': 1846}, 'topleft': {'x': 2742, 'y': 1029}}, {'label': 'bowl', 'confidence': 0.12725255, 'bottomright': {'x': 738, 'y': 1757}, 'topleft': {'x': 374, 'y': 1543}}, {'label': 'chair', 'confidence': 0.16184662, 'bottomright': {'x': 1542, 'y': 1673}, 'topleft': {'x': 895, 'y': 1272}}, {'label': 'chair', 'confidence': 0.117204905, 'bottomright': {'x': 2032, 'y': 1579}, 'topleft': {'x': 1774, 'y': 1374}}, {'label': 'chair', 'confidence': 0.1403688, 'bottomright': {'x': 954, 'y': 1742}, 'topleft': {'x': 796, 'y': 1561}}, {'label': 'chair', 'confidence': 0.107318684, 'bottomright': {'x': 2066, 'y': 1716}, 'topleft': {'x': 1706, 'y': 1572}}, {'label': 'chair', 'confidence': 0.30983013, 'bottomright': {'x': 2471, 'y': 1951}, 'topleft': {'x': 2034, 'y': 1417}}, {'label': 'chair', 'confidence': 0.15158811, 'bottomright': {'x': 2659, 'y': 1788}, 'topleft': {'x': 2398, 'y': 1492}}, {'label': 'chair', 'confidence': 0.22778173, 'bottomright': {'x': 2612, 'y': 1930}, 'topleft': {'x': 2300, 'y': 1394}}, {'label': 'chair', 'confidence': 0.23035064, 'bottomright': {'x': 828, 'y': 2381}, 'topleft': {'x': 313, 'y': 1742}}, {'label': 'chair', 'confidence': 0.16745067, 'bottomright': {'x': 1077, 'y': 2402}, 'topleft': {'x': 635, 'y': 1755}}, {'label': 'chair', 'confidence': 0.4338943, 'bottomright': {'x': 1556, 'y': 2388}, 'topleft': {'x': 888, 'y': 1754}}, {'label': 'chair', 'confidence': 0.41220787, 'bottomright': {'x': 1888, 'y': 2415}, 'topleft': {'x': 1208, 'y': 1725}}, {'label': 'chair', 'confidence': 0.25196952, 'bottomright': {'x': 2152, 'y': 2374}, 'topleft': {'x': 1586, 'y': 1676}}, {'label': 'diningtable', 'confidence': 0.104920916, 'bottomright': {'x': 1993, 'y': 1886}, 'topleft': {'x': 1011, 'y': 1486}}]
# ---
imgcv = cv2.imread("./sample_img/sample_person.jpg")
result = tfnet.return_predict(imgcv)
print(result)
>>> imgcv = cv2.imread("./sample_img/sample_person.jpg")
>>> result = tfnet.return_predict(imgcv)
>>> print(result)
[{'label': 'person', 'confidence': 0.7048151, 'bottomright': {'x': 274, 'y': 382}, 'topleft': {'x': 184, 'y': 101}}, {'label': 'dog', 'confidence': 0.8366541, 'bottomright': {'x': 193, 'y': 353}, 'topleft': {'x': 71, 'y': 263}}, {'label': 'dog', 'confidence': 0.13467567, 'bottomright': {'x': 194, 'y': 340}, 'topleft': {'x': 150, 'y': 284}}, {'label': 'horse', 'confidence': 0.6584867, 'bottomright': {'x': 592, 'y': 337}, 'topleft': {'x': 412, 'y': 109}}, {'label': 'sheep', 'confidence': 0.70237964, 'bottomright': {'x': 583, 'y': 347}, 'topleft': {'x': 387, 'y': 136}}]
# ---
imgcv = cv2.imread("./sample_img/sample_scream.jpg")
result = tfnet.return_predict(imgcv)
print(result)
>>> imgcv = cv2.imread("./sample_img/sample_scream.jpg")
>>> result = tfnet.return_predict(imgcv)
>>> print(result)
[{'label': 'clock', 'confidence': 0.18412226, 'bottomright': {'x': 211, 'y': 303}, 'topleft': {'x': 159, 'y': 214}}]
pi@raspberrypi:~/darkflow $ ./flow --model cfg/tiny-yolo.cfg --load bin/tiny-yolo-voc.weights --demo camera
Parsing ./cfg/tiny-yolo-voc.cfg
Parsing cfg/tiny-yolo.cfg
Loading bin/tiny-yolo-voc.weights ...
Successfully identified 63471556 bytes
Finished in 0.04451560974121094s
Model has a coco model name, loading coco labels.
Building net ...
Source | Train? | Layer description | Output size
-------+--------+----------------------------------+---------------
| | input | (?, 416, 416, 3)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 416, 416, 16)
Load | Yep! | maxp 2x2p0_2 | (?, 208, 208, 16)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 208, 208, 32)
Load | Yep! | maxp 2x2p0_2 | (?, 104, 104, 32)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 104, 104, 64)
Load | Yep! | maxp 2x2p0_2 | (?, 52, 52, 64)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 52, 52, 128)
Load | Yep! | maxp 2x2p0_2 | (?, 26, 26, 128)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 26, 26, 256)
Load | Yep! | maxp 2x2p0_2 | (?, 13, 13, 256)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 13, 13, 512)
Load | Yep! | maxp 2x2p0_1 | (?, 13, 13, 512)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 13, 13, 1024)
Load | Yep! | conv 3x3p1_1 +bnorm leaky | (?, 13, 13, 1024)
Init | Yep! | conv 1x1p0_1 linear | (?, 13, 13, 425)
-------+--------+----------------------------------+---------------
Running entirely on CPU
Finished in 21.176759243011475s
VIDEOIO ERROR: V4L: can't open camera by index 0
Press [ESC] to quit demo
Traceback (most recent call last):
File "./flow", line 6, in <module>
cliHandler(sys.argv)
File "/home/pi/darkflow/darkflow/cli.py", line 29, in cliHandler
tfnet.camera()
File "/home/pi/darkflow/darkflow/net/help.py", line 84, in camera
'Cannot capture source'
AssertionError: Cannot capture source
Running entirely on CPU
Finished in 20.816428184509277s
Press [ESC] to quit demo
: cannot connect to X server
sudo systemctl start lightdm
sudo systemctl stop lightdm
./flow --model cfg/tiny-yolo.cfg --load bin/tiny-yolo.weights --demo camera
食事時は混み合う歩道(ニューデリー)
wget https://www.pakutaso.com/shared/img/thumb/miyazaki049INDDSCF4975_TP_V4.jpg
ls -l miyazaki049INDDSCF4975_TP_V4.jpg
python3
from darkflow.net.build import TFNet
import cv2
options = {"model": "cfg/tiny-yolo.cfg", "load": "bin/tiny-yolo.weights", "threshold": 0.1}
tfnet = TFNet(options)
imgcv = cv2.imread("./miyazaki049INDDSCF4975_TP_V4.jpg")
result = tfnet.return_predict(imgcv)
print(result)
quit()
>>> imgcv = cv2.imread("./miyazaki049INDDSCF4975_TP_V4.jpg")
>>> result = tfnet.return_predict(imgcv)
>>> print(result)
[{'bottomright': {'x': 244, 'y': 335}, 'topleft': {'x': 165, 'y': 214}, 'confidence': 0.42663893, 'label': 'person'}, {'bottomright': {'x': 566, 'y': 516}, 'topleft': {'x': 471, 'y': 194}, 'confidence': 0.47630596, 'label': 'person'}, {'bottomright': {'x': 593, 'y': 440}, 'topleft': {'x': 543, 'y': 253}, 'confidence': 0.23304082, 'label': 'person'}, {'bottomright': {'x': 475, 'y': 532}, 'topleft': {'x': 356, 'y': 210}, 'confidence': 0.6419304, 'label': 'person'}, {'bottomright': {'x': 796, 'y': 532}, 'topleft': {'x': 745, 'y': 245}, 'confidence': 0.15032068, 'label': 'person'}, {'bottomright': {'x': 460, 'y': 526}, 'topleft': {'x': 385, 'y': 390}, 'confidence': 0.1102702, 'label': 'dog'}]
YOLO v2
# Tiny YOLO VOC 2007+2012
wget https://pjreddie.com/media/files/yolov2-tiny-voc.weights
mv yolov2-tiny-voc.weights ./bin/
wget https://raw.githubusercontent.com/pjreddie/darknet/master/cfg/yolov2-tiny-voc.cfg
tail yolov2-tiny-voc.cfg
mv yolov2-tiny-voc.cfg ./cfg/
#
python3
#
from darkflow.net.build import TFNet
import cv2
options = {"model": "cfg/yolov2-tiny-voc.cfg", "load": "bin/yolov2-tiny-voc.weights", "threshold": 0.1}
tfnet = TFNet(options)
imgcv = cv2.imread("./miyazaki049INDDSCF4975_TP_V4.jpg")
result = tfnet.return_predict(imgcv)
print(result)
quit()
AssertionError: labels.txt and cfg/yolov2-tiny-voc.cfg indicate inconsistent class numbers
https://github.com/thtrieu/darkflow/issues/295
https://github.com/pjreddie/darknet/issues/850
pi@raspberrypi:~/darkflow $ ffmpeg
-bash: ffmpeg: command not found
pi@raspberrypi:~/darkflow $ sudo apt-get install -y ffmpeg
ffmpeg -i {読み込む動画ファイル名} -s {幅x高さ} {出力動画ファイル名}
ffmpeg -i video_org.mov -s 640x360 video_640x360.mov
Tags: [Raspberry Pi], [電子工作], [ディープラーニング]
●関連するコンテンツ(この記事を読んだ人は、次の記事も読んでいます)
NVIDIA Jetson Nano 開発者キットを買ってみた。メモリ容量 4GB LPDDR4 RAM
Jetson Nanoで TensorFlow PyTorch Caffe/Caffe2 Keras MXNet等を GPUパワーで超高速で動かす!
Raspberry Piでメモリを馬鹿食いするアプリ用に不要なサービスを停止してフリーメモリを増やす方法
ラズパイでメモリを沢山使用するビルドやアプリ用に不要なサービス等を停止して使えるメインメモリを増やす
【成功版】最新版の Darknetに digitalbrain79版の Darknet with NNPACKの NNPACK処理を適用する
ラズパイで NNPACK対応の最新版の Darknetを動かして超高速で物体検出や DeepDreamの悪夢を見る
【成功版】Raspberry Piで NNPACK対応版の Darknet Neural Network Frameworkをビルドする方法
ラズパイに Darknet NNPACK darknet-nnpackをソースからビルドして物体検出を行なう方法
【成功版】Raspberry Piで Darknet Neural Network Frameworkをビルドする方法
ラズパイに Darknet Neural Network Frameworkを入れて物体検出や悪夢のグロ画像を生成する
【成功版】Raspberry Piに TensorFlow Deep Learning Frameworkをインストールする方法
ラズパイに TensorFlow Deep Learning Frameworkを入れて Google DeepDreamで悪夢を見る方法
Raspberry Piで TensorFlow Deep Learning Frameworkを自己ビルドする方法
ラズパイで TensorFlow Deep Learning Frameworkを自己ビルドする方法
Raspberry Piで Caffe Deep Learning Frameworkで物体認識を行なってみるテスト
ラズパイで Caffe Deep Learning Frameworkを動かして物体認識を行なってみる
【ビルド版】Raspberry Piで DeepDreamを動かしてキモイ絵をモリモリ量産 Caffe Deep Learning Framework
ラズパイで Caffe Deep Learning Frameworkをビルドして Deep Dreamを動かしてキモイ絵を生成する
【インストール版】Raspberry Piで DeepDreamを動かしてキモイ絵をモリモリ量産 Caffe Deep Learning
ラズパイで Caffe Deep Learning Frameworkをインストールして Deep Dreamを動かしてキモイ絵を生成する
Raspberry Piで Caffe2 Deep Learning Frameworkをソースコードからビルドする方法
ラズパイで Caffe 2 Deep Learning Frameworkをソースコードから自己ビルドする方法
Orange Pi PC 2の 64bitのチカラで DeepDreamしてキモイ絵を高速でモリモリ量産してみるテスト
OrangePi PC2に Caffe Deep Learning Frameworkをビルドして Deep Dreamを動かしてキモイ絵を生成する
Raspberry Piに Jupyter Notebookをインストールして拡張子 ipynb形式の IPythonを動かす
ラズパイに IPython Notebookをインストールして Google DeepDream dream.ipynbを動かす
Raspberry Piで Deep Learningフレームワーク Chainerをインストールしてみる
ラズパイに Deep Learningのフレームワーク Chainerを入れてみた
Raspberry Piで DeepBeliefSDKをビルドして画像認識フレームワークを動かす方法
ラズパイに DeepBeliefSDKを入れて画像の物体認識を行なう
Raspberry Piで Microsoftの ELLをビルドする方法
ラズパイで Microsoftの ELL Embedded Learning Libraryをビルドしてみるテスト、ビルドするだけ
Raspberry Piで MXNet port of SSD Single Shot MultiBoxを動かして画像の物体検出をする方法
ラズパイで MXNet port of SSD Single Shot MultiBox Object Detectorで物体検出を行なってみる
Raspberry Piで Apache MXNet Incubatingをビルドする方法
ラズパイで Apache MXNet Incubatingをビルドしてみるテスト、ビルドするだけ
Raspberry Piで OpenCVの Haar Cascade Object Detectionでリアルタイムにカメラ映像の顔検出を行なってみる
ラズパイで OpenCVの Haar Cascade Object Detection Face & Eyeでリアルタイムでカメラ映像の顔検出をする方法
Raspberry Piで NNPACKをビルドする方法
ラズパイで NNPACKをビルドしてみるテスト、ビルドするだけ
Raspberry Pi 3の Linuxコンソール上で使用する各種コマンドまとめ
ラズパイの Raspbian OSのコマンドラインで使用する便利コマンド、負荷試験や CPUシリアル番号の確認方法等も
[HOME]
|
[BACK]
リンクフリー(連絡不要、ただしトップページ以外は Web構成の変更で移動する場合があります)
Copyright (c)
2018 FREE WING,Y.Sakamoto
Powered by 猫屋敷工房 & HTML Generator
http://www.neko.ne.jp/~freewing/raspberry_pi/raspberry_pi_darkflow_tensorflow_realtime_recognize_object/