HOME
  Security
   Software
    Hardware
  
FPGA
  CPU
   Android
    Raspberry Pi
  
nLite
  Xcode
   etc.
    ALL
  
LINK
BACK
 

2018/08/06

Orange Pi PC 2の 64bitのチカラで DeepDreamしてキモイ絵を高速でモリモリ量産してみるテスト Orange Pi PC 2の 64bitのチカラで DeepDreamしてキモイ絵を高速でモリモリ量産してみるテスト

(OrangePi PC2に Caffe Deep Learning Frameworkをビルドして Deep Dreamを動かしてキモイ絵を生成する)

Tags: [Raspberry Pi], [Orange Pi], [電子工作], [海外通販], [通信販売]





● Orange Pi PC 2の 64bitのチカラで DeepDreamしてキモイ絵を高速で量産してみるテスト

 Raspberry Piで DeepDreamを動かせる事を知ったので動かしてみました。ラズパイで動いたので次は Orange Piで動かすのがスジと言う物。
 Orange Pi PC2は 64bitで動くので 64bitのチカラも確認してみます。

 Orange Pi PC2で Google DeepDreamを動かして一時期流行したキモイ絵を量産します。

DeepDream - Wikipedia

 DeepDreamで生成した画像の例(Wikipediaより引用)
・DeepDream
DeepDream




● Raspberry Piで Caffe Deep Learning Frameworkを自前でビルドして DeepDreamする方法

2018/08/04
【ビルド版】Raspberry Piで DeepDreamを動かしてキモイ絵をモリモリ量産 Caffe Deep Learning Framework
【ビルド版】Raspberry Piで DeepDreamを動かしてキモイ絵をモリモリ量産 Caffe Deep Learning Framework

  ラズパイで Caffe Deep Learning Frameworkをビルドして Deep Dreamを動かしてキモイ絵を生成する


● Orange Pi PC2で Google DeepDreamを動かしてキモイ絵を量産する方法

 DeepDreamを動かすには Caffeと言う Deep Learning Frameworkを使用します。

 Orange Pi PC2の Ubuntuの場合は apt-get installで caffeをインストールできません。
 ※ Debianの場合は apt-get installで caffeをインストールが可能です。
user@orangepipc2:~$ apt-cache search caffe
caffeine - prevent the desktop becoming idle in full-screen mode
git-cola - highly caffeinated git GUI
ttf-aenigma - 465 free TrueType fonts by Brian Kent


●今回動かした Orange Pi PC2の OSのバージョン

Armbian_5.34.171121_Orangepipc2_Ubuntu_xenial_next_4.13.14.img

Welcome to ARMBIAN 5.34.171121 nightly Ubuntu 16.04.3 LTS 4.13.14-sunxi64

user@orangepipc2:~$ uname -a
Linux orangepipc2 4.13.14-sunxi64 #246 SMP Mon Nov 20 01:58:09 CET 2017 aarch64 aarch64 aarch64 GNU/Linux
Armbian_5.40_Orangepipc2_Ubuntu_xenial_next_4.14.15_desktop.img

Welcome to ARMBIAN 5.40 stable Ubuntu 16.04.3 LTS 4.14.15-sunxi64

user@orangepipc2:~$ uname -a
Linux orangepipc2 4.14.15-sunxi64 #30 SMP Tue Jan 30 17:40:12 CET 2018 aarch64 aarch64 aarch64 GNU/Linux
Armbian_5.40_Orangepipc2_Debian_stretch_next_4.14.15.img

Welcome to ARMBIAN 5.40 stable Debian GNU/Linux 9 (stretch) 4.14.15-sunxi64

user@orangepipc2:~$ uname -a
Linux orangepipc2 4.14.15-sunxi64 #30 SMP Tue Jan 30 17:40:12 CET 2018 aarch64 GNU/Linux


●メモリを沢山使うので不要なサービス等を停止して使えるメインメモリを増やす

 ビルドの前に行なうとビルド処理に対しても有利

● topコマンドでメモリの使用具合を確認する
● ARMBIAN 5.34.171121 nightly Ubuntu 16.04.3 LTS 4.13.14-sunxi64
top
  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
  523 root      20   0  274952  15124  12936 S   0.0  1.5   0:00.36 NetworkManager
  703 root      20   0  232552   7132   6288 S   0.0  0.7   0:00.07 polkitd
    1 root      20   0  154272   5208   3480 S   0.0  0.5   0:04.82 systemd
  530 syslog    20   0  225856   3164   2236 S   0.0  0.3   0:00.13 rsyslogd
  728 ntp       20   0   80428   4368   3736 S   0.0  0.4   0:00.60 ntpd

黄色のサービスを停止する
● ARMBIAN 5.40 stable Debian GNU/Linux 9 (stretch) 4.14.15-sunxi64
top
  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
  657 root      20   0  279036  16392  13980 S   0.0  1.6   0:00.30 NetworkMan+
  930 root      20   0  233932   7492   6600 S   0.0  0.7   0:00.07 polkitd
  605 root      20   0  217812   2656   2248 S   0.0  0.3   0:00.11 rsyslogd
 2409 user      20   0  159316   2956   1180 S   0.0  0.3   0:00.00 (sd-pam)
    1 root      20   0  157600   6440   4780 S   0.0  0.6   0:03.93 systemd
 1029 ntp       20   0   72828   3568   3016 S   0.0  0.4   0:00.12 ntpd

黄色のサービスを停止する
※ (sd-pam) = PAM(Pluggable Authentication Module)

 # ARMBIAN 5.34.171121 nightly Ubuntu 16.04.3 LTS 4.13.14-sunxi64
user@orangepipc2:~$ free -h

free -h
#               total        used        free      shared  buff/cache   available
# Mem:           994M         38M        716M         22M        240M        851M
# Swap:          497M          0B        497M

 # ARMBIAN 5.40 stable Debian GNU/Linux 9 (stretch) 4.14.15-sunxi64
user@orangepipc2:~$ free -h
#               total        used        free      shared  buff/cache   available
# Mem:           994M         50M        854M        4.9M         90M        873M
# Swap:          127M          0B        127M

# Disable rsyslogd syslog
sudo systemctl stop rsyslog.service
sudo systemctl disable rsyslog.service
sudo service rsyslog stop

# Disable NetworkManager
sudo systemctl stop NetworkManager.service
sudo systemctl disable NetworkManager.service

# Disable polkitd PolicyKit for ARMBIAN Ubuntu
sudo systemctl stop polkitd.service
sudo systemctl disable polkitd.service

# Disable polkitd PolicyKit for ARMBIAN Debian
sudo systemctl stop polkit.service
sudo systemctl disable polkit.service

# Disable ntpd NTP
sudo systemctl stop ntp.service
sudo systemctl disable ntp.service

# LEDの設定を変更する。
# なお Orange Pi PC2の場合のハートビート設定は CPUがハングアップしても点滅の動作は変になるが、点滅を続ける。
sudo sh -c "echo heartbeat > /sys/class/leds/orangepi\:red\:status/trigger"
sudo sh -c "echo mmc0 > /sys/class/leds/orangepi\:green\:pwr/trigger"

# CPUの動作周波数のガバナを Conservativeに設定して、電源への急激な負荷変動を発生しない様にする。
# Conservative設定は段階的に動作周波数を変化させるので負荷変動がマイルドになる。
sudo sh -c 'echo "conservative" >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor'

cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
# conservative
# conservative
# conservative
# conservative

# 再起動すると設定をわすれるっぽいので再起動しない
### sudo reboot

 # ARMBIAN 5.34.171121 nightly Ubuntu 16.04.3 LTS 4.13.14-sunxi64
user@orangepipc2:~$ free -h
              total        used        free      shared  buff/cache   available
Mem:           994M         35M        810M         22M        149M        856M
Swap:          497M          0B        497M


 # ARMBIAN 5.40 stable Debian GNU/Linux 9 (stretch) 4.14.15-sunxi64
user@orangepipc2:~$ free -h
              total        used        free      shared  buff/cache   available
Mem:           994M         43M        541M        4.0M        409M        877M
Swap:          127M          0B        127M


● Orange Piで Caffe Deep Learning Frameworkをビルドする

Caffe - Deep Learning Framework

BVLC/caffe
 Caffe: a fast open framework for deep learning. http://caffe.berkeleyvision.org/

 BVLC = Berkeley Vision and Learning Center(カリフォルニア大学バークレー校)

● caffeのビルド方法の情報源

 下記の caffe公式のインストール手順書を見ながら Orange Pi PC2環境に合わせて総合的に読み砕き応用して試行錯誤で Caffe Deep Learning Frameworkをビルドします。
Caffe - Installation
Caffe - Ubuntu Installation
Caffe - OS X Installation


●他に apt-getをしていないのに apt-getで lockファイルエラーが出ました。
user@orangepipc2:~/caffe$ sudo apt-get install libprotobuf-dev
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

 psでプロセスを確認すると apt.systemd.daily updateが動いています。
user@orangepipc2:~/caffe$ ps aux | grep apt | grep -v 'grep'
root      1319  0.0  0.0   1880   432 ?        Ss   10:32   0:00 /bin/sh /usr/lib/apt/apt.systemd.daily update
root      1323  0.0  0.1   1880  1132 ?        S    10:32   0:00 /bin/sh /usr/lib/apt/apt.systemd.daily lock_is_held update

 自動で定期的に動く apt-dailyと apt-daily-upgradesを停止して、手動で行なう apt-get installの操作とバッティングしない様にします。
 apt-dailyと言う「自動アップデート」、apt-daily-upgradesと言う「自動アップグレード」が定期的に動く様になっているので停止します。
 ※ 自動アップデートは sudo apt update、自動アップグレードは sudo apt upgradeと同等の動作になります。
# 自動で定期的に動く apt-dailyと apt-daily-upgradesを停止する
sudo systemctl mask apt-daily.service
sudo systemctl mask apt-daily.timer
sudo systemctl mask apt-daily-upgrade.service
sudo systemctl mask apt-daily-upgrade.timer


● Orange Pi PC2で Ubuntuや Debianで Python3 unattended-upgradesが勝手に実行される

Debian - UnattendedUpgrades

 インストールコマンドが下記の様になっているので
apt-get install unattended-upgrades apt-listchanges

 逆のアンインストールのコマンドを実行します。
sudo apt-get -y remove unattended-upgrades


● Orange Pi PC2の Ubuntuで X-Windowの Desktop環境を削除する

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
 1637 user      20   0  478428  71056  47676 S   0.0  7.0   0:01.63 nm-applet
 1629 user      20   0  454792  64644  45660 S   0.0  6.3   0:01.38 pasystray
 1635 user      20   0  403404  62796  30128 S   0.0  6.2   0:02.86 blueman-ap+
  670 root      20   0  135048  51576  32512 S   0.0  5.1   0:01.01 Xorg
 1630 user      20   0  276156  43160  36516 S   0.0  4.2   0:00.33 polkit-gno+
 1624 user      20   0  187884  28864  17252 S   0.0  2.8   0:00.96 xfce4-panel
 1646 user      20   0  113620  28704  12940 S   0.0  2.8   0:01.57 applet.py
 1628 user      20   0  253928  20800  15584 S   0.0  2.0   0:00.78 xfdesktop
 1620 user      20   0   27988  15844  13716 S   0.0  1.6   0:00.34 xfwm4
 1631 user      20   0  204272  15112  12800 S   0.0  1.5   0:00.20 xfsettingsd
 1782 user      20   0   25972  13864  12000 S   0.0  1.4   0:00.13 panel-2-ac+
 1779 user      20   0   24488  12620  10988 S   0.0  1.2   0:00.12 panel-6-sy+
 1612 user      20   0  172424  11800  10316 S   0.0  1.2   0:00.15 xfce4-sess+
 1626 user      20   0   25560  11708  10328 S   0.0  1.1   0:00.08 Thunar
 2384 user      20   0   53272   9092   7800 S   0.0  0.9   0:00.04 obexd
 1652 user      20   0  370832   9024   6304 S   0.0  0.9   0:00.27 pulseaudio
 1699 root      20   0  316596   8868   7152 S   0.0  0.9   0:00.14 udisksd
root@orangepipc2:~# cat /etc/systemd/system/default.target

root@orangepipc2:~# sudo systemctl enable multi-user.target --force
root@orangepipc2:~# sudo systemctl set-default multi-user.target
Created symlink from /etc/systemd/system/default.target to /lib/systemd/system/multi-user.target.
root@orangepipc2:~# cat /etc/systemd/system/default.target
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=Multi-User System
Documentation=man:systemd.special(7)
Requires=basic.target
Conflicts=rescue.service rescue.target
After=basic.target rescue.service rescue.target
AllowIsolate=yes
sudo apt remove -y xubuntu-desktop xfdesktop4 xfce4-* libxfce4-* lightdm-gtk-greeter
sudo apt autoremove -y
sudo reboot
user@orangepipc2:~$ systemctl list-unit-files | grep gdm
(無い)
user@orangepipc2:~$ systemctl list-unit-files | grep x11
x11-common.service                         masked

sudo systemctl stop x11-common.service
sudo systemctl disable x11-common.service


● Orange Pi PC2で Caffe Deep Learning Frameworkをビルドする。

# Orange Piでお決まりの sudo apt-get update
sudo apt-get update

# BVLC/caffeの Gitからソースリスト一式を clone(ダウンロード)する
cd
git clone https://github.com/BVLC/caffe.git --depth 1
cd
cd caffe

# Makefile.configファイルを作成(元々有る Makefile.config.exampleの参考例のファイルからコピー)する
cp Makefile.config.example Makefile.config
# Adjust Makefile.config (for example, if using Anaconda Python, or if cuDNN is desired)

# Makefile.configファイルをラズパイ環境に合わせて編集する
nano Makefile.config

# ラズパイ環境は演算処理に CPUしか使えないので CPU_ONLY := 1の行のコメント文字#を取って有効にする
# CPU-only switch (uncomment to build without GPU support).
CPU_ONLY := 1

# BLAS(Basic Linear Algebra Subprograms、ベクトルと行列に関する数値演算ライブラリの名称)
# 今回は BLASライブラリとして OpenBlas実装を使用します(OpenBlasはマルチスレッドに対応しています)
# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := open

# hdf5関係で「ファイルが見つからないエラー」が出るのでパスを設定する
# https://support.hdfgroup.org/HDF5/
# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/aarch64-linux-gnu/hdf5/serial

# コマンドラインでサクッと Makefile.configファイルを変更する
sed -i '8s/.*/CPU_ONLY := 1/' Makefile.config
sed -i '51s/.*/BLAS := open/' Makefile.config
sed -i '95s/.*/INCLUDE_DIRS := $(PYTHON_INCLUDE) \/usr\/local\/include \/usr\/include\/hdf5\/serial/' Makefile.config
sed -i '96s/.*/LIBRARY_DIRS := $(PYTHON_LIB) \/usr\/local\/lib \/usr\/lib \/usr\/lib\/aarch64-linux-gnu\/hdf5\/serial/' Makefile.config

# 編集内容を確認する
grep "BLAS " Makefile.config
grep "CPU" Makefile.config
grep "_DIRS :" Makefile.config

# 編集内容を確認する
user@orangepipc2:~/caffe $ grep "BLAS " Makefile.config
# BLAS choice:
BLAS := open

user@orangepipc2:~/caffe $ grep "CPU" Makefile.config
# CPU-only switch (uncomment to build without GPU support).
CPU_ONLY := 1

user@orangepipc2:~/caffe $ grep "_DIRS :" Makefile.config
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/aarch64-linux-gnu/hdf5/serial

● hdf5が有る場所
user@orangepipc2:~/caffe$ find /usr/ -name hdf5
/usr/include/hdf5
/usr/lib/aarch64-linux-gnu/hdf5

user@orangepipc2:~/caffe$ ls -l /usr/lib/aarch64-linux-gnu/hdf5/serial/
total 0
lrwxrwxrwx 1 root root 31 Apr  6  2016 include -> ../../../../include/hdf5/serial
lrwxrwxrwx 1 root root  1 Apr  6  2016 lib -> .
lrwxrwxrwx 1 root root 22 Apr  6  2016 libhdf5.a -> ../../libhdf5_serial.a
lrwxrwxrwx 1 root root 19 Apr  6  2016 libhdf5_cpp.a -> ../../libhdf5_cpp.a
lrwxrwxrwx 1 root root 20 Apr  6  2016 libhdf5_cpp.so -> ../../libhdf5_cpp.so
lrwxrwxrwx 1 root root 30 Apr  6  2016 libhdf5_fortran.a -> ../../libhdf5_serial_fortran.a
lrwxrwxrwx 1 root root 31 Apr  6  2016 libhdf5_fortran.so -> ../../libhdf5_serial_fortran.so
lrwxrwxrwx 1 root root 25 Apr  6  2016 libhdf5_hl.a -> ../../libhdf5_serial_hl.a
lrwxrwxrwx 1 root root 22 Apr  6  2016 libhdf5_hl_cpp.a -> ../../libhdf5_hl_cpp.a
lrwxrwxrwx 1 root root 23 Apr  6  2016 libhdf5_hl_cpp.so -> ../../libhdf5_hl_cpp.so
lrwxrwxrwx 1 root root 32 Apr  6  2016 libhdf5hl_fortran.a -> ../../libhdf5_serialhl_fortran.a
lrwxrwxrwx 1 root root 33 Apr  6  2016 libhdf5hl_fortran.so -> ../../libhdf5_serialhl_fortran.so
lrwxrwxrwx 1 root root 26 Apr  6  2016 libhdf5_hl.so -> ../../libhdf5_serial_hl.so
lrwxrwxrwx 1 root root 29 Apr  6  2016 libhdf5.settings -> ../../libhdf5_serial.settings
lrwxrwxrwx 1 root root 23 Apr  6  2016 libhdf5.so -> ../../libhdf5_serial.so

● (1) 事前に Caffeのビルドに必要なライブラリ等を apt-get installする
# install Library
sudo apt-get -y install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
# sudo apt-get -y install --no-install-recommends libboost-all-dev
sudo apt-get -y install libboost-dev
sudo apt-get -y install libgflags-dev libgoogle-glog-dev liblmdb-dev

# install OpenBLAS
sudo apt-get -y install libopenblas-dev

sudo apt-get -y install libboost-system-dev libboost-filesystem-dev libboost-thread-dev

● (2) make pycaffeの実行時にエラーが出ない様に必要なライブラリ等を apt-get installする
# /usr/bin/ld: cannot find -lboost_python
sudo apt-get -y install libboost-python-dev

● (3) deepdreamer.pyの実行時にエラーが出ない様に必要なライブラリ等を apt-get installする
# ImportError: No module named numpy
sudo apt-get -y install python-numpy

# ImportError: No module named skimage.io
sudo apt-get -y install python-skimage

# ImportError: No module named google.protobuf.internal
sudo apt-get -y install python-protobuf

## ImportError: No module named images2gif
#sed '196,198d' -i ./deepdreamer/deepdreamer.py
#sed '12d' -i ./deepdreamer/deepdreamer.py

# ImportError: No module named PIL.Image
sudo apt-get -y install python-pil

●上記の (1)~(3)の apt-get installを 1行で実行する
# Makefile.config, BLAS := open
sudo apt-get -y install libopenblas-dev libboost-dev libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler libgflags-dev libgoogle-glog-dev liblmdb-dev libboost-python-dev python-numpy python-skimage python-protobuf python-pil libboost-system-dev libboost-filesystem-dev libboost-thread-dev

# Makefile.config, BLAS := atlas
# sudo apt-get -y install libatlas-base-dev

●実際に caffeをビルドする
# make clean

# make all -j3で 3 coreを使ってビルド速度を高速化できるが、メモリ使用量と電源の相性がらみの不安定で落ちるのが怖いので 2 coreでビルドします
date >BUILD_START
time make all -j2
date >BUILD_END
cat BUILD_START
cat BUILD_END

# make testと make runtest
make test
make runtest

# Python用の Caffeの作成と distributeでビルド内容を反映
make pycaffe
make distribute

● make all -j2
 2 coreでビルド、ビルド時間は約 18分。
real    17m23.289s
user    33m15.530s
sys     1m13.343s
Sun Aug 12 05:51:42 UTC 2018
Sun Aug 12 06:09:06 UTC 2018

● make all -j3
 3 coreでビルド、ビルド時間は約 12分。
real    11m29.839s
user    32m40.048s
sys     1m13.328s
Sun Aug 12 09:58:21 UTC 2018
Sun Aug 12 10:09:51 UTC 2018

● make all
 1 coreでビルド
user@orangepipc2:~/caffe$ make all
...
AR -o .build_release/lib/libcaffe.a
LD -o .build_release/lib/libcaffe.so.1.0.0
CXX tools/convert_imageset.cpp
CXX/LD -o .build_release/tools/convert_imageset.bin
CXX tools/extract_features.cpp
CXX/LD -o .build_release/tools/extract_features.bin
CXX tools/upgrade_solver_proto_text.cpp
CXX/LD -o .build_release/tools/upgrade_solver_proto_text.bin
CXX tools/caffe.cpp
CXX/LD -o .build_release/tools/caffe.bin
CXX tools/upgrade_net_proto_binary.cpp
CXX/LD -o .build_release/tools/upgrade_net_proto_binary.bin
CXX tools/compute_image_mean.cpp
CXX/LD -o .build_release/tools/compute_image_mean.bin
CXX tools/upgrade_net_proto_text.cpp
CXX/LD -o .build_release/tools/upgrade_net_proto_text.bin
CXX examples/siamese/convert_mnist_siamese_data.cpp
CXX/LD -o .build_release/examples/siamese/convert_mnist_siamese_data.bin
CXX examples/mnist/convert_mnist_data.cpp
CXX/LD -o .build_release/examples/mnist/convert_mnist_data.bin
CXX examples/cpp_classification/classification.cpp
CXX/LD -o .build_release/examples/cpp_classification/classification.bin
CXX examples/cifar10/convert_cifar_data.cpp
CXX/LD -o .build_release/examples/cifar10/convert_cifar_data.bin

user@orangepipc2:~/caffe$ ./.build_release/tools/caffe -version
caffe version 1.0.0
user@orangepipc2:~/caffe$ ./.build_release/tools/caffe
caffe: command line brew
usage: caffe <command> <args>

commands:
  train           train or finetune a model
  test            score a model
  device_query    show GPU diagnostic information
  time            benchmark model execution time

  Flags from tools/caffe.cpp:
    -gpu (Optional; run in GPU mode on given device IDs separated by ','.Use
      '-gpu all' to run on all available GPUs. The effective training batch
      size is multiplied by the number of devices.) type: string default: ""
    -iterations (The number of iterations to run.) type: int32 default: 50
    -level (Optional; network level.) type: int32 default: 0
    -model (The model definition protocol buffer text file.) type: string
      default: ""
    -phase (Optional; network phase (TRAIN or TEST). Only used for 'time'.)
      type: string default: ""
    -sighup_effect (Optional; action to take when a SIGHUP signal is received:
      snapshot, stop or none.) type: string default: "snapshot"
    -sigint_effect (Optional; action to take when a SIGINT signal is received:
      snapshot, stop or none.) type: string default: "stop"
    -snapshot (Optional; the snapshot solver state to resume training.)
      type: string default: ""
    -solver (The solver definition protocol buffer text file.) type: string
      default: ""
    -stage (Optional; network stages (not to be confused with phase), separated
      by ','.) type: string default: ""
    -weights (Optional; the pretrained weights to initialize finetuning,
      separated by ','. Cannot be set simultaneously with snapshot.)
      type: string default: ""

● make test
 1 coreで test
user@orangepipc2:~/caffe$ make test
CXX src/caffe/test/test_solver.cpp
CXX src/caffe/test/test_split_layer.cpp
CXX src/caffe/test/test_protobuf.cpp
...
LD .build_release/src/caffe/test/test_contrastive_loss_layer.o
LD .build_release/src/caffe/test/test_multinomial_logistic_loss_layer.o
LD .build_release/src/caffe/test/test_argmax_layer.o
LD .build_release/src/caffe/test/test_data_layer.o
...
LD .build_release/src/caffe/test/test_crop_layer.o
LD .build_release/src/caffe/test/test_math_functions.o
LD .build_release/src/caffe/test/test_hdf5_output_layer.o

● make runtest
 1 coreで runtest
user@orangepipc2:~/caffe$ make runtest
.build_release/tools/caffe
caffe: command line brew
usage: caffe <command> <args>
...
.build_release/test/test_all.testbin 0 --gtest_shuffle --gtest_filter="-*GPU*"
Note: Google Test filter = -*GPU*
Note: Randomizing tests' orders with a seed of 1959 .
[==========] Running 1158 tests from 152 test cases.
[----------] Global test environment set-up.
[----------] 2 tests from InternalThreadTest
[ RUN      ] InternalThreadTest.TestStartAndExit
[       OK ] InternalThreadTest.TestStartAndExit (14 ms)
...
[ RUN      ] HingeLossLayerTest/1.TestGradientL1
[       OK ] HingeLossLayerTest/1.TestGradientL1 (1 ms)
[----------] 2 tests from HingeLossLayerTest/1 (2 ms total)

[----------] Global test environment tear-down
[==========] 1158 tests from 152 test cases ran. (3198949 ms total)
[  PASSED  ] 1158 tests.

user@orangepipc2:~/caffe$ make pycaffe
CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp
touch python/caffe/proto/__init__.py
PROTOC (python) src/caffe/proto/caffe.proto

●メモリ不足で make pycaffeが固まるので Swapを増やす。
 # ARMBIAN 5.40 stable Debian GNU/Linux 9 (stretch) 4.14.15-sunxi64

user@orangepipc2:~/caffe$ sudo cat /proc/swaps
Filename                                Type            Size    Used    Priority
/var/swap                               file            131068  21076   -2

# 不要 sudo apt-get install swapd 不要

# 512MBの Swapファイルを作成する
dd if=/dev/zero of=swapfile bs=1024 count=524288

# mkswap: swapfile: insecure permissions 0644, 0600 suggested.
chmod 0600 swapfile

# swapon: /home/user/caffe/swapfile: insecure file owner 1000, 0 (root) suggested.
sudo chown 0:0 swapfile

sudo /sbin/mkswap swapfile 524288
sync
sudo /sbin/swapon swapfile

user@orangepipc2:~/caffe$ free -h
              total        used        free      shared  buff/cache   available
Mem:           994M         35M        387M        284K        570M        885M
Swap:          639M         19M        620M

user@orangepipc2:~/caffe$ make distribute
# add proto
cp -r src/caffe/proto distribute/
# add include
cp -r include distribute/
mkdir -p distribute/include/caffe/proto
cp .build_release/src/caffe/proto/caffe.pb.h distribute/include/caffe/proto
# add tool and example binaries
cp .build_release/tools/convert_imageset.bin .build_release/tools/extract_features.bin .build_release/tools/upgrade_solver_proto_text.bin .build_release/tools/caffe.bin .build_release/tools/upgrade_net_proto_binary.bin .build_release/tools/compute_image_mean.bin .build_release/tools/upgrade_net_proto_text.bin distribute/bin
cp .build_release/examples/siamese/convert_mnist_siamese_data.bin .build_release/examples/mnist/convert_mnist_data.bin .build_release/examples/cpp_classification/classification.bin .build_release/examples/cifar10/convert_cifar_data.bin distribute/bin
# add libraries
cp .build_release/lib/libcaffe.a distribute/lib
install -m 644 .build_release/lib/libcaffe.so.1.0.0 distribute/lib
cd distribute/lib; rm -f libcaffe.so;   ln -s libcaffe.so.1.0.0 libcaffe.so
# add python - it's not the standard way, indeed...
cp -r python distribute/

user@orangepipc2:~/caffe$ ls -l distribute/
total 20
drwxrwxr-x 2 user user 4096 Aug  8 13:42 bin
drwxrwxr-x 3 user user 4096 Aug  8 13:42 include
drwxrwxr-x 2 user user 4096 Aug  8 13:42 lib
drwxrwxr-x 2 user user 4096 Aug  8 13:42 proto
drwxrwxr-x 3 user user 4096 Aug  8 13:42 python

user@orangepipc2:~/caffe$ ls -l distribute/bin
total 536
-rwxrwxr-x 1 user user 121408 Aug  8 13:42 caffe.bin
-rwxrwxr-x 1 user user  74160 Aug  8 13:42 classification.bin
-rwxrwxr-x 1 user user  27888 Aug  8 13:42 compute_image_mean.bin
-rwxrwxr-x 1 user user  31800 Aug  8 13:42 convert_cifar_data.bin
-rwxrwxr-x 1 user user  49936 Aug  8 13:42 convert_imageset.bin
-rwxrwxr-x 1 user user  32416 Aug  8 13:42 convert_mnist_data.bin
-rwxrwxr-x 1 user user  32128 Aug  8 13:42 convert_mnist_siamese_data.bin
-rwxrwxr-x 1 user user  92448 Aug  8 13:42 extract_features.bin
-rwxrwxr-x 1 user user  21632 Aug  8 13:42 upgrade_net_proto_binary.bin
-rwxrwxr-x 1 user user  21624 Aug  8 13:42 upgrade_net_proto_text.bin
-rwxrwxr-x 1 user user  21656 Aug  8 13:42 upgrade_solver_proto_text.bin

user@orangepipc2:~/caffe$ ls -l distribute/lib
total 20656
-rw-rw-r-- 1 user user 16617432 Aug  8 13:42 libcaffe.a
lrwxrwxrwx 1 user user       17 Aug  8 13:42 libcaffe.so -> libcaffe.so.1.0.0
-rw-r--r-- 1 user user  4530608 Aug  8 13:42 libcaffe.so.1.0.0

user@orangepipc2:~/caffe$ ls -l distribute/python/
total 36
drwxrwxr-x 5 user user 4096 Aug  8 13:42 caffe
-rwxrwxr-x 1 user user 4262 Aug  8 13:42 classify.py
-rw-rw-r-- 1 user user 1523 Aug  8 13:42 CMakeLists.txt
-rwxrwxr-x 1 user user 5734 Aug  8 13:42 detect.py
-rwxrwxr-x 1 user user 2254 Aug  8 13:42 draw_net.py
-rw-rw-r-- 1 user user  261 Aug  8 13:42 requirements.txt
-rw-rw-r-- 1 user user 3145 Aug  8 13:42 train.py


● Orange Pi PC2で Google Deep Dreamアプリを動かす

GitHub - google/deepdream
 Googleの deepdreamは IPythonと言う言語で動き、普通の Pythonでは動きません。

 普通の Pythonで動く様に移植した下記を使用します。
kesara/deepdreamer
 Easy to configure Python program that make use of Google's DeepDream. https://deepdreamer.fq.nz/

Deep Dreamer | deepdreamer

# Python版の Google Deep Dream kesara/deepdreamerをダウンロードする
cd
git clone https://github.com/kesara/deepdreamer
cd deepdreamer

# 学習データ bvlc_googlenet.caffemodelをダウンロードする
wget http://dl.caffe.berkeleyvision.org/bvlc_googlenet.caffemodel

# deploy.prototxtをダウンロードする
# https://github.com/BVLC/caffe/tree/master/models/bvlc_googlenet
wget https://raw.githubusercontent.com/BVLC/caffe/master/models/bvlc_googlenet/deploy.prototxt

# deploy.prototxtの一番最後に force_backward: trueの行を追加する
# nano deploy.prototxt
# force_backward: true

# コマンドラインでサクッと force_backward: trueの行を追加する
echo "force_backward: true" >> deploy.prototxt

# tailコマンドで最後に追加された事を確認する
tail deploy.prototxt

# ビルドで作成した Caffeをパスに追加する
export PYTHONPATH=/home/user/caffe/python:$PYTHONPATH
export LD_LIBRARY_PATH=/home/user/caffe/distribute/lib:$LD_LIBRARY_PATH

 python3で動かない。
user@orangepipc2:~/deepdreamer $ python3 deepdreamer.py sample.jpg

Traceback (most recent call last):
  File "deepdreamer.py", line 9, in <module>
    from deepdreamer.deepdreamer import deepdream, deepdream_video, list_layers
  File "/home/pi/deepdreamer/deepdreamer/deepdreamer.py", line 11, in <module>
    from caffe import Classifier, set_device, set_mode_gpu
  File "/home/pi/DeepDream/caffe/python/caffe/__init__.py", line 1, in <module>
    from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver, NCCL, Timer
  File "/home/pi/DeepDream/caffe/python/caffe/pycaffe.py", line 13, in <module>
    from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, \
ImportError: dynamic module does not define module export function (PyInit__caffe)

 python(python2)で動かない。
user@orangepipc2:~/deepdreamer $ python deepdreamer.py sample.jpg

Traceback (most recent call last):
  File "deepdreamer.py", line 9, in <module>
    from deepdreamer.deepdreamer import deepdream, deepdream_video, list_layers
  File "/home/pi/deepdreamer/deepdreamer/deepdreamer.py", line 12, in <module>
    from deepdreamer.images2gif import writeGif
ImportError: No module named images2gif

./deepdreamer/deepdreamer.py
 の
 images2gif import writeGifの gif動画書き出し機能を無効にする。
nano ./deepdreamer/deepdreamer.py

● 12行目をコメントにする。
# from deepdreamer.images2gif import writeGif

● 196~198行目をコメントにする。
#         writeGif(
#             "{}.gif".format(img_path), frames, duration=duration,
#             repeat=loop)

# コマンドラインでサクッと deepdreamer/deepdreamer.pyを編集する
# 196~198行目を削除する
sed '196,198d' -i ./deepdreamer/deepdreamer.py
# 12行目を削除する
sed '12d' -i ./deepdreamer/deepdreamer.py

 python(python2)で動く様になる。
user@orangepipc2:~/deepdreamer $ python deepdreamer.py sample.jpg
...
    weight_filler {
      type: "xavier"
      std: 0.2
    }
    bias_filler {
      type: "c
I0808 14:13:54.593655  2097 layer_factory.hpp:77] Creating layer data
I0808 14:13:54.593793  2097 net.cpp:84] Creating Layer data
I0808 14:13:54.593852  2097 net.cpp:380] data -> data
I0808 14:13:54.593928  2097 net.cpp:122] Setting up data
I0808 14:13:54.593957  2097 net.cpp:129] Top shape: 10 3 224 224 (1505280)
I0808 14:13:54.593993  2097 net.cpp:137] Memory required for data: 6021120
I0808 14:13:54.594020  2097 layer_factory.hpp:77] Creating layer conv1/7x7_s2
...
I0808 14:13:57.750905  2097 net.cpp:744] Ignoring source layer loss2/classifier
I0808 14:13:57.750928  2097 net.cpp:744] Ignoring source layer loss2/loss
I0808 14:13:57.766621  2097 net.cpp:744] Ignoring source layer loss3/loss3
Dreaming...
/usr/lib/python2.7/dist-packages/scipy/ndimage/interpolation.py:549: UserWarning: From scipy 0.13.0, the output shape of zoom() is calculated with round() instead of int() - for these inputs the size of the returned array has changed.
  "the returned array has changed.", UserWarning)

# 環境変数で OpenBLASライブラリを 1コアで動かす指定をする
export OPENBLAS_NUM_THREADS=1

cd
cd deepdreamer
wget https://github.com/google/deepdream/raw/master/flowers.jpg

export PYTHONPATH=/home/user/caffe/python:$PYTHONPATH
export LD_LIBRARY_PATH=/home/user/caffe/distribute/lib:$LD_LIBRARY_PATH

python deepdreamer.py flowers.jpg
# 1コア 3分 33秒/枚(1世代)
・環境変数で OpenBLASライブラリを 1コアで動かす指定をする
環境変数で OpenBLASライブラリを 1コアで動かす指定をする



# 環境変数で OpenBLASライブラリを 2コアで動かす指定をする
export OPENBLAS_NUM_THREADS=2

cd
cd deepdreamer
wget https://github.com/google/deepdream/raw/master/flowers.jpg

export PYTHONPATH=/home/user/caffe/python:$PYTHONPATH
export LD_LIBRARY_PATH=/home/user/caffe/distribute/lib:$LD_LIBRARY_PATH

python deepdreamer.py flowers.jpg
# 2コア 2分 58秒/枚(1世代)

# 環境変数で OpenBLASライブラリを 3コアで動かす指定をする
export OPENBLAS_NUM_THREADS=3

cd
cd deepdreamer
wget https://github.com/google/deepdream/raw/master/flowers.jpg

export PYTHONPATH=/home/user/caffe/python:$PYTHONPATH
export LD_LIBRARY_PATH=/home/user/caffe/distribute/lib:$LD_LIBRARY_PATH

python deepdreamer.py flowers.jpg
# 3コア 2分 58秒/枚(1世代)
・環境変数で OpenBLASライブラリを 1コアで動かす指定をする
環境変数で OpenBLASライブラリを 1コアで動かす指定をする




●生成したキモイ絵

user@orangepipc2:~$ uname -a
Linux orangepipc2 4.13.14-sunxi64 #246 SMP Mon Nov 20 01:58:09 CET 2017 aarch64 aarch64 aarch64 GNU/Linux

user@orangepipc2:~$ cat /proc/cpuinfo
processor       : 0
BogoMIPS        : 48.00
Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x0
CPU part        : 0xd03
CPU revision    : 4

 Orange Pi PC 2の
 OpenBLASライブラリ
export OPENBLAS_NUM_THREADS=2
 で 2コア実行で
320x240px 1枚(1世代)生成するのに 3分
 ラズパイ3B+と変わらんな~。

 Caffe + Google DeepDreamerで生成したキモイ絵は下記に有ります。

2018/08/04
【ビルド版】Raspberry Piで DeepDreamを動かしてキモイ絵をモリモリ量産 Caffe Deep Learning Framework
【ビルド版】Raspberry Piで DeepDreamを動かしてキモイ絵をモリモリ量産 Caffe Deep Learning Framework

  ラズパイで Caffe Deep Learning Frameworkをビルドして Deep Dreamを動かしてキモイ絵を生成する


● Orange Pi PC2で Google DeepDreamを動かしてキモイ絵を量産する方法

 DeepDreamを動かすには Caffeと言う Deep Learning Frameworkを使用します。

 Orange Pi PC2の Ubuntuの場合は apt-get installで caffeをインストールできません。
 ※ Debianの場合は apt-get installで caffeをインストールが可能です。
Welcome to ARMBIAN 5.40 stable Debian GNU/Linux 9 (stretch) 4.14.15-sunxi64

root@orangepipc2:~# uname -a
Linux orangepipc2 4.14.15-sunxi64 #30 SMP Tue Jan 30 17:40:12 CET 2018 aarch64 GNU/Linux

root@orangepipc2:~# apt-cache search caffe
caffe-cpu - Fast, open framework for Deep Learning (Meta)
caffe-doc - Caffe's doxygen docs and examples
caffe-tools-cpu - Tools for fast, open framework for Deep Learning (CPU_ONLY)
libcaffe-cpu-dev - development files for Caffe (CPU_ONLY)
libcaffe-cpu1 - library of Caffe, deep learning framework (CPU_ONLY)
python3-caffe-cpu - Python3 interface of Caffe (CPU_ONLY)

root@orangepipc2:~# apt search caffe-cpu
Sorting... Done
Full Text Search... Done
caffe-cpu/stable 1.0.0~rc4-1 arm64
  Fast, open framework for Deep Learning (Meta)

libcaffe-cpu-dev/stable 1.0.0~rc4-1 arm64
  development files for Caffe (CPU_ONLY)

libcaffe-cpu1/stable 1.0.0~rc4-1 arm64
  library of Caffe, deep learning framework (CPU_ONLY)

python3-caffe-cpu/stable 1.0.0~rc4-1 arm64
  Python3 interface of Caffe (CPU_ONLY)



Tags: [Raspberry Pi], [Orange Pi], [電子工作], [海外通販], [通信販売]

●関連するコンテンツ(この記事を読んだ人は、次の記事も読んでいます)

NVIDIA Jetson Nano 開発者キットを買ってみた。メモリ容量 4GB LPDDR4 RAM
NVIDIA Jetson Nano 開発者キットを買ってみた。メモリ容量 4GB LPDDR4 RAM

  Jetson Nanoで TensorFlow PyTorch Caffe/Caffe2 Keras MXNet等を GPUパワーで超高速で動かす!

Raspberry Piでメモリを馬鹿食いするアプリ用に不要なサービスを停止してフリーメモリを増やす方法
Raspberry Piでメモリを馬鹿食いするアプリ用に不要なサービスを停止してフリーメモリを増やす方法

  ラズパイでメモリを沢山使用するビルドやアプリ用に不要なサービス等を停止して使えるメインメモリを増やす

【成功版】最新版の Darknetに digitalbrain79版の Darknet with NNPACKの NNPACK処理を適用する
【成功版】最新版の Darknetに digitalbrain79版の Darknet with NNPACKの NNPACK処理を適用する

  ラズパイで NNPACK対応の最新版の Darknetを動かして超高速で物体検出や DeepDreamの悪夢を見る

【成功版】Raspberry Piで NNPACK対応版の Darknet Neural Network Frameworkをビルドする方法
【成功版】Raspberry Piで NNPACK対応版の Darknet Neural Network Frameworkをビルドする方法

  ラズパイに Darknet NNPACK darknet-nnpackをソースからビルドして物体検出を行なう方法

【成功版】Raspberry Piで Darknet Neural Network Frameworkをビルドする方法
【成功版】Raspberry Piで Darknet Neural Network Frameworkをビルドする方法

  ラズパイに Darknet Neural Network Frameworkを入れて物体検出や悪夢のグロ画像を生成する

【成功版】Raspberry Piに TensorFlow Deep Learning Frameworkをインストールする方法
【成功版】Raspberry Piに TensorFlow Deep Learning Frameworkをインストールする方法

  ラズパイに TensorFlow Deep Learning Frameworkを入れて Google DeepDreamで悪夢を見る方法

Raspberry Piで TensorFlow Deep Learning Frameworkを自己ビルドする方法
Raspberry Piで TensorFlow Deep Learning Frameworkを自己ビルドする方法

  ラズパイで TensorFlow Deep Learning Frameworkを自己ビルドする方法

Raspberry Piで Caffe Deep Learning Frameworkで物体認識を行なってみるテスト
Raspberry Piで Caffe Deep Learning Frameworkで物体認識を行なってみるテスト

  ラズパイで Caffe Deep Learning Frameworkを動かして物体認識を行なってみる

【ビルド版】Raspberry Piで DeepDreamを動かしてキモイ絵をモリモリ量産 Caffe Deep Learning Framework
【ビルド版】Raspberry Piで DeepDreamを動かしてキモイ絵をモリモリ量産 Caffe Deep Learning Framework

  ラズパイで Caffe Deep Learning Frameworkをビルドして Deep Dreamを動かしてキモイ絵を生成する

【インストール版】Raspberry Piで DeepDreamを動かしてキモイ絵をモリモリ量産 Caffe Deep Learning
【インストール版】Raspberry Piで DeepDreamを動かしてキモイ絵をモリモリ量産 Caffe Deep Learning

  ラズパイで Caffe Deep Learning Frameworkをインストールして Deep Dreamを動かしてキモイ絵を生成する

Raspberry Piで Caffe2 Deep Learning Frameworkをソースコードからビルドする方法
Raspberry Piで Caffe2 Deep Learning Frameworkをソースコードからビルドする方法

  ラズパイで Caffe 2 Deep Learning Frameworkをソースコードから自己ビルドする方法

Raspberry Piに Jupyter Notebookをインストールして拡張子 ipynb形式の IPythonを動かす
Raspberry Piに Jupyter Notebookをインストールして拡張子 ipynb形式の IPythonを動かす

  ラズパイに IPython Notebookをインストールして Google DeepDream dream.ipynbを動かす

Raspberry Piで Deep Learningフレームワーク Chainerをインストールしてみる
Raspberry Piで Deep Learningフレームワーク Chainerをインストールしてみる

  ラズパイに Deep Learningのフレームワーク Chainerを入れてみた

Raspberry Piで DeepBeliefSDKをビルドして画像認識フレームワークを動かす方法
Raspberry Piで DeepBeliefSDKをビルドして画像認識フレームワークを動かす方法

  ラズパイに DeepBeliefSDKを入れて画像の物体認識を行なう

Raspberry Piで Microsoftの ELLをビルドする方法
Raspberry Piで Microsoftの ELLをビルドする方法

  ラズパイで Microsoftの ELL Embedded Learning Libraryをビルドしてみるテスト、ビルドするだけ

Raspberry Piで MXNet port of SSD Single Shot MultiBoxを動かして画像の物体検出をする方法
Raspberry Piで MXNet port of SSD Single Shot MultiBoxを動かして画像の物体検出をする方法

  ラズパイで MXNet port of SSD Single Shot MultiBox Object Detectorで物体検出を行なってみる

Raspberry Piで Apache MXNet Incubatingをビルドする方法
Raspberry Piで Apache MXNet Incubatingをビルドする方法

  ラズパイで Apache MXNet Incubatingをビルドしてみるテスト、ビルドするだけ

Raspberry Piで OpenCVの Haar Cascade Object Detectionでリアルタイムにカメラ映像の顔検出を行なってみる
Raspberry Piで OpenCVの Haar Cascade Object Detectionでリアルタイムにカメラ映像の顔検出を行なってみる

  ラズパイで OpenCVの Haar Cascade Object Detection Face & Eyeでリアルタイムでカメラ映像の顔検出をする方法

Raspberry Piで NNPACKをビルドする方法
Raspberry Piで NNPACKをビルドする方法

  ラズパイで NNPACKをビルドしてみるテスト、ビルドするだけ

Raspberry Pi 3の Linuxコンソール上で使用する各種コマンドまとめ
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/orange_pi_pc2_build_caffe_deep_dream_image/