Raspberry Pi Zero/物体認識
これに関する依存ライブラリ周り
コンソールからディスプレイ
AWS
多分SageMakerで適当なモデル作って出力になる。
AWS IoTとは統合されてる。
Amazon Rekognition(カスタムラベル)はエッジ向けモデルを提供してない?
デバイスは、興味を引くような事柄や懸念が生じたときにイメージまたはビデオをクラウドに渡し、Amazon Rekognition を使ってより詳しく調べることができます。
Azure
Custom Visionがエッジデバイス向けの軽量モデルエクスポートに対応している。
TensorFlow
tfite_runtimeのarmv6l向けビルドは用意されていない。
Arm向けビルドを作っている人がいる。
メモリ量が足らないのでスワップを拡張しておく。
memo
Pythonクイックスタート
armv6l向けビルドない。
pip3 install tensorflow
まずメモリ不足に対応するため、スワップサイズを拡張する。
pi@raspberrypi:~$ sudo vi /etc/dphys-swapfile
CONF_SWAPSIZE=2048
pi@raspberrypi:~$ sudo /etc/init.d/dphys-swapfile restart
code:memo.py
import io, picamera, pygame, sys, os
import argparse
import cv2
import numpy as np
from cv2 import dnn
from pygame.locals import *
import threading
parser = argparse.ArgumentParser()
parser.add_argument("--video", help="number of video device", default=0)
parser.add_argument("--prototxt", default="mobilenet_v2_deploy.prototxt")
parser.add_argument("--caffemodel", default="mobilenet_v2.caffemodel")
parser.add_argument("--classNames", default="synset.txt")
args = parser.parse_args()
width = 480
height= 640
camera = picamera.PiCamera()
camera.resolution = (width, height)
camera.rotation = 90
net = dnn.readNetFromCaffe(args.prototxt, args.caffemodel)
f = open(args.classNames, 'r')
rawClassNames = f.readlines()
classNames = []
for nameStr in rawClassNames:
spaceIndex = nameStr.find(' ')
classNames.append(nameStr)
inWidth = 224
inHeight = 224
inScaleFactor = 0.017
meanVal = (103.94, 116.78, 123.68)
resultText = None
pygame.init()
screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN, 0)
screen.fill(0)
basicfont = pygame.font.SysFont(None, 15)
frame_cnt = 0
last_frame_cnt = 0
img = None
resultText = None
def dnn_worker():
global frame_cnt
global img
global resultText
while True:
frame = np.empty((width * height * 3), dtype=np.uint8)
camera.capture(frame, format='rgb')
frame = frame.reshape((height, width, 3))
blob = dnn.blobFromImage(frame, inScaleFactor, (inWidth, inHeight), meanVal)
net.setInput(blob)
detections = net.forward()
maxClassId = 0
maxClassPoint = 0;
for i in range(detections.shape1): if (classPoint > maxClassPoint):
maxClassId = i
maxClassPoint = classPoint
img = pygame.image.frombuffer(frame.tobytes(), (width, height), 'RGB')
img = pygame.transform.scale(img, (int(img.get_width() * 480 / img.get_height()), 480))
frame_cnt = frame_cnt + 1
dnn_t = threading.Thread(target=dnn_worker)
dnn_t.start()
while True:
if (frame_cnt != last_frame_cnt):
last_frame_cnt = frame_cnt
screen.blit(img, (0, 0))
if (resultText != None):
screen.fill((0, 0, 0), resultText.get_rect())
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
pygame.display.update()