mermaid.initialize({ startOnLoad: true });</script><metacontent="Aron Petau"property=og:site_name><metacontent="Übersetzung: AIRASPI Build Log - Aron Petau"property=og:title><metacontent=https://aron.petau.net/de/project/airaspi-build-log/property=og:url><metacontent="Utilizing an edge TPU to build an edge device for image recognition and object detection"property=og:description><metacontent=https://aron.petau.net/card.pngproperty=og:image><metacontent=de_DEproperty=og:locale><body><headerid=site-nav><nav><ahref=#main-contenttabindex=0> Zum Hauptinhalt springen </a><ul><liid=home><ahref=https://aron.petau.net/de/><iclass=icon></i>Aron Petau</a><liclass=divider><li><ahref=https://aron.petau.net/de/project/>Projekte</a><li><ahref=https://aron.petau.net/de/pages/contact/>Kontakt</a><li><ahref=https://aron.petau.net/de/pages/cv/>Vita</a><li><ahref=https://aron.petau.net/de/pages/about/>Über mich</a><liid=search><buttonclass=circleid=search-toggletitle=Suche><iclass=icon></i></button><liid=language-switcher><detailsclass=closable><summaryclass=circletitle=Sprache><iclass=icon></i></summary><ul><li><ahref=https://aron.petau.net/project/airaspi-build-log/lang=en>English</a></ul></details><liid=theme-switcher><detailsclass=closable><summaryclass=circletitle=Thema><iclass=icon></i></summary><ul><li><buttontitle="Zum hellen Thema wechseln"class=circleid=theme-light><iclass=icon></i></button><li><buttontitle="Zum dunklen Thema wechseln"class=circleid=theme-dark><iclass=icon></i></button><li><buttontitle="Systemthema nutzen"class=circleid=theme-system><iclass=icon></i></button></ul></details><liid=feed><aclass=circlehref=https://aron.petau.net/de/atom.xmltitle=Feed><iclass=icon></i></a><liid=repo><aclass=circlehref=https://forgejo.petau.net/aron/awebsitetitle=Repository><iclass=icon></i></a></ul></nav><divid=search-container><labelclass=visually-hiddenfor=search-bar>Suche</label><inputplaceholder="Suche nach…"autocomplete=offdisabledid=search-bartype=search><divid=search-results-container><divid=search-results></div></div></div></header><mainid=main-content><article><divid=heading><p><small><timedatetime=" 2024-01-30T00:00:00+00:00">Veröffentlicht am 30. 01. 2024</time></small><h1>Übersetzung: AIRASPI Build Log</h1><p><small><span>Von Aron Petau</span><span> • </span><span>6 Minuten gelesen</span><span> • </span></small><ulclass=tags><li><aclass=taghref=https://aron.petau.net/de/tags/coral/>coral</a><li><aclass=taghref=https://aron.petau.net/de/tags/docker/>docker</a><li><aclass=taghref=https://aron.petau.net/de/tags/edge-tpu/>edge TPU</a><li><aclass=taghref=https://aron.petau.net/de/tags/edge-computing/>edge computing</a><li><aclass=taghref=https://aron.petau.net/de/tags/frigate/>frigate</a><li><aclass=taghref=https://aron.petau.net/de/tags/local-ai/>local AI</a><li><aclass=taghref=https://aron.petau.net/de/tags/private/>private</a><li><aclass=taghref=https://aron.petau.net/de/tags/raspberry-pi/>raspberry pi</a><li><aclass=taghref=https://aron.petau.net/de/tags/surveillance/>surveillance</a></ul></div><divid=buttons-container><atitle="Nach Oben gehen"href=#topid=go-to-top><iclass=icon></i></a><ahref="https://shareopenly.org/share/?url=https://aron.petau.net/de/project/airaspi-build-log/&text=Utilizing%20an%20edge%20TPU%20to%20build%20an%20edge%20device%20for%20image%20recognition%20and%20object%20detection"id=sharetitle=Teilen><iclass=icon></i></a><atitle="Ein Issue erstellen"href=https://forgejo.petau.net/aron/awebsite/issuesid=issue><iclass=icon></i></a></div><h2id=AI-Raspi_Build_Log>AI-Raspi Build Log</h2><p>This should document the rough steps to recreate airaspi as I go along.<p>Rough Idea: Build an edge device with image recognition and object detection capabilites.<br> It should be realtime, aiming for 30fps at 720p.<br> Portability and usage at installations is a priority, so it has to function without active internet connection and be as small as possible.<br> It would be a real Edge Device, with
</code></pre><h3id=prep_system_for_coral>prep system for coral</h3><p>Thanks again @Jeff Geerling, this is completely out of my comfort zone, I rely on people writing solid tutorials like this one.<preclass=language-zshdata-lang=zsh><codeclass=language-zshdata-lang=zsh># check kernel version
</code></pre><p>While in the file, add the following lines:<preclass=language-configdata-lang=config><codeclass=language-configdata-lang=config>kernel=kernel8.img
dtparam=pciex1
dtparam=pciex1_gen=2
</code></pre><p>Save and reboot:<preclass=language-zshdata-lang=zsh><codeclass=language-zshdata-lang=zsh>sudo reboot
</code></pre><preclass=language-zshdata-lang=zsh><codeclass=language-zshdata-lang=zsh># check kernel version again
uname -a
</code></pre><ul><li>should be different now, with a -v8 at the end</ul><p>edit /boot/firmware/cmdline.txt<preclass=language-zshdata-lang=zsh><codeclass=language-zshdata-lang=zsh>sudo nano /boot/firmware/cmdline.txt
</code></pre><ul><li>add pcie_aspm=off before rootwait</ul><preclass=language-zshdata-lang=zsh><codeclass=language-zshdata-lang=zsh>sudo reboot
</code></pre><h3id=change_device_tree>change device tree</h3><h4id=wrong_device_tree>wrong device tree</h4><p>The script simply did not work for me.<p>maybe this script is the issue? i will try again without it {: .notice}<preclass=language-zshdata-lang=zsh><codeclass=language-zshdata-lang=zsh>curl https://gist.githubusercontent.com/dataslayermedia/714ec5a9601249d9ee754919dea49c7e/raw/32d21f73bd1ebb33854c2b059e94abe7767c3d7e/coral-ai-pcie-edge-tpu-raspberrypi-5-setup | sh
</code></pre><ul><li>Yes it was the issue, wrote a comment about it on the gist <ahref="https://gist.github.com/dataslayermedia/714ec5a9601249d9ee754919dea49c7e?permalink_comment_id=4860232#gistcomment-4860232">comment</a></ul><p>What to do instead?<p>Here, I followed Jeff Geerling down to the T. Please refer to his tutorial for more information.<p>In the meantime the Script got updated and it is now recommended again. {: .notice}<preclass=language-zshdata-lang=zsh><codeclass=language-zshdata-lang=zsh># Back up the current dtb
</code></pre><p>Note: msi- parent sems to carry the value <0x2c> nowadays, cost me a few hours. {: .notice}<h3id=install_apex_driver>install apex driver</h3><p>following instructions from <ahref=https://coral.ai/docs/m2/get-started#2a-on-linux>coral.ai</a><preclass=language-zshdata-lang=zsh><codeclass=language-zshdata-lang=zsh>echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list
</code></pre><ul><li>should display the connected tpu</ul><preclass=language-zshdata-lang=zsh><codeclass=language-zshdata-lang=zsh>sudo reboot
</code></pre><p>confirm with, if the output is not /dev/apex_0, something went wrong<preclass=language-zshdata-lang=zsh><codeclass=language-zshdata-lang=zsh>ls /dev/apex_0
</code></pre><h3id=Docker>Docker</h3><p>Install docker, use the official instructions for debian.<preclass=language-zshdata-lang=zsh><codeclass=language-zshdata-lang=zsh>curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
</code></pre><preclass=language-zshdata-lang=zsh><codeclass=language-zshdata-lang=zsh># add user to docker group
sudo groupadd docker
sudo usermod -aG docker $USER
</code></pre><p>Probably a source with source .bashrc would be enough, but I rebooted anyways {: .notice}<preclass=language-zshdata-lang=zsh><codeclass=language-zshdata-lang=zsh>sudo reboot
</code></pre><preclass=language-zshdata-lang=zsh><codeclass=language-zshdata-lang=zsh># verify with
docker run hello-world
</code></pre><h3id=set_docker_to_start_on_boot>set docker to start on boot</h3><preclass=language-zshdata-lang=zsh><codeclass=language-zshdata-lang=zsh>sudo systemctl enable docker.service
sudo systemctl enable containerd.service
</code></pre><h3id=Test_the_edge_tpu>Test the edge tpu</h3><preclass=language-zshdata-lang=zsh><codeclass=language-zshdata-lang=zsh>mkdir coraltest
cd coraltest
sudo nano Dockerfile
</code></pre><p>Into the new file, paste:<preclass=language-Dockerfiledata-lang=Dockerfile><codeclass=language-Dockerfiledata-lang=Dockerfile>FROM debian:10
</code></pre><p>Here, you should see the inference results from the edge tpu with some confidence values.<br> If it ain't so, safest bet is a clean restart<h3id=Portainer>Portainer</h3><p>This is optional, gives you a browser gui for your various docker containers {: .notice}<p>Install portainer<preclass=language-zshdata-lang=zsh><codeclass=language-zshdata-lang=zsh>docker volume create portainer_data
</code></pre><p>open portainer in browser and set admin password<ul><li>should be available under <ahref=https://airaspi.local:9443>https://airaspi.local:9443</a></ul><h3id=vnc_in_raspi-config>vnc in raspi-config</h3><p>optional, useful to test your cameras on your headless device. You could of course also attach a monitor, but i find this more convenient. {: .notice}<preclass=language-zshdata-lang=zsh><codeclass=language-zshdata-lang=zsh>sudo raspi-config
</code></pre><p>-- interface otions, enable vnc<h3id=connect_through_vnc_viewer>connect through vnc viewer</h3><p>Install vnc viewer on mac.<br> Use airaspi.local:5900 as address.<h3id=working_docker-compose_for_frigate>working docker-compose for frigate</h3><p>Start this as a custom template in portainer.<p>Important: you need to change the paths to your own paths {: .notice}<preclass=language-yamldata-lang=yaml><codeclass=language-yamldata-lang=yaml>version: "3.9"
services:
frigate:
container_name: frigate
privileged: true # this may not be necessary for all setups
restart: unless-stopped
image: ghcr.io/blakeblackshear/frigate:stable
shm_size: "64mb" # update for your cameras based on calculation above
devices:
- /dev/apex_0:/dev/apex_0 # passes a PCIe Coral, follow driver instructions here https://coral.ai/docs/m2/get-started/#2a-on-linux
volumes:
- /etc/localtime:/etc/localtime:ro
- /home/aron/frigate/config.yml:/config/config.yml # replace with your config file
- /home/aron/frigate/storage:/media/frigate # replace with your storage directory
</code></pre><h3id=Working_frigate_config_file>Working frigate config file</h3><p>Frigate wants this file wherever you specified earlier that it will be.<br> This is necessary just once. Afterwards, you will be able to change the config in the gui. {: .notice}<preclass=language-yamldata-lang=yaml><codeclass=language-yamldata-lang=yaml>mqtt:
enabled: False
detectors:
cpu1:
type: cpu
num_threads: 3
coral_pci:
type: edgetpu
device: pci
cameras:
cam1: # <++++++ Name the camera
ffmpeg:
hwaccel_args: preset-rpi-64-h264
inputs:
- path: rtsp://192.168.1.58:8900/cam1
roles:
- detect
cam2: # <++++++ Name the camera
ffmpeg:
hwaccel_args: preset-rpi-64-h264
inputs:
- path: rtsp://192.168.1.58:8900/cam2
roles:
- detect
detect:
enabled: True # <+++- disable detection until you have a working camera feed
width: 1280 # <+++- update for your camera's resolution
height: 720 # <+++- update for your camera's resolution
</code></pre><h3id=mediamtx>mediamtx</h3><p>install mediamtx, do not use the docker version, it will be painful<p>double check the chip architecture here, caused me some headache {: .notice}<preclass=language-zshdata-lang=zsh><codeclass=language-zshdata-lang=zsh>mkdir mediamtx
tar xzvf mediamtx_v1.5.0_linux_arm64v8.tar.gz && rm mediamtx_v1.5.0_linux_arm64v8.tar.gz
</code></pre><p>edit the mediamtx.yml file<h3id=working_paths_section_in_mediamtx.yml>working paths section in mediamtx.yml</h3><preclass=language-yamldata-lang=yaml><codeclass=language-yamldata-lang=yaml>paths:
</code></pre><p>also change rtspAddress: :8554<br> to rtspAddress: :8900<br> Otherwise there is a conflict with frigate.<p>With this, you should be able to start mediamtx.<preclass=language-zshdata-lang=zsh><codeclass=language-zshdata-lang=zsh>./mediamtx