-
很多包需要下載編譯,以孱弱的Raspberry Pi編譯應用,需要極大的耐心。
-
然而開源的深度學習框架很多,不同類庫的依賴不同,有些會互相衝突,比如有些需要Python 2.7,有些則依賴 3.x。雖然我們可以用virtualenv對Python環境進行隔離,但是對於一些系統級的依賴衝突就不好辦了。在漫長構建中遇到依賴導致編譯失敗,讓人非常有挫敗感。
-
如果需要在另外一塊板上部署相同應用,整個過程需要重新來過。
下麵我們將利用Docker來構建打包應用映象,這樣可以一次構建到處執行,也可以充分利用Dockerfile自帶的分層能力,可以方便地調整依賴包,這樣在開發部署過程中格外高效。
# Install Docker
curl -sSL https://get.docker.com | sh
# Add pi to Docker group
sudo usermod pi -aG docker
# config cgroup for Docker
echo Adding " cgroup_enable=cpuset cgroup_enable=memory" to /boot/cmdline.txt
sudo cp /boot/cmdline.txt /boot/cmdline_backup.txt
# if you encounter problems, try changing cgroup_memory=1 to cgroup_enable=memory.
orig="$(head -n1 /boot/cmdline.txt) cgroup_enable=cpuset cgroup_memory=1"
echo $orig | sudo tee /boot/cmdline.txt
sudo reboot
docker run -it \
--name face_recognition \
--device /dev/vchiq \
registry.cn-hangzhou.aliyuncs.com/denverdino/face_recognition \
bash
# This is a demo of running face recognition on a Raspberry Pi.
# This program will print out the names of anyone it recognizes to the console.
# To run this, you need a Raspberry Pi 2 (or greater) with face_recognition and
# the picamera[array] module installed.
# You can follow this installation instructions to get your RPi set up:
# https://gist.github.com/ageitgey/1ac8dbe8572f3f533df6269dab35df65
import face_recognition
import picamera
import numpy as np
known_face_encodings = []
names = []
def load_face_encoding(name, file_name):
image = face_recognition.load_image_file(file_name)
face_encoding = face_recognition.face_encodings(image)[0]
known_face_encodings.append(face_encoding)
names.append(name)
# Get a reference to the Raspberry Pi camera.
# If this fails, make sure you have a camera connected to the RPi and that you
# enabled your camera in raspi-config and rebooted first.
camera = picamera.PiCamera()
camera.resolution = (320, 240)
output = np.empty((240, 320, 3), dtype=np.uint8)
# Load a sample picture and learn how to recognize it.
print("Loading known face image(s)")
load_face_encoding("Yi Li", "yili.jpg")
load_face_encoding("Zhang Kai", "zhangkai.jpg")
load_face_encoding("Che Yang", "cheyang.jpg")
# Initialize some variables
face_locations = []
face_encodings = []
while True:
print("Capturing image.")
# Grab a single frame of video from the RPi camera as a numpy array
camera.capture(output, format="rgb")
# Find all the faces and face encodings in the current frame of video
face_locations = face_recognition.face_locations(output)
print("Found {} faces in image.".format(len(face_locations)))
face_encodings = face_recognition.face_encodings(output, face_locations)
# Loop over each face found in the frame to see if it's someone we know.
for face_encoding in face_encodings:
# See if the face is a match for the known face(s)
matches = face_recognition.face_distance(known_face_encodings, face_encoding)
name = "
min_distance = min(matches)
if min_distance < 0.6:
i = matches.argmin()
name = names[i]
print("I see someone named {}!".format(name))
load_face_encoding("Yi Li", "yili.jpg")
face_locations = face_recognition.face_locations(output)
...
face_encodings = face_recognition.face_encodings(output, face_locations)
matches = face_recognition.face_distance(known_face_encodings, face_encoding)
# python3 facerec_on_raspberry_pi.py
Loading known face image(s)
Found 0 faces in image.
Capturing image.
Found 0 faces in image.
Capturing image.
Found 1 faces in image.
I see someone named Yi Li!
...
FROM resin/raspberry-pi-python:3
COPY pip.conf /root/.pip/pip.conf
RUN apt-get -y update
RUN apt-get install -y --fix-missing \
build-essential \
cmake \
gfortran \
git \
wget \
curl \
graphicsmagick \
libgraphicsmagick1-dev \
libatlas-dev \
libavcodec-dev \
libavformat-dev \
libboost-all-dev \
libgtk2.0-dev \
libjpeg-dev \
liblapack-dev \
libswscale-dev \
pkg-config \
python3-dev \
zip \
&& apt-get clean && rm -rf /tmp/* /var/tmp/*
RUN python3 -m ensurepip --upgrade && pip3 install --upgrade picamera[array] dlib
# The rest of this file just runs an example script.
# If you wanted to use this Dockerfile to run your own app instead, maybe you would do this:
# COPY . /root/your_app_or_whatever
# RUN cd /root/your_app_or_whatever && \
# pip3 install -r requirements.txt
# RUN whatever_command_you_run_to_start_your_app
RUN git clone --single-branch https://github.com/ageitgey/face_recognition.git
RUN cd /face_recognition && \
pip3 install -r requirements.txt && \
python3 setup.py install
CMD cd /face_recognition/examples && \
python3 recognize_faces_in_pictures.py
本次培訓包含:Kubernetes核心概念;Kubernetes叢集的安裝配置、運維管理、架構規劃;Kubernetes元件、監控、網路;針對於Kubernetes API介面的二次開發;DevOps基本理念;微服務架構;微服務的容器化等,點選識別下方二維碼加微信好友瞭解具體培訓內容。