BPI-M4 : Nginx 스트리밍 서버 구축(컴파일)

OS/Banana Pi /BPI-Bit 2021. 2. 23. 01:44 Posted by 파란크리스마스

출처

openssl 라이브러리 소스 다운로드

pi@bpi-iot-ros-ai:~$ wget http://www.openssl.org/source/openssl-1.1.1g.tar.gz
pi@bpi-iot-ros-ai:~$ tar xvf openssl-1.1.1g.tar.gz

PCRE 라이브러리 설치

pi@bpi-iot-ros-ai:~$ wget https://acc.dl.osdn.jp/sfnet/p/pc/pcre/pcre/8.32/pcre-8.32.tar.gz
pi@bpi-iot-ros-ai:~$ tar xvf pcre-8.32.tar.gz
pi@bpi-iot-ros-ai:~$ cd pcre-8.32/
pi@bpi-iot-ros-ai:~/pcre-8.32$ ./configure --prefix=/usr/local
pi@bpi-iot-ros-ai:~/pcre-8.32$ make
pi@bpi-iot-ros-ai:~/pcre-8.32$ sudo make install

zip 라이브러리 설치

pi@bpi-iot-ros-ai:~$ wget https://zlib.net/fossils/zlib-1.2.8.tar.gz
pi@bpi-iot-ros-ai:~$ tar xvf zlib-1.2.8.tar.gz 
pi@bpi-iot-ros-ai:~$ cd zlib-1.2.8/
pi@bpi-iot-ros-ai:~/zlib-1.2.8$ ./configure --prefix=/usr/localmake
pi@bpi-iot-ros-ai:~/zlib-1.2.8$ make -j4
pi@bpi-iot-ros-ai:~/zlib-1.2.8$ sudo make install

nginx 설치

nginx-vod-module 소스 다운로드

pi@bpi-iot-ros-ai:~$ git clone https://github.com/kaltura/nginx-vod-module.git

nginx 소스 다운로드

pi@bpi-iot-ros-ai:~$ wget http://nginx.org/download/nginx-1.19.7.tar.gz
pi@bpi-iot-ros-ai:~$ tar xvf nginx-1.19.7.tar.gz
pi@bpi-iot-ros-ai:~$ cd nginx-1.19.7/

빌드 환경 설정 - configure

  • --add-module=../nginx-vod-module : 스트리밍 관련 라이브러리 추가
  • --pid-path : pid 파일 생성 기본 경로 / 해당 옵션이 없는 경우 nginx.conf에서 설정 가능
pi@bpi-iot-ros-ai:~/nginx-1.19.7$ ./configure \
  --add-module=../nginx-vod-module \
  --prefix=/usr/local/nginx \
  --conf-path=/usr/local/nginx/conf/nginx.conf \
  --error-log-path=/usr/local/nginx/logs/error.log \
  --http-log-path=/usr/local/nginx/logs/access.log \
  --user=nginx \
  --group=nginx \
  --lock-path=/usr/local/nginx/system/nginx.lock \
  --pid-path=/usr/local/nginx/system/nginx.pid \
  --without-http_autoindex_module \
  --without-http_ssi_module \
  --with-file-aio \
  --with-http_ssl_module \
  --with-openssl=../openssl-1.1.1g \
  --with-openssl-opt=enable-weak-ssl-ciphers \
  --with-http_gunzip_module \
  --with-http_gzip_static_module \
  --with-http_random_index_module \
  --with-http_secure_link_module \
  --with-http_stub_status_module \
  --with-http_auth_request_module \
  --with-http_addition_module \
  --with-http_realip_module \
  --with-http_stub_status_module \
  --with-threads --with-stream \
  --with-stream_ssl_module \
  --with-http_v2_module \
  --http-client-body-temp-path=/var/cache/nginx/client_body_temp \
  --http-proxy-temp-path=/var/cache/nginx/proxy_temp \
  --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
  --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
  --http-scgi-temp-path=/var/cache/nginx/scgi_temp

빌드

pi@bpi-iot-ros-ai:~/nginx-1.19.7$ make -j4

설치

pi@bpi-iot-ros-ai:~/nginx-1.19.7$ sudo make install
make -f objs/Makefile install
make[1]: Entering directory '/home/pi/nginx-1.19.7'
cp objs/nginx '/usr/local/nginx/sbin/nginx'
cp conf/koi-win '/usr/local/nginx/conf'
cp conf/koi-utf '/usr/local/nginx/conf'
cp conf/win-utf '/usr/local/nginx/conf'
cp conf/mime.types '/usr/local/nginx/conf/mime.types.default'
cp conf/fastcgi_params \
        '/usr/local/nginx/conf/fastcgi_params.default'
cp conf/fastcgi.conf '/usr/local/nginx/conf/fastcgi.conf.default'
cp conf/uwsgi_params \
        '/usr/local/nginx/conf/uwsgi_params.default'
cp conf/scgi_params \
        '/usr/local/nginx/conf/scgi_params.default'
cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf.default'
test -d '/usr/local/nginx/system' \
        || mkdir -p '/usr/local/nginx/system'
test -d '/usr/local/nginx/logs' \
        || mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/html' \
        || cp -R html '/usr/local/nginx'
test -d '/usr/local/nginx/logs' \
        || mkdir -p '/usr/local/nginx/logs'
make[1]: Leaving directory '/home/pi/nginx-1.19.7'

nginx 계정 추가

error.log에 해당 오류 발견시 계정 추가 필요 nginx: [emerg] getpwnam("nginx") failed

pi@bpi-iot-ros-ai:~$ sudo groupadd nginx
pi@bpi-iot-ros-ai:~$ sudo useradd -g nginx -s /bin/bash -m nginx

nginx 서비스 등록

nginx.service 파일 생성

pi@bpi-iot-ros-ai:~$ sudo vi /etc/systemd/system/nginx.service

 

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/system/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

nginx.service 서비스 등록

pi@bpi-iot-ros-ai:~$ sudo systemctl enable nginx.service
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /etc/systemd/system/nginx.service.

nginx.service 서비스 시작

pi@bpi-iot-ros-ai:~$ sudo systemctl start nginx.service

nginx.service 서비스 상태확인

pi@bpi-iot-ros-ai:~$ sudo systemctl status nginx.service

nginx 스트리밍 관련 환경 설정

nginx.conf 수정

pi@bpi-iot-ros-ai:~$ sudo vi /usr/local/nginx/conf/nginx.conf

 

    server {
        listen       80;
        server_name  localhost;

        # vod settings
        vod_mode local;
        vod_fallback_upstream_location /fallback;
        vod_last_modified 'Sun, 19 Nov 2000 08:52:00 GMT';
        vod_last_modified_types *;
        vod_metadata_cache metadata_cache 512m;
        vod_response_cache response_cache 128m;
        gzip on;
        gzip_types application/vnd.apple.mpegurl;

        vod_segment_duration 1000;

        open_file_cache          max=1000 inactive=5m;
        open_file_cache_valid    2m;
        open_file_cache_min_uses 1;
        open_file_cache_errors   on;
        aio on;
        location /content/ {
                root /media_content/;
                vod hls;
                add_header Access-Control-Allow-Headers '*';
                add_header Access-Control-Expose-Headers 'Server,range,Content-Length,Content-Range';
                add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
                add_header Access-Control-Allow-Origin '*';
                expires 100d;
        }

nginx.service 서비스 재시작

pi@bpi-iot-ros-ai:~$ sudo systemctl restart nginx.service

동영상 파일 복사

pi@bpi-iot-ros-ai:~$ sudo mkdir -p /media_content/content
pi@bpi-iot-ros-ai:~$ cd /media_content/content
pi@bpi-iot-ros-ai:/media_content/content$ wget https://www.radiantmediaplayer.com/media/big-buck-bunny-360p.mp4

동영상 구현 (hls.js)

pi@bpi-iot-ros-ai:~$ cd /usr/local/nginx/html
pi@bpi-iot-ros-ai:/usr/local/nginx/html$ sudo vi player.htm

 

<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
<video id="video" controls></video>
<script>
  if(Hls.isSupported()) {
    var video = document.getElementById('video');
    var hls = new Hls();
    hls.loadSource('http://192.168.0.87/content/big-buck-bunny-360p.mp4/index.m3u8');
    hls.attachMedia(video);
    hls.on(Hls.Events.MANIFEST_PARSED,function() {
      // video.play();
    });
  }
</script>

확인

TAG BPI M4, nginx

댓글을 달아 주세요

BPI-M4 : M.2 E-Key - SD 드라이브 설치

OS/Banana Pi /BPI-Bit 2021. 2. 20. 02:19 Posted by 파란크리스마스

출처

BPI-M4의 경우 전용 카메라, 모니터를 사용할 수 있는 확장 슬롯이 없고 기본 eMMC가 용량이 작아서 아쉬웠는데 M.2 E-Key로 SD 메모리를 확장 할 수 있어서 소개합니다.

SD 메모리 장착 전, 후
확장보드 장착 전, 후

리눅스 정보 확인

pi@bpi-iot-ros-ai:~$ uname -a
Linux bpi-iot-ros-ai 4.9.119-BPI-M4-Kernel #1 SMP PREEMPT Mon May 18 10:41:36 HKT 2020 aarch64 aarch64 aarch64 GNU/Linux

리눅스 배포판 버전 확인

pi@bpi-iot-ros-ai:~$ grep . /etc/*-release
/etc/armbian-image-release:# PLEASE DO NOT EDIT THIS FILE
/etc/armbian-image-release:BOARD=bananapim64
/etc/armbian-image-release:BOARD_NAME="Banana Pi M64"
/etc/armbian-image-release:BOARDFAMILY=sun50iw1
/etc/armbian-image-release:VERSION=5.41
/etc/armbian-image-release:LINUXFAMILY=pine64
/etc/armbian-image-release:BRANCH=default
/etc/armbian-image-release:ARCH=arm64
/etc/armbian-image-release:IMAGE_TYPE=user-built
/etc/armbian-image-release:BOARD_TYPE=csc
/etc/armbian-image-release:INITRD_ARCH=arm
/etc/armbian-image-release:KERNEL_IMAGE_TYPE=Image
/etc/lsb-release:DISTRIB_ID=Ubuntu
/etc/lsb-release:DISTRIB_RELEASE=18.04
/etc/lsb-release:DISTRIB_CODENAME=bionic
/etc/lsb-release:DISTRIB_DESCRIPTION="Ubuntu 18.04.4 LTS"
/etc/os-release:NAME="Ubuntu"
/etc/os-release:VERSION="18.04.4 LTS (Bionic Beaver)"
/etc/os-release:ID=ubuntu
/etc/os-release:ID_LIKE=debian
/etc/os-release:PRETTY_NAME="Ubuntu 18.04.4 LTS"
/etc/os-release:VERSION_ID="18.04"
/etc/os-release:HOME_URL="https://www.ubuntu.com/"
/etc/os-release:SUPPORT_URL="https://help.ubuntu.com/"
/etc/os-release:BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
/etc/os-release:PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
/etc/os-release:VERSION_CODENAME=bionic
/etc/os-release:UBUNTU_CODENAME=bionic

dmesg 확인

pi@bpi-iot-ros-ai:~$ dmesg | grep pci
[    2.204941] [RTD139x PCIE] 98060000.pcie: PCIE host driver initial begin.
[    2.204973] [RTD139x PCIE] 98060000.pcie: PCIE Debug Mode off
[    2.441801] [RTD139x PCIE] 98060000.pcie: PCIE device has link down in slot 2
[    2.441833] [RTD139x PCIE] 98060000.pcie: rtk_pcie_139x_hw_initial fail
[    2.441886] [RTD139x PCIE]: probe of 98060000.pcie failed with error -22
[    4.922306] ehci-pci: EHCI PCI platform driver
[    4.922978] ohci-pci: OHCI PCI platform driver

블럭장치 확인

확장 드라이브 설치 전

pi@bpi-iot-ros-ai:~$ lsblk
NAME         MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
mmcblk0      179:0    0  7.3G  0 disk 
├─mmcblk0p1  179:1    0  256M  0 part /media/pi/BPI-BOOT
└─mmcblk0p2  179:2    0  6.8G  0 part /
mmcblk0boot0 179:8    0    4M  1 disk 
mmcblk0boot1 179:16   0    4M  1 disk 
mmcblk0rpmb  179:24   0  512K  0 disk

확장 드라이브 설치 후

pi@bpi-iot-ros-ai:~$ lsblk
NAME         MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda            8:0    1 29.7G  0 disk 
└─sda1         8:1    1 29.7G  0 part /media/pi/3665-3463
mmcblk0      179:0    0  7.3G  0 disk 
├─mmcblk0p1  179:1    0  256M  0 part /media/pi/BPI-BOOT
└─mmcblk0p2  179:2    0  6.8G  0 part /
mmcblk0boot0 179:8    0    4M  1 disk 
mmcblk0boot1 179:16   0    4M  1 disk 
mmcblk0rpmb  179:24   0  512K  0 disk

USB 정보 확인

확장 드라이브 설치 전

pi@bpi-iot-ros-ai:~$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 0bda:c820 Realtek Semiconductor Corp. 
Bus 001 Device 002: ID 1a40:0201 Terminus Technology Inc. FE 2.1 7-port Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

확장 드라이브 설치 후

pi@bpi-iot-ros-ai:~$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 005: ID 0bda:c820 Realtek Semiconductor Corp. 
Bus 001 Device 003: ID 05e3:0751 Genesys Logic, Inc. 
Bus 001 Device 002: ID 1a40:0201 Terminus Technology Inc. FE 2.1 7-port Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

fdisk 확인

pi@bpi-iot-ros-ai:~$ sudo fdisk -l
 
... 생략 ...
 
Disk /dev/sda: 29.7 GiB, 31914983424 bytes, 62333952 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000
 
Device     Boot Start      End  Sectors  Size Id Type
/dev/sda1        8192 62333951 62325760 29.7G  c W95 FAT32 (LBA)

추가된 디스트의 파티션을 만들고 mount 하기

디스크 확인

pi@bpi-iot-ros-ai:~$ sudo fdisk -l | grep '^Disk'
Disk /dev/ram0: 4 MiB, 4194304 bytes, 8192 sectors
Disk /dev/ram1: 4 MiB, 4194304 bytes, 8192 sectors
Disk /dev/ram2: 4 MiB, 4194304 bytes, 8192 sectors
Disk /dev/ram3: 4 MiB, 4194304 bytes, 8192 sectors
Disk /dev/ram4: 4 MiB, 4194304 bytes, 8192 sectors
Disk /dev/ram5: 4 MiB, 4194304 bytes, 8192 sectors
Disk /dev/ram6: 4 MiB, 4194304 bytes, 8192 sectors
Disk /dev/ram7: 4 MiB, 4194304 bytes, 8192 sectors
Disk /dev/ram8: 4 MiB, 4194304 bytes, 8192 sectors
Disk /dev/ram9: 4 MiB, 4194304 bytes, 8192 sectors
Disk /dev/ram10: 4 MiB, 4194304 bytes, 8192 sectors
Disk /dev/ram11: 4 MiB, 4194304 bytes, 8192 sectors
Disk /dev/ram12: 4 MiB, 4194304 bytes, 8192 sectors
Disk /dev/ram13: 4 MiB, 4194304 bytes, 8192 sectors
Disk /dev/ram14: 4 MiB, 4194304 bytes, 8192 sectors
Disk /dev/ram15: 4 MiB, 4194304 bytes, 8192 sectors
Disk /dev/mmcblk0: 7.3 GiB, 7818182656 bytes, 15269888 sectors
Disklabel type: dos
Disk identifier: 0xc69bd2d7
Disk /dev/mmcblk0boot1: 4 MiB, 4194304 bytes, 8192 sectors
Disk /dev/mmcblk0boot0: 4 MiB, 4194304 bytes, 8192 sectors
Disk /dev/sda: 29.7 GiB, 31914983424 bytes, 62333952 sectors
Disklabel type: dos
Disk identifier: 0x00000000

기존 파티션을 삭제하고 새로 파티션 생성

pi@bpi-iot-ros-ai:~$ sudo fdisk /dev/sda
 
Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
 
 
Command (m for help): p
Disk /dev/sda: 29.7 GiB, 31914983424 bytes, 62333952 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000
 
Device     Boot Start      End  Sectors  Size Id Type
/dev/sda1        8192 62333951 62325760 29.7G  c W95 FAT32 (LBA)
 
Command (m for help): d
Selected partition 1
Partition 1 has been deleted.
 
Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-62333951, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-62333951, default 62333951): 
 
Created a new partition 1 of type 'Linux' and of size 29.7 GiB.
 
Command (m for help): w
The partition table has been altered.
Failed to remove partition 1 from system: Device or resource busy
Failed to add partition 1 to system: Device or resource busy
 
The kernel still uses the old partitions. The new table will be used at the next reboot. 
Syncing disks.

재부팅

pi@bpi-iot-ros-ai:/sd_disk$ sudo shutdown -r now

디스크 format

pi@bpi-iot-ros-ai:~$ sudo mkfs.ext4 /dev/sda1
mke2fs 1.44.1 (24-Mar-2018)
Creating filesystem with 7791488 4k blocks and 1949696 inodes
Filesystem UUID: ca144d66-31b2-4bac-ac7d-db0d6ccb0075
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000
 
Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information:        
done

mount 할 디렉토리 생성

pi@bpi-iot-ros-ai:~$ sudo mkdir /sd_disk

mount

pi@bpi-iot-ros-ai:~$ sudo mount /dev/sda1 /sd_disk

확인

pi@bpi-iot-ros-ai:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            320M     0  320M   0% /dev
tmpfs            68M  6.0M   63M   9% /run
/dev/mmcblk0p2  6.7G  5.4G  992M  85% /
tmpfs           340M     0  340M   0% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           340M     0  340M   0% /sys/fs/cgroup
tmpfs           340M  4.0K  340M   1% /tmp
tmpfs            68M   16K   68M   1% /run/user/1000
overlaid         68M   16K   68M   1% /run/user/1000/pi-chromium
/dev/sda1        30G  128K   30G   1% /sd_disk
/dev/mmcblk0p1  256M   38M  218M  15% /media/pi/BPI-BOOT

자동 mount

UUID 확인

pi@bpi-iot-ros-ai:~$ sudo blkid
/dev/mmcblk0: PTUUID="c69bd2d7" PTTYPE="dos"
/dev/mmcblk0p1: SEC_TYPE="msdos" LABEL="BPI-BOOT" UUID="D0B7-DA68" TYPE="vfat" PARTUUID="c69bd2d7-01"
/dev/mmcblk0p2: LABEL="BPI-ROOT" UUID="f28d8061-d9a4-495b-96f0-c3e5233eaa1d" TYPE="ext4" PARTUUID="c69bd2d7-02"
/dev/sda1: UUID="ca144d66-31b2-4bac-ac7d-db0d6ccb0075" TYPE="ext4"

fstab 파일에 파티션 추가

pi@bpi-iot-ros-ai:~$ sudo vi /etc/fstab

 

# 파티션 추가 
UUID=ca144d66-31b2-4bac-ac7d-db0d6ccb0075 /sd_disk ext4 defaults 0 0

댓글을 달아 주세요

리눅스 정보 확인

CPU 정보 확인

$ cat /proc/cpuinfo
processor       : 0
BogoMIPS        : 54.00
Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x0
CPU part        : 0xd03
CPU revision    : 4
 
... 생략 ...

nstruction set architecture (ISA)

$ uname -i
aarch64

커널에 대한 정보

$ uname -a
Linux bpi-iot-ros-ai 4.9.119-BPI-M4-Kernel #1 SMP PREEMPT Mon May 18 10:41:36 HKT 2020 aarch64 aarch64 aarch64 GNU/Linux

OS버전에 대한 정보

$ cat /etc/issue
Ubuntu 18.04.4 LTS \n \l

논리 코어 수 확인

$ grep -c processor /proc/cpuinfo
4

메모리, swap 사이즈 확인

$ free -h
'              total        used        free      shared  buff/cache   available
Mem:           679M        273M        161M         21M        245M        270M
Swap:          255M          0B        255M

Tensorflow 설치된 Linux 이미지 eMMC에 설치

$ sudo bpi-copy 2020-05-18-ubuntu-18.04-mate-desktop-bpi-m4-aarch64-sd-emmc_tensorflow-2.2.0.img.zip 
SRC=2020-05-18-ubuntu-18.04-mate-desktop-bpi-m4-aarch64-sd-emmc_tensorflow-2.2.0.img.zip
DST=
COPYMODE=imagetodisk
imagetodisk
bpi-copy(v1.3.4(github)), bananapi image & disk tools

Usage: bpi-copy [OPTIONS]...
       bpi-copy [ --help | -v | --version ]
       bpi-copy IMGFILE
       bpi-copy IMGDIR
       bpi-copy IMGFILE DEVICE
       bpi-copy DEVICE IMGFILE

Warning: Try to write 2020-05-18-ubuntu-18.04-mate-desktop-bpi-m4-aarch64-sd-emmc_tensorflow-2.2.0.img.zip to BOOTDISK /dev/mmcblk1
==============================================================
Sat Jun  6 22:43:02 CST 2020
*** start COPY (blue led on ) .....
INFO: /dev/mmcblk1 : SD/eMMC !!
umount device: /dev/mmcblk1
umount /dev/mmcblk1p2
umount /dev/mmcblk1p1
==============================================================
IMGFILE=2020-05-18-ubuntu-18.04-mate-desktop-bpi-m4-aarch64-sd-emmc_tensorflow-2.2.0.img.zip
==============================================================
zip
7.28GiB 0:06:07 [20.3MiB/s] [                                                         <=>                                 ]
0+108268 records in
0+108268 records out
***  end  COPY (blue led off) .....
Sat Jun  6 22:49:11 CST 2020
==============================================================
RUNTIME 6:9
OK!! You can remove the BOOTDISK /dev/mmcblk1 now!!

Python, pip 버전확인

$ python3 --version
Python 3.7.7
$ pip3 --version
pip 20.1.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

Tensorflow 버전확인

$ python3
Python 3.7.7 (default, Jun  6 2020, 12:24:50) 
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> tf.__version__
'2.2.0'


댓글을 달아 주세요

BPI-M4 : eMMC Linux Images SD메모리에 복사

OS/Banana Pi /BPI-Bit 2020. 6. 6. 22:36 Posted by 파란크리스마스

출처

$ sudo bpi-copy /dev/mmcblk1 2020-05-18-ubuntu-18.04-mate-desktop-bpi-m4-aarch64-sd-emmc_tensorflow-2.2.0.img.zip
SRC=/dev/mmcblk1
DST=2020-05-18-ubuntu-18.04-mate-desktop-bpi-m4-aarch64-sd-emmc_tensorflow-2.2.0.img.zip
COPYMODE=disktoimage
disktoimage
bpi-copy(v1.3.4(github)), bananapi image & disk tools

Usage: bpi-copy [OPTIONS]...
       bpi-copy [ --help | -v | --version ]
       bpi-copy IMGFILE
       bpi-copy IMGDIR
       bpi-copy IMGFILE DEVICE
       bpi-copy DEVICE IMGFILE

Info: Try to write /dev/mmcblk1 to BOOTDISK 2020-05-18-ubuntu-18.04-mate-desktop-bpi-m4-aarch64-sd-emmc_tensorflow-2.2.0.img.zip
==============================================================
Sat Jun  6 20:56:12 CST 2020
INFO: /dev/mmcblk1 : SD/eMMC !!
umount device: /dev/mmcblk1
==============================================================
IMGFILE=2020-05-18-ubuntu-18.04-mate-desktop-bpi-m4-aarch64-sd-emmc_tensorflow-2.2.0.img.zip
==============================================================
zip
dd if=/dev/mmcblk1 bs=1M | pv | zip 2020-05-18-ubuntu-18.04-mate-desktop-bpi-m4-aarch64-sd-emmc_tensorflow-2.2.0.img.zip -
  adding: -25.2MiB 0:00:01 [25.2MiB/s] [ <=>                                                                               7456+0 records in24.6MiB/s] [            <=>                                                                              ]
7456+0 records out
7.28GiB 0:21:47 [5.70MiB/s] [              <=>                                                                            ]
7818182656 bytes (7.8 GB, 7.3 GiB) copied, 1307.85 s, 6.0 MB/s
 (deflated 66%)
Sat Jun  6 21:18:02 CST 2020
==============================================================
RUNTIME 21:50
OK!! You can remove the BOOTDISK /dev/mmcblk1 now!!

댓글을 달아 주세요

BPI-M4 : TensorFlow 2.2.0 (aarch64) 설치 (Python 3.7)

OS/Banana Pi /BPI-Bit 2020. 6. 6. 09:16 Posted by 파란크리스마스

출처

리눅스 정보 확인

CPU 정보 확인

$ cat /proc/cpuinfo
processor       : 0
BogoMIPS        : 54.00
Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x0
CPU part        : 0xd03
CPU revision    : 4
 
... 생략 ...
i

nstruction set architecture (ISA)

$ uname -i
aarch64

커널에 대한 정보

$ uname -a
Linux bpi-iot-ros-ai 4.9.119-BPI-M4-Kernel #1 SMP PREEMPT Mon May 18 10:41:36 HKT 2020 aarch64 aarch64 aarch64 GNU/Linux

OS버전에 대한 정보

$ cat /etc/issue
Ubuntu 18.04.4 LTS \n \l

논리 코어 수 확인

$ grep -c processor /proc/cpuinfo
4

메모리, swap 사이즈 확인

$ free -h
              total        used        free      shared  buff/cache   available
Mem:           1.5G        236M        533M         33M        802M        1.0G
Swap:            0B          0B          0B

관련 라이브러리 설치, pip3 설치 확인

$ sudo apt update
$ sudo apt install gfortran libopenblas-dev liblapack-dev libhdf5-dev
$ pip3 --version
pip 20.1.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

TensorFlow 2.2.0 패키지 설치

TensorFlow 2.2.0 패키지 다운로드

$ wget https://github.com/lhelontra/tensorflow-on-arm/releases/download/v2.2.0/tensorflow-2.2.0-cp37-none-linux_aarch64.whl

tensorflow 2.2.0 파이썬 페키지 설치

$ export TMPDIR=/var/tmp
$ pip3 install tensorflow-2.2.0-cp37-none-linux_aarch64.whl
Defaulting to user installation because normal site-packages is not writeable
Processing ./tensorflow-2.2.0-cp37-none-linux_aarch64.whl
Requirement already satisfied: opt-einsum>=2.3.2 in ./.local/lib/python3.7/site-packages (from tensorflow==2.2.0) (3.2.1)
Requirement already satisfied: numpy<2.0,>=1.16.0 in ./.local/lib/python3.7/site-packages (from tensorflow==2.2.0) (1.18.5)
Requirement already satisfied: grpcio>=1.8.6 in ./.local/lib/python3.7/site-packages (from tensorflow==2.2.0) (1.29.0)
Requirement already satisfied: termcolor>=1.1.0 in ./.local/lib/python3.7/site-packages (from tensorflow==2.2.0) (1.1.0)
Requirement already satisfied: tensorflow-estimator<2.3.0,>=2.2.0 in ./.local/lib/python3.7/site-packages (from tensorflow==2.2.0) (2.2.0)
Requirement already satisfied: h5py<2.11.0,>=2.10.0 in ./.local/lib/python3.7/site-packages (from tensorflow==2.2.0) (2.10.0)
Requirement already satisfied: wrapt>=1.11.1 in ./.local/lib/python3.7/site-packages (from tensorflow==2.2.0) (1.12.1)
Requirement already satisfied: absl-py>=0.7.0 in ./.local/lib/python3.7/site-packages (from tensorflow==2.2.0) (0.9.0)
Requirement already satisfied: keras-preprocessing>=1.1.0 in ./.local/lib/python3.7/site-packages (from tensorflow==2.2.0) (1.1.2)
Requirement already satisfied: protobuf>=3.8.0 in ./.local/lib/python3.7/site-packages (from tensorflow==2.2.0) (3.12.2)
Requirement already satisfied: gast==0.3.3 in ./.local/lib/python3.7/site-packages (from tensorflow==2.2.0) (0.3.3)
Requirement already satisfied: astunparse==1.6.3 in ./.local/lib/python3.7/site-packages (from tensorflow==2.2.0) (1.6.3)
Requirement already satisfied: scipy==1.4.1; python_version >= "3" in ./.local/lib/python3.7/site-packages (from tensorflow==2.2.0) (1.4.1)
Requirement already satisfied: tensorboard<2.3.0,>=2.2.0 in ./.local/lib/python3.7/site-packages (from tensorflow==2.2.0) (2.2.2)
Requirement already satisfied: wheel>=0.26; python_version >= "3" in /usr/local/lib/python3.7/site-packages (from tensorflow==2.2.0) (0.34.2)
Requirement already satisfied: google-pasta>=0.1.8 in ./.local/lib/python3.7/site-packages (from tensorflow==2.2.0) (0.2.0)
Requirement already satisfied: six>=1.12.0 in ./.local/lib/python3.7/site-packages (from tensorflow==2.2.0) (1.15.0)
Requirement already satisfied: setuptools in /usr/local/lib/python3.7/site-packages (from protobuf>=3.8.0->tensorflow==2.2.0) (47.1.1)
Requirement already satisfied: google-auth<2,>=1.6.3 in ./.local/lib/python3.7/site-packages (from tensorboard<2.3.0,>=2.2.0->tensorflow==2.2.0) (1.16.1)
Requirement already satisfied: tensorboard-plugin-wit>=1.6.0 in ./.local/lib/python3.7/site-packages (from tensorboard<2.3.0,>=2.2.0->tensorflow==2.2.0) (1.6.0.post3)
Requirement already satisfied: werkzeug>=0.11.15 in ./.local/lib/python3.7/site-packages (from tensorboard<2.3.0,>=2.2.0->tensorflow==2.2.0) (1.0.1)
Requirement already satisfied: requests<3,>=2.21.0 in ./.local/lib/python3.7/site-packages (from tensorboard<2.3.0,>=2.2.0->tensorflow==2.2.0) (2.23.0)
Requirement already satisfied: markdown>=2.6.8 in ./.local/lib/python3.7/site-packages (from tensorboard<2.3.0,>=2.2.0->tensorflow==2.2.0) (3.2.2)
Requirement already satisfied: google-auth-oauthlib<0.5,>=0.4.1 in ./.local/lib/python3.7/site-packages (from tensorboard<2.3.0,>=2.2.0->tensorflow==2.2.0) (0.4.1)
Requirement already satisfied: rsa<4.1,>=3.1.4 in ./.local/lib/python3.7/site-packages (from google-auth<2,>=1.6.3->tensorboard<2.3.0,>=2.2.0->tensorflow==2.2.0) (4.0)
Requirement already satisfied: cachetools<5.0,>=2.0.0 in ./.local/lib/python3.7/site-packages (from google-auth<2,>=1.6.3->tensorboard<2.3.0,>=2.2.0->tensorflow==2.2.0) (4.1.0)
Requirement already satisfied: pyasn1-modules>=0.2.1 in ./.local/lib/python3.7/site-packages (from google-auth<2,>=1.6.3->tensorboard<2.3.0,>=2.2.0->tensorflow==2.2.0) (0.2.8)
Requirement already satisfied: certifi>=2017.4.17 in ./.local/lib/python3.7/site-packages (from requests<3,>=2.21.0->tensorboard<2.3.0,>=2.2.0->tensorflow==2.2.0) (2020.4.5.1)
Requirement already satisfied: idna<3,>=2.5 in ./.local/lib/python3.7/site-packages (from requests<3,>=2.21.0->tensorboard<2.3.0,>=2.2.0->tensorflow==2.2.0) (2.9)
Requirement already satisfied: chardet<4,>=3.0.2 in ./.local/lib/python3.7/site-packages (from requests<3,>=2.21.0->tensorboard<2.3.0,>=2.2.0->tensorflow==2.2.0) (3.0.4)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in ./.local/lib/python3.7/site-packages (from requests<3,>=2.21.0->tensorboard<2.3.0,>=2.2.0->tensorflow==2.2.0) (1.25.9)
Requirement already satisfied: importlib-metadata; python_version < "3.8" in ./.local/lib/python3.7/site-packages (from markdown>=2.6.8->tensorboard<2.3.0,>=2.2.0->tensorflow==2.2.0) (1.6.1)
Requirement already satisfied: requests-oauthlib>=0.7.0 in ./.local/lib/python3.7/site-packages (from google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.3.0,>=2.2.0->tensorflow==2.2.0) (1.3.0)
Requirement already satisfied: pyasn1>=0.1.3 in ./.local/lib/python3.7/site-packages (from rsa<4.1,>=3.1.4->google-auth<2,>=1.6.3->tensorboard<2.3.0,>=2.2.0->tensorflow==2.2.0) (0.4.8)
Requirement already satisfied: zipp>=0.5 in ./.local/lib/python3.7/site-packages (from importlib-metadata; python_version < "3.8"->markdown>=2.6.8->tensorboard<2.3.0,>=2.2.0->tensorflow==2.2.0) (3.1.0)
Requirement already satisfied: oauthlib>=3.0.0 in ./.local/lib/python3.7/site-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.3.0,>=2.2.0->tensorflow==2.2.0) (3.1.0)
Installing collected packages: tensorflow
Successfully installed tensorflow-2.2.0

버전 확인

$ python3
Python 3.7.7 (default, Jun  6 2020, 12:24:50) 
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> tf.__version__
'2.2.0'

댓글을 달아 주세요

출처

리눅스 정보 확인

CPU 정보 확인

$ cat /proc/cpuinfo
processor       : 0
BogoMIPS        : 54.00
Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x0
CPU part        : 0xd03
CPU revision    : 4
 
... 생략 ...
i

nstruction set architecture (ISA)

$ uname -i
aarch64

커널에 대한 정보

$ uname -a
Linux bpi-iot-ros-ai 4.9.119-BPI-M4-Kernel #1 SMP PREEMPT Mon May 18 10:41:36 HKT 2020 aarch64 aarch64 aarch64 GNU/Linux

OS버전에 대한 정보

$ cat /etc/issue
Ubuntu 18.04.4 LTS \n \l

논리 코어 수 확인

$ grep -c processor /proc/cpuinfo
4

메모리, swap 사이즈 확인

$ free -h
              total        used        free      shared  buff/cache   available
Mem:           1.5G        236M        533M         33M        802M        1.0G
Swap:            0B          0B          0B

TensorFlow C, C++ 라이브러리 설치

TensorFlow 라이브러리 다운로드

$ wget http://1.229.109.140:3562/tensorflow/tensorflow-2.2.0.aarch64/libtensorflow.tar.gz

TensorFlow 라이브러리 설치

$ sudo tar -C /usr/local -xzf libtensorflow.tar.gz

Linker 설정

$ sudo ldconfig

예제 hello.c

#include <stdio.h>
#include <tensorflow/c/c_api.h>

int main() {
  printf("TensorFlow C library version %s\n", TF_Version());
  return 0;
}

예제 컴파일

$ gcc hello.c -ltensorflow -o hello

예제 실행

$ ./hello
TensorFlow C library version 2.2.0

댓글을 달아 주세요

BPI-M4 : TensorFlow 2.1.0 (aarch64) 설치 (Python 3.7)

OS/Banana Pi /BPI-Bit 2020. 4. 23. 01:33 Posted by 파란크리스마스

출처

리눅스 정보 확인

CPU 정보 확인

$ 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
 
 ... 생략 ...
 
Hardware        : Allwinnersun50iw2Family
Revision        : 0000
Serial          : 0000000000000000

instruction set architecture (ISA)

$ uname -i
aarch64

커널에 대한 정보

$ uname -a
Linux NanoPi-NEO2-Black 4.14.111 #1 SMP Thu Dec 19 19:12:27 CST 2019 aarch64 aarch64 aarch64 GNU/Linux

OS버전에 대한 정보

$ cat /etc/issue
Ubuntu 16.04.6 LTS \n \l

논리 코어 수 확인

$ grep -c processor /proc/cpuinfo
4

swap 사이즈 설정

현재 swap 사이즈 확인

$ free -h
              total        used        free      shared  buff/cache   available
Mem:           1.5G        276M        164M         33M        1.1G        989M
Swap:          255M          0B        255M
$ sudo swapon -s
Filename                                Type            Size    Used    Priority
/var/swap                               file            262140  0       -1

swap 서비스 종료 (swap 설정 파일 수정을 위해서)

$ sudo /sbin/dphys-swapfile swapoff

swap 설정 파일 수정

$ sudo vi /etc/dphys-swapfile

# CONF_SWAPSIZE=100
CONF_SWAPSIZE=1024

swap 서비스 시작

$ sudo rm /var/swap
$ sudo /sbin/dphys-swapfile setup
want /var/swap=1024MByte, generating swapfile ... of 1024MBytes
$ sudo /sbin/dphys-swapfile swapon

현재 swap 사이즈 확인

$ free -h
              total        used        free      shared  buff/cache   available
Mem:           1.5G        277M        431M         24M        862M        980M
Swap:          1.0G          0B        1.0G
$ sudo swapon -s
Filename                                Type            Size    Used    Priority
/var/swap                               file            1048572 0       -1

관련 라이브러리 설치, pip3 설치 확인

$ sudo apt update
$ sudo apt install gfortran libopenblas-dev liblapack-dev libhdf5-dev
$ pip3 --version
pip 20.0.2 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

TensorFlow 2.1.0 패키지 설치

TensorFlow 2.1.0 패키지 다운로드

$ wget http://1.229.109.140:3562/tensorflow/tensorflow-2.1.0.aarch64/tensorflow-2.1.0-cp37-cp37m-linux_aarch64.whl

tensorflow 2.1.0 파이썬 패키지 설치

$ export TMPDIR=/var/tmp
$ pip3 install tensorflow-2.1.0-cp37-cp37m-linux_aarch64.whl
Defaulting to user installation because normal site-packages is not writeable
Processing ./tensorflow-2.1.0-cp37-cp37m-linux_aarch64.whl
Requirement already satisfied: astor>=0.6.0 in ./.local/lib/python3.7/site-packages (from tensorflow==2.1.0) (0.8.1)
Requirement already satisfied: numpy<2.0,>=1.16.0 in ./.local/lib/python3.7/site-packages (from tensorflow==2.1.0) (1.18.4)
Requirement already satisfied: keras-applications>=1.0.8 in ./.local/lib/python3.7/site-packages (from tensorflow==2.1.0) (1.0.8)
Requirement already satisfied: grpcio>=1.8.6 in ./.local/lib/python3.7/site-packages (from tensorflow==2.1.0) (1.29.0)
Requirement already satisfied: protobuf>=3.8.0 in ./.local/lib/python3.7/site-packages (from tensorflow==2.1.0) (3.12.2)
Requirement already satisfied: tensorboard<2.2.0,>=2.1.0 in ./.local/lib/python3.7/site-packages (from tensorflow==2.1.0) (2.1.1)
Requirement already satisfied: absl-py>=0.7.0 in ./.local/lib/python3.7/site-packages (from tensorflow==2.1.0) (0.9.0)
Requirement already satisfied: opt-einsum>=2.3.2 in ./.local/lib/python3.7/site-packages (from tensorflow==2.1.0) (3.2.1)
Requirement already satisfied: six>=1.12.0 in ./.local/lib/python3.7/site-packages (from tensorflow==2.1.0) (1.15.0)
Requirement already satisfied: google-pasta>=0.1.6 in ./.local/lib/python3.7/site-packages (from tensorflow==2.1.0) (0.2.0)
Requirement already satisfied: wrapt>=1.11.1 in ./.local/lib/python3.7/site-packages (from tensorflow==2.1.0) (1.12.1)
Requirement already satisfied: tensorflow-estimator<2.2.0,>=2.1.0rc0 in ./.local/lib/python3.7/site-packages (from tensorflow==2.1.0) (2.1.0)
Requirement already satisfied: termcolor>=1.1.0 in ./.local/lib/python3.7/site-packages (from tensorflow==2.1.0) (1.1.0)
Requirement already satisfied: wheel>=0.26; python_version >= "3" in /usr/local/lib/python3.7/site-packages (from tensorflow==2.1.0) (0.34.2)
Requirement already satisfied: gast==0.2.2 in ./.local/lib/python3.7/site-packages (from tensorflow==2.1.0) (0.2.2)
Requirement already satisfied: keras-preprocessing>=1.1.0 in ./.local/lib/python3.7/site-packages (from tensorflow==2.1.0) (1.1.2)
Requirement already satisfied: scipy==1.4.1; python_version >= "3" in ./.local/lib/python3.7/site-packages (from tensorflow==2.1.0) (1.4.1)
Requirement already satisfied: h5py in ./.local/lib/python3.7/site-packages (from keras-applications>=1.0.8->tensorflow==2.1.0) (2.10.0)
Requirement already satisfied: setuptools in /usr/local/lib/python3.7/site-packages (from protobuf>=3.8.0->tensorflow==2.1.0) (47.1.1)
Requirement already satisfied: werkzeug>=0.11.15 in ./.local/lib/python3.7/site-packages (from tensorboard<2.2.0,>=2.1.0->tensorflow==2.1.0) (1.0.1)
Requirement already satisfied: google-auth-oauthlib<0.5,>=0.4.1 in ./.local/lib/python3.7/site-packages (from tensorboard<2.2.0,>=2.1.0->tensorflow==2.1.0) (0.4.1)
Requirement already satisfied: requests<3,>=2.21.0 in ./.local/lib/python3.7/site-packages (from tensorboard<2.2.0,>=2.1.0->tensorflow==2.1.0) (2.23.0)
Requirement already satisfied: markdown>=2.6.8 in ./.local/lib/python3.7/site-packages (from tensorboard<2.2.0,>=2.1.0->tensorflow==2.1.0) (3.2.2)
Requirement already satisfied: google-auth<2,>=1.6.3 in ./.local/lib/python3.7/site-packages (from tensorboard<2.2.0,>=2.1.0->tensorflow==2.1.0) (1.16.0)
Requirement already satisfied: requests-oauthlib>=0.7.0 in ./.local/lib/python3.7/site-packages (from google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1.0) (1.3.0)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in ./.local/lib/python3.7/site-packages (from requests<3,>=2.21.0->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1.0) (1.25.9)
Requirement already satisfied: chardet<4,>=3.0.2 in ./.local/lib/python3.7/site-packages (from requests<3,>=2.21.0->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1.0) (3.0.4)
Requirement already satisfied: idna<3,>=2.5 in ./.local/lib/python3.7/site-packages (from requests<3,>=2.21.0->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1.0) (2.9)
Requirement already satisfied: certifi>=2017.4.17 in ./.local/lib/python3.7/site-packages (from requests<3,>=2.21.0->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1.0) (2020.4.5.1)
Requirement already satisfied: importlib-metadata; python_version < "3.8" in ./.local/lib/python3.7/site-packages (from markdown>=2.6.8->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1.0) (1.6.0)
Requirement already satisfied: cachetools<5.0,>=2.0.0 in ./.local/lib/python3.7/site-packages (from google-auth<2,>=1.6.3->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1.0) (4.1.0)
Requirement already satisfied: pyasn1-modules>=0.2.1 in ./.local/lib/python3.7/site-packages (from google-auth<2,>=1.6.3->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1.0) (0.2.8)
Requirement already satisfied: rsa<4.1,>=3.1.4 in ./.local/lib/python3.7/site-packages (from google-auth<2,>=1.6.3->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1.0) (4.0)
Requirement already satisfied: oauthlib>=3.0.0 in ./.local/lib/python3.7/site-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1.0) (3.1.0)
Requirement already satisfied: zipp>=0.5 in ./.local/lib/python3.7/site-packages (from importlib-metadata; python_version < "3.8"->markdown>=2.6.8->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1.0) (3.1.0)
Requirement already satisfied: pyasn1<0.5.0,>=0.4.6 in ./.local/lib/python3.7/site-packages (from pyasn1-modules>=0.2.1->google-auth<2,>=1.6.3->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1.0) (0.4.8)
Installing collected packages: tensorflow
Successfully installed tensorflow-2.1.0
WARNING: You are using pip version 20.0.2; however, version 20.1.1 is available.
You should consider upgrading via the '/usr/local/bin/python3 -m pip install --upgrade pip' command.

버전 확인

$ python3
Python 3.7.7 (default, Jun  1 2020, 00:48:31) 
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> tf.__version__
'2.1.0'

댓글을 달아 주세요

출처

리눅스 정보 확인

CPU 정보 확인

$ cat /proc/cpuinfo
processor       : 0
BogoMIPS        : 54.00
Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x0
CPU part        : 0xd03
CPU revision    : 4
 
processor       : 1
BogoMIPS        : 54.00
Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x0
CPU part        : 0xd03
CPU revision    : 4
 
processor       : 2
BogoMIPS        : 54.00
Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x0
CPU part        : 0xd03
CPU revision    : 4
 
processor       : 3
BogoMIPS        : 54.00
Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x0
CPU part        : 0xd03
CPU revision    : 4

instruction set architecture (ISA)

$ uname -i
aarch64

커널에 대한 정보

$ uname -a
Linux bpi-iot-ros-ai 4.9.119-BPI-M4-Kernel #6 SMP PREEMPT Tue Jun 18 10:49:05 CST 2019 aarch64 aarch64 aarch64 GNU/Linux

OS버전에 대한 정보

$ cat /etc/issue
Ubuntu 16.04.5 LTS \n \l

논리 코어 수 확인

$ grep -c processor /proc/cpuinfo
4

TensorFlow C, C++ 라이브러리 설치

TensorFlow 라이브러리 다운로드

$ wget http://1.229.109.140:3562/tensorflow/tensorflow-2.1.0.aarch64/libtensorflow.tar.gz

TensorFlow 라이브러리 설치

$ sudo tar -C /usr/local -xzf libtensorflow.tar.gz

Linker 설정

$ sudo ldconfig

예제 hello.c

#include <stdio.h>
#include <tensorflow/c/c_api.h>

int main() {
  printf("TensorFlow C library version %s\n", TF_Version());
  return 0;
}

예제 컴파일

$ gcc hello.c -ltensorflow -o hello

예제 실행

$ ./hello
TensorFlow C library version 2.1.0
TAG BPI-M4

댓글을 달아 주세요

BPI-M4 : Python 3.7 수동 설치

OS/Banana Pi /BPI-Bit 2020. 4. 13. 23:04 Posted by 파란크리스마스

출처

Python 3.6 제거 (옵션)

Python 3 설치된 패키지 확인

$ aptitude search '~i' | grep python

Python 3.6 제거

$ sudo apt remove python3 python3-minimal python3.6 python3.6-minimal libpython3.6 libpython3.6-minimal
$ sudo apt autoremove

Python 3.7 설치

Python을 설치하기 전에 Python을 빌드하는 데 필요한 필수 패키지를 설치

$ sudo apt update
$ sudo apt install -y --no-install-recommends libbluetooth-dev tk-dev uuid-dev wget ca-certificates gnupg2 dirmngr gcc build-essential wget zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev

Python 소스 다운로드

$ PYTHON_VERSION=3.7.7
$ wget "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz"

Python 빌드

$ tar -xvf Python-$PYTHON_VERSION.tar.xz 
$ cd Python-$PYTHON_VERSION/
$ sudo ./configure --enable-loadable-sqlite-extensions \
  --enable-optimizations \
  --enable-option-checking=fatal \
  --enable-shared \
  --with-system-expat \
  --with-system-ffi \
  --without-ensurepip
$ sudo make -j 2 PROFILE_TASK='-m test.regrtest --pgo \
  test_array test_base64 test_binascii test_binhex test_binop test_bytes test_c_locale_coercion \
  test_class test_cmath test_codecs test_compile test_complex test_csv test_decimal test_dict \
  test_float test_fstring test_hashlib test_io test_iter test_json test_long test_math test_memoryview \
  test_pickle test_re test_set test_slice test_struct test_threading test_time test_traceback test_unicode'
 
 ... 생략 ...
 
Python build finished successfully!
The necessary bits to build these optional modules were not found:
_bz2                  _lzma                 _sqlite3           
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
 
 
The following modules found by detect_modules() in setup.py, have been
built by the Makefile instead, as configured by the Setup files:
_abc                  atexit                pwd                
time                                                           
 
 
Failed to build these modules:
_curses               _curses_panel                            
 
running build_scripts
copying and adjusting /home/pi/Python-3.7.7/Tools/scripts/pydoc3 -> build/scripts-3.7
copying and adjusting /home/pi/Python-3.7.7/Tools/scripts/idle3 -> build/scripts-3.7
copying and adjusting /home/pi/Python-3.7.7/Tools/scripts/2to3 -> build/scripts-3.7
copying and adjusting /home/pi/Python-3.7.7/Tools/scripts/pyvenv -> build/scripts-3.7
changing mode of build/scripts-3.7/pydoc3 from 644 to 755
changing mode of build/scripts-3.7/idle3 from 644 to 755
changing mode of build/scripts-3.7/2to3 from 644 to 755
changing mode of build/scripts-3.7/pyvenv from 644 to 755
renaming build/scripts-3.7/pydoc3 to build/scripts-3.7/pydoc3.7
renaming build/scripts-3.7/idle3 to build/scripts-3.7/idle3.7
renaming build/scripts-3.7/2to3 to build/scripts-3.7/2to3-3.7
renaming build/scripts-3.7/pyvenv to build/scripts-3.7/pyvenv-3.7
make[1]: Leaving directory '/home/pi/Python-3.7.7'

Python 3.7 설치

$ sudo make install
$ sudo ldconfig
$ sudo find /usr/local -depth \
  \( \( -type d -a \( -name test -o -name tests -o -name idle_test \) \) \
  -o \( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \) -exec rm -rf '{}' +

pip 설치

$ cd ~  
$ wget -O get-pip.py "https://github.com/pypa/get-pip/raw/d59197a3c169cef378a22428a3fa99d33e080a5d/get-pip.py"
$ sudo python3 get-pip.py --disable-pip-version-check --no-cache-dir "pip==20.1.1"

설치 확인

$ python3 --version
Python 3.7.7
$ pip3 --version
pip 20.1.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

댓글을 달아 주세요

BPI-M2 ZERO : TensorFlow 2.1.0 설치 (Python 3.7)

OS/Banana Pi /BPI-Bit 2020. 4. 11. 10:42 Posted by 파란크리스마스

출처

리눅스 정보 확인

CPU 정보 확인

$ cat /proc/cpuinfo
Processor       : ARMv7 Processor rev 5 (v7l)
processor       : 0
BogoMIPS        : 1142.85
 
processor       : 1
BogoMIPS        : 1142.85
 
processor       : 2
BogoMIPS        : 1142.85
 
processor       : 3
BogoMIPS        : 1142.85
 
Features        : swp half thumb fastmult vfp edsp thumbee neon vfpv3 tls vfpv4 idiva idivt 
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xc07
CPU revision    : 5
 
Hardware        : sun8i
Revision        : 0000
Serial          : 44007867890c5817090e

커널에 대한 정보

$ uname -a
Linux bananapim2zero 3.4.113-sun8i #2 SMP PREEMPT Wed May 8 15:09:43 CEST 2019 armv7l armv7l armv7l GNU/Linux

OS버전에 대한 정보

$ cat /etc/issue
Ubuntu 16.04.6 LTS \n \l

논리 코어 수 확인

$ grep -c processor /proc/cpuinfo
4

libstdc++6 라이브러리 업데이트

오류 메시지 ImportError: /usr/lib/arm-linux-gnueabihf/libstdc++.so.6: version `GLIBCXX_3.4.22' not found (required by /home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/_pywrap_tensorflow_internal.so)

libstdc++.so.6 라이브러리가 지원하는 버전 확인

$ strings /usr/lib/arm-linux-gnueabihf/libstdc++.so.6 | grep GLIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_3.4.20
GLIBCXX_3.4.21
GLIBCXX_DEBUG_MESSAGE_LENGTH

libstdc++6 업데이트

$ sudo apt-get install software-properties-common
$ sudo add-apt-repository ppa:ubuntu-toolchain-r/test
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get upgrade libstdc++6

libstdc++.so.6 라이브러리가 지원하는 버전 확인

$ strings /usr/lib/arm-linux-gnueabihf/libstdc++.so.6 | grep GLIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_3.4.20
GLIBCXX_3.4.21
GLIBCXX_3.4.22
GLIBCXX_3.4.23
GLIBCXX_3.4.24
GLIBCXX_3.4.25
GLIBCXX_3.4.26
GLIBCXX_3.4.27
GLIBCXX_3.4.28
GLIBCXX_DEBUG_MESSAGE_LENGTH

pip3 설치

$ sudo apt update
$ sudo apt install gfortran libopenblas-dev liblapack-dev libhdf5-dev
$ pip3 --version
pip 20.0.2 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

파이썬 라이브러리 설치

$ sudo pip3 install setuptools wheel
$ pip3 install numpy
$ sudo pip3 install h5py

swap 사이즈 설정

현재 swap 사이즈 확인

$ free -h
              total        used        free      shared  buff/cache   available
Mem:           495M         85M        337M        524K         72M        388M
Swap:          247M         96M        151M
$ sudo swapon -s
Filename                                Type            Size    Used    Priority
/dev/zram0                              partition       63376   24648   5
/dev/zram1                              partition       63376   24616   5
/dev/zram2                              partition       63376   24584   5
/dev/zram3                              partition       63376   24544   5
$ sudo swapoff /dev/zram0
$ sudo swapoff /dev/zram1
$ sudo swapoff /dev/zram2
$ sudo swapoff /dev/zram3
$ sudo zramctl --reset /dev/zram0
$ sudo zramctl --reset /dev/zram1
$ sudo zramctl --reset /dev/zram2
$ sudo zramctl --reset /dev/zram3
$ sudo zramctl --find --size 512M
/dev/zram0
$ sudo zramctl --find --size 512M
/dev/zram1
$ sudo zramctl --find --size 512M
/dev/zram2
$ sudo zramctl --find --size 512M
/dev/zram3
$ sudo mkswap /dev/zram0
Setting up swapspace version 1, size = 512 MiB (536866816 bytes)
no label, UUID=e6662e60-e230-4c77-8bf5-fad980fcc8d4
$ sudo mkswap /dev/zram1
Setting up swapspace version 1, size = 512 MiB (536866816 bytes)
no label, UUID=3047af26-0e95-4da6-99de-7f27b6bacc1f
$ sudo mkswap /dev/zram2
Setting up swapspace version 1, size = 512 MiB (536866816 bytes)
no label, UUID=0777059c-8ec4-4db5-833c-d4a12204f2a4
$ sudo mkswap /dev/zram3
Setting up swapspace version 1, size = 512 MiB (536866816 bytes)
no label, UUID=e29b5ab6-9b7c-4298-a252-5492183d3c05
$ sudo swapon /dev/zram0
$ sudo swapon /dev/zram1
$ sudo swapon /dev/zram2
$ sudo swapon /dev/zram3
$ free -h
              total        used        free      shared  buff/cache   available
Mem:           495M        129M        283M        6.5M         82M        338M
Swap:          2.0G          0B        2.0G
$ sudo swapon -s
Filename                                Type            Size    Used    Priority
/dev/zram0                              partition       524284  0       -1
/dev/zram1                              partition       524284  0       -2
/dev/zram2                              partition       524284  0       -3
/dev/zram3                              partition       524284  0       -4

TensorFlow 2.1.0 패키지 설치

TensorFlow 2.1.0 패키지 다운로드

$ wget http://1.229.109.140:3562/tensorflow/tensorflow-2.1.0/tensorflow-2.1.0-cp37-none-linux_armv7l.whl

tensorflow 2.1.0 파이썬 페키지 설치

$ export TMPDIR=/var/tmp
$ pip3 install tensorflow-2.1.0-cp37-none-linux_armv7l.whl
 
 ... 생략 ...
 
Successfully built wrapt gast grpcio absl-py scipy termcolor
Installing collected packages: google-pasta, tensorflow-estimator, protobuf, wrapt, absl-py, idna, urllib3, certifi, chardet, requests, markdown, werkzeug, cachetools, pyasn1, pyasn1-modules, rsa, google-auth, grpcio, oauthlib, requests-oauthlib, google-auth-oauthlib, tensorboard, gast, keras-applications, astor, scipy, opt-einsum, termcolor, keras-preprocessing, tensorflow
Successfully installed absl-py-0.9.0 astor-0.8.1 cachetools-4.1.0 certifi-2020.4.5.1 chardet-3.0.4 gast-0.2.2 google-auth-1.13.1 google-auth-oauthlib-0.4.1 google-pasta-0.2.0 grpcio-1.28.1 idna-2.9 keras-applications-1.0.8 keras-preprocessing-1.1.0 markdown-3.2.1 oauthlib-3.1.0 opt-einsum-3.2.0 protobuf-3.11.3 pyasn1-0.4.8 pyasn1-modules-0.2.8 requests-2.23.0 requests-oauthlib-1.3.0 rsa-4.0 scipy-1.4.1 tensorboard-2.1.1 tensorflow-2.1.0 tensorflow-estimator-2.1.0 termcolor-1.1.0 urllib3-1.25.8 werkzeug-1.0.1 wrapt-1.12.1

버전 확인

$ python3
Python 3.7.7 (default, Apr 10 2020, 05:33:30) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> tf.__version__
'2.1.0'

댓글을 달아 주세요

출처

리눅스 정보 확인

CPU 정보 확인

$ cat /proc/cpuinfo
Processor       : ARMv7 Processor rev 5 (v7l)
processor       : 0
BogoMIPS        : 1142.85
 
processor       : 1
BogoMIPS        : 1142.85
 
processor       : 2
BogoMIPS        : 1142.85
 
processor       : 3
BogoMIPS        : 1142.85
 
Features        : swp half thumb fastmult vfp edsp thumbee neon vfpv3 tls vfpv4 idiva idivt 
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xc07
CPU revision    : 5
 
Hardware        : sun8i
Revision        : 0000
Serial          : 44007867890c5817090e

커널에 대한 정보

$ uname -a
Linux bananapim2zero 3.4.113-sun8i #2 SMP PREEMPT Wed May 8 15:09:43 CEST 2019 armv7l armv7l armv7l GNU/Linux

OS버전에 대한 정보

$ cat /etc/issue
Ubuntu 16.04.6 LTS \n \l

논리 코어 수 확인

$ grep -c processor /proc/cpuinfo
4

libstdc++6 라이브러리 업데이트

오류 메시지 `GLIBCXX_3.4.22' not found

libstdc++.so.6 라이브러리가 지원하는 버전 확인

$ strings /usr/lib/arm-linux-gnueabihf/libstdc++.so.6 | grep GLIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_3.4.20
GLIBCXX_3.4.21
GLIBCXX_DEBUG_MESSAGE_LENGTH

libstdc++6 업데이트

$ sudo apt-get install software-properties-common
$ sudo add-apt-repository ppa:ubuntu-toolchain-r/test
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get upgrade libstdc++6

libstdc++.so.6 라이브러리가 지원하는 버전 확인

$ strings /usr/lib/arm-linux-gnueabihf/libstdc++.so.6 | grep GLIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_3.4.20
GLIBCXX_3.4.21
GLIBCXX_3.4.22
GLIBCXX_3.4.23
GLIBCXX_3.4.24
GLIBCXX_3.4.25
GLIBCXX_3.4.26
GLIBCXX_3.4.27
GLIBCXX_3.4.28
GLIBCXX_DEBUG_MESSAGE_LENGTH

TensorFlow C, C++ 라이브러리 설치

TensorFlow 라이브러리 다운로드

$ wget http://1.229.109.140:3562/tensorflow/tensorflow-2.1.0.armv6l/libtensorflow.tar.gz

TensorFlow 라이브러리 설치

$ sudo tar -C /usr/local -xzf libtensorflow.tar.gz

Linker 설정

$ sudo ldconfig

예제 hello.c

#include <stdio.h>
#include <tensorflow/c/c_api.h>

int main() {
  printf("TensorFlow C library version %s\n", TF_Version());
  return 0;
}

예제 컴파일

$ gcc hello.c -ltensorflow -o hello

예제 실행

$ ./hello
TensorFlow C library version 2.1.0

댓글을 달아 주세요

BPI-M2 ZERO : Tensorflow Lite 2.1 - 빌드

OS/Banana Pi /BPI-Bit 2020. 4. 11. 01:04 Posted by 파란크리스마스

출처

리눅스 정보 확인

HW 정보 확인

$ sudo apt-get install lshw
$ sudo lshw
bananapim2zero            
    description: Computer
    width: 32 bits
  *-core
       description: Motherboard
       physical id: 0
     *-memory
          description: System memory
          physical id: 0
          size: 495MiB
     *-cpu:0
          physical id: 1
          bus info: cpu@0
          size: 1008MHz
          capacity: 1008MHz
          capabilities: cpufreq
     *-cpu:1
          physical id: 2
          bus info: cpu@1
          size: 1008MHz
          capacity: 1008MHz
          capabilities: cpufreq
     *-cpu:2
          physical id: 3
          bus info: cpu@2
          size: 1008MHz
          capacity: 1008MHz
          capabilities: cpufreq
     *-cpu:3
          physical id: 4
          bus info: cpu@3
          size: 1008MHz
          capacity: 1008MHz
          capabilities: swp half thumb fastmult vfp edsp thumbee neon vfpv3 tls vfpv4 idiva idivt cpufreq
  *-usbhost:0
       product: SW USB2.0 'Open' Host Controller (OHCI) Driver
       vendor: Linux 3.4.113-sun8i ohci_hcd
       physical id: 1
       bus info: usb@2
       logical name: usb2
       version: 3.04
       capabilities: usb-1.10
       configuration: driver=hub slots=1 speed=12Mbit/s
  *-usbhost:1
       product: SW USB2.0 'Enhanced' Host Controller (EHCI) Driver
       vendor: Linux 3.4.113-sun8i ehci_hcd
       physical id: 2
       bus info: usb@1
       logical name: usb1
       version: 3.04
       capabilities: usb-2.00
       configuration: driver=hub slots=1 speed=480Mbit/s
     *-usb
          description: USB hub
          product: USB 2.0 Hub
          vendor: Terminus Technology Inc.
          physical id: 1
          bus info: usb@1:1
          version: 1.11
          capabilities: usb-2.00
          configuration: driver=hub maxpower=100mA slots=4 speed=480Mbit/s
        *-usb:0
             description: Keyboard
             product: Smart Control
             vendor: HL 0000 00 00 00 01
             physical id: 1
             bus info: usb@1:1.1
             version: 1.00
             capabilities: usb-1.10
             configuration: driver=usbhid maxpower=200mA speed=12Mbit/s
        *-usb:1
             description: Generic USB device
             product: USB 2.0 10/100M Ethernet Adaptor
             vendor: Kontron (Industrial Computer Source / ICS Advent)
             physical id: 2
             bus info: usb@1:1.2
             version: 1.01
             capabilities: usb-1.10
             configuration: driver=qf9700 maxpower=120mA speed=12Mbit/s
  *-network:0
       description: Wireless interface
       physical id: 3
       logical name: wlan0
       serial: cc:b8:a8:aa:b7:b4
       capabilities: ethernet physical wireless
       configuration: broadcast=yes driver=wl driverversion=0 multicast=yes wireless=IEEE 802.11
  *-network:1
       description: Ethernet interface
       physical id: 4
       logical name: eth0
       serial: 7a:24:59:9a:a1:b8
       size: 10Mbit/s
       capacity: 100Mbit/s
       capabilities: ethernet physical tp mii 10bt 10bt-fd 100bt 100bt-fd autonegotiation
       configuration: autonegotiation=on broadcast=yes driver=sunxi_geth driverversion=SUNXI Gbgit driver V1.1 duplex=half link=no multicast=yes port=MII speed=10Mbit/s
  *-network:2
       description: Ethernet interface
       physical id: 5
       logical name: enx00e04c534458
       serial: 00:e0:4c:53:44:58
       size: 100Mbit/s
       capacity: 100Mbit/s
       capabilities: ethernet physical tp mii 10bt 10bt-fd 100bt 100bt-fd autonegotiation
       configuration: autonegotiation=on broadcast=yes driver=qf9700 driverversion=22-Aug-2005 duplex=full firmware=QF9700 USB Ethernet ip=192.168.0.3 link=yes multicast=yes port=MII speed=100Mbit/s

instruction set architecture (ISA)

$ uname -i
armv7l

swap 사이즈 설정

현재 swap 사이즈 확인

$ free -h
              total        used        free      shared  buff/cache   available
Mem:           495M        129M        136M         19M        228M        324M
Swap:          247M          0B        247M
$ sudo swapon -s
Filename                                Type            Size    Used    Priority
/dev/zram0                              partition       63376   0       5
/dev/zram1                              partition       63376   0       5
/dev/zram2                              partition       63376   0       5
/dev/zram3                              partition       63376   0       5
$ sudo swapoff /dev/zram0
$ sudo swapoff /dev/zram1
$ sudo swapoff /dev/zram2
$ sudo swapoff /dev/zram3
$ sudo zramctl --reset /dev/zram0
$ sudo zramctl --reset /dev/zram1
$ sudo zramctl --reset /dev/zram2
$ sudo zramctl --reset /dev/zram3
$ sudo zramctl --find --size 512M
/dev/zram0
$ sudo zramctl --find --size 512M
/dev/zram1
$ sudo zramctl --find --size 512M
/dev/zram2
$ sudo zramctl --find --size 512M
/dev/zram3
$ sudo mkswap /dev/zram0
Setting up swapspace version 1, size = 512 MiB (536866816 bytes)
no label, UUID=db53f0c1-5ca4-41cb-acae-ba8c61e17827
$ sudo mkswap /dev/zram1
Setting up swapspace version 1, size = 512 MiB (536866816 bytes)
no label, UUID=f2b75b1c-77e6-485d-adfa-df2f3a7abc01
$ sudo mkswap /dev/zram2
Setting up swapspace version 1, size = 512 MiB (536866816 bytes)
no label, UUID=9612064a-508e-4c7f-8f7f-07d1a5cbe79d
$ sudo mkswap /dev/zram3
Setting up swapspace version 1, size = 512 MiB (536866816 bytes)
no label, UUID=cc344046-c130-4f79-9d33-fc0882cf3f6a
$ sudo swapon /dev/zram0
$ sudo swapon /dev/zram1
$ sudo swapon /dev/zram2
$ sudo swapon /dev/zram3
$ free -h
              total        used        free      shared  buff/cache   available
Mem:           495M        134M        132M         19M        228M        319M
Swap:          2.0G          0B        2.0G
$ sudo swapon -s
Filename                                Type            Size    Used    Priority
/dev/zram0                              partition       524284  0       -1
/dev/zram1                              partition       524284  0       -2
/dev/zram2                              partition       524284  0       -3
/dev/zram3                              partition       524284  0       -4

Bazel 설치

출처 : トマト農家のロボット創り Robot creation by tomato farmer: Build Bazel(0.29.0) on Raspberry Pi 4

JDK 설치

$ sudo apt install openjdk-8-jdk

Bazel 다운로드 및 설치

$ mkdir bazel
$ cd bazel
$ wget https://github.com/bazelbuild/bazel/releases/download/0.29.1/bazel-0.29.1-dist.zip
$ unzip bazel-0.29.1-dist.zip
$ sudo env EXTRA_BAZEL_ARGS="--host_javabase=@local_jdk//:jdk" VERBOSE=yes BAZEL_JAVAC_OPTS="-J-Xms384m -J-Xmx1024m" bash ./compile.sh
$ sudo cp output/bazel /usr/local/bin/bazel

Tensorflow Lite 빌드

Tensorflow 소스 다운로드

$ wget https://github.com/tensorflow/tensorflow/archive/v2.1.0.tar.gz
$ tar -zxvf v2.1.0.tar.gz 
$ cd tensorflow-2.1.0/

Tensorflow Lite 빌드

$ tensorflow/lite/tools/make/download_dependencies.sh
tensorflow/lite/tools/make/download_dependencies.sh: line 59: 1: Usage: download_and_extract URL DIR
pi@bananapim2zero:~/tensorflow-2.1.0$ 
$ sed -i "/^EIGEN_URL=/c\EIGEN_URL=\"\$(grep -o 'https://storage.googleapis.com/mirror.tensorflow.org/gitlab.com/libeigen/eigen/.*tar.gz' \"\${BZL_FILE_PATH}\")\"" tensorflow/lite/tools/make/download_dependencies.sh
$ tensorflow/lite/tools/make/download_dependencies.sh

컴파일 옵션 변경

BPI-M2 ZERO 리소스 부족으로 컴파일 오류가 발생하므로 컴파일 옵션 변경

$ vi tensorflow/lite/tools/make/build_lib.sh

-j 옵션값을 4에서 2로 변경

make -j 2 BUILD_WITH_NNAPI=false -C "${TENSORFLOW_DIR}" -f tensorflow/lite/tools/make/Makefile

Tensorflow Lite 빌드

$ sudo tensorflow/lite/tools/make/build_lib.sh 
+ set -e
+++ dirname tensorflow/lite/tools/make/build_lib.sh
++ cd tensorflow/lite/tools/make
++ pwd
+ SCRIPT_DIR=/home/pi/tensorflow-2.1.0/tensorflow/lite/tools/make
+ TENSORFLOW_DIR=/home/pi/tensorflow-2.1.0/tensorflow/lite/tools/make/../../../..
+ make -j 4 BUILD_WITH_NNAPI=false -C /home/pi/tensorflow-2.1.0/tensorflow/lite/tools/make/../../../.. -f tensorflow/lite/tools/make/Makefile
make: Entering directory '/home/pi/tensorflow-2.1.0'

Python 패키지 빌드, 설치

$ sudo apt install swig
$ tensorflow/lite/tools/pip_package/build_pip_package.sh
$ pip3 install /tmp/tflite_pip/python3/dist/tflite_runtime-2.1.0-cp37-cp37m-linux_armv7l.whl
Defaulting to user installation because normal site-packages is not writeable
Processing /tmp/tflite_pip/python3/dist/tflite_runtime-2.1.0-cp37-cp37m-linux_armv7l.whl
Requirement already satisfied: numpy>=1.12.1 in /home/pi/.local/lib/python3.7/site-packages (from tflite-runtime==2.1.0) (1.18.2)
Installing collected packages: tflite-runtime
Successfully installed tflite-runtime-2.1.0

댓글을 달아 주세요