awebsite/public/de/project/airaspi-build-log/index.html

152 lines
26 KiB
HTML
Raw Normal View History

2025-05-23 22:05:50 +02:00
<!doctype html><html data-theme=light lang=de xmlns=http://www.w3.org/1999/xhtml><head><meta charset=UTF-8><meta content="Mein Portfolio, Blog und allgemeine Präsenz online" name=description><meta content="width=device-width,initial-scale=1" name=viewport><meta content=#FF7E3C name=theme-color><meta content=#CC5A26 media=(prefers-color-scheme:dark) name=theme-color><title>Übersetzung: AIRASPI Build Log - Aron Petau</title><link href=https://aron.petau.net/de/project/airaspi-build-log/ rel=canonical><link href=https://mastodon.online/@reprintedAron rel=me><meta content=@reprintedAron@mastodon.online name=fediverse:creator><link href=https://aron.petau.net/favicon.png rel=icon type=image/png><link href=https://aron.petau.net/apple-touch-icon.png rel=apple-touch-icon sizes=180x180 type=image/png><link crossorigin href=https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css integrity=sha512-... referrerpolicy=no-referrer rel=stylesheet><link title="Aron Petau - Atom Feed" href=https://aron.petau.net/atom.xml rel=alternate type=application/atom+xml><style>:root{--accent-color:#ff7e3c}[data-theme=dark]{--accent-color:#cc5a26}@media (prefers-color-scheme:dark){:root:not([data-theme=light]){--accent-color:#cc5a26}}</style><link href=https://aron.petau.net/style.css rel=stylesheet><link href=https://aron.petau.net/css/timeline.css rel=stylesheet><link href=https://aron.petau.net/css/mermaid.css rel=stylesheet><link href=https://aron.petau.net/css/skills.css rel=stylesheet><link href=https://aron.petau.net/css/gallery.css rel=stylesheet><script defer src=https://aron.petau.net/closable.js></script><script defer src=https://aron.petau.net/copy-button.js></script><script data-goatcounter=https://aron@petau.net.https://awebsite.goatcounter.com/count/count defer src=https://aron.petau.net/count.js></script><script defer src=https://aron.petau.net/fuse.js></script><script defer src=https://aron.petau.net/search-fuse.js></script><script defer src=https://aron.petau.net/theme-switcher.js></script><script type=module>import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs';
2025-05-17 17:22:24 +02:00
mermaid.initialize({ startOnLoad: true });</script><meta content="Aron Petau" property=og:site_name><meta content="Übersetzung: AIRASPI Build Log - Aron Petau" property=og:title><meta content=https://aron.petau.net/de/project/airaspi-build-log/ property=og:url><meta content="Utilizing an edge TPU to build an edge device for image recognition and object detection" property=og:description><meta content=https://aron.petau.net/card.png property=og:image><meta content=de_DE property=og:locale><body><header id=site-nav><nav><a href=#main-content tabindex=0> Zum Hauptinhalt springen </a><ul><li id=home><a href=https://aron.petau.net/de/> <i class=icon></i>Aron Petau</a><li class=divider><li><a href=https://aron.petau.net/de/project/>Projekte</a><li><a href=https://aron.petau.net/de/pages/contact/>Kontakt</a><li><a href=https://aron.petau.net/de/pages/cv/>Vita</a><li><a href=https://aron.petau.net/de/pages/about/>Über mich</a><li id=search><button class=circle id=search-toggle title=Suche><i class=icon></i></button><li id=language-switcher><details class=closable><summary class=circle title=Sprache><i class=icon></i></summary> <ul><li><a href=https://aron.petau.net/project/airaspi-build-log/ lang=en>English</a></ul></details><li id=theme-switcher><details class=closable><summary class=circle title=Thema><i class=icon></i></summary> <ul><li><button title="Zum hellen Thema wechseln" class=circle id=theme-light><i class=icon></i></button><li><button title="Zum dunklen Thema wechseln" class=circle id=theme-dark><i class=icon></i></button><li><button title="Systemthema nutzen" class=circle id=theme-system><i class=icon></i></button></ul></details><li id=feed><a class=circle href=https://aron.petau.net/de/atom.xml title=Feed> <i class=icon></i> </a><li id=repo><a class=circle href=https://forgejo.petau.net/aron/awebsite title=Repository> <i class=icon></i> </a></ul></nav><div id=search-container><label class=visually-hidden for=search-bar>Suche</label><input placeholder="Suche nach…" autocomplete=off disabled id=search-bar type=search><div id=search-results-container><div id=search-results></div></div></div></header><main id=main-content><article><div id=heading><p><small> <time datetime=" 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><ul class=tags><li><a class=tag href=https://aron.petau.net/de/tags/coral/>coral</a><li><a class=tag href=https://aron.petau.net/de/tags/docker/>docker</a><li><a class=tag href=https://aron.petau.net/de/tags/edge-tpu/>edge TPU</a><li><a class=tag href=https://aron.petau.net/de/tags/edge-computing/>edge computing</a><li><a class=tag href=https://aron.petau.net/de/tags/frigate/>frigate</a><li><a class=tag href=https://aron.petau.net/de/tags/local-ai/>local AI</a><li><a class=tag href=https://aron.petau.net/de/tags/private/>private</a><li><a class=tag href=https://aron.petau.net/de/tags/raspberry-pi/>raspberry pi</a><li><a class=tag href=https://aron.petau.net/de/tags/surveillance/>surveillance</a></ul></div><div id=buttons-container><a title="Nach Oben gehen" href=#top id=go-to-top><i class=icon></i></a><a href="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=share title=Teilen><i class=icon></i></a><a title="Ein Issue erstellen" href=https://forgejo.petau.net/aron/awebsite/issues id=issue><i class=icon></i></a></div><h2 id=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><h3 id=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.<pre class=language-zsh data-lang=zsh><code class=language-zsh data-lang=zsh># check kernel version
uname -a
</code></pre><pre class=language-zsh data-lang=zsh><code class=language-zsh data-lang=zsh># modify config.txt
sudo nano /boot/firmware/config.txt
</code></pre><p>While in the file, add the following lines:<pre class=language-config data-lang=config><code class=language-config data-lang=config>kernel=kernel8.img
dtparam=pciex1
dtparam=pciex1_gen=2
</code></pre><p>Save and reboot:<pre class=language-zsh data-lang=zsh><code class=language-zsh data-lang=zsh>sudo reboot
</code></pre><pre class=language-zsh data-lang=zsh><code class=language-zsh data-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<pre class=language-zsh data-lang=zsh><code class=language-zsh data-lang=zsh>sudo nano /boot/firmware/cmdline.txt
</code></pre><ul><li>add pcie_aspm=off before rootwait</ul><pre class=language-zsh data-lang=zsh><code class=language-zsh data-lang=zsh>sudo reboot
</code></pre><h3 id=change_device_tree>change device tree</h3><h4 id=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}<pre class=language-zsh data-lang=zsh><code class=language-zsh data-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 <a href="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}<pre class=language-zsh data-lang=zsh><code class=language-zsh data-lang=zsh># Back up the current dtb
sudo cp /boot/firmware/bcm2712-rpi-5-b.dtb /boot/firmware/bcm2712-rpi-5-b.dtb.bak
# Decompile the current dtb (ignore warnings)
dtc -I dtb -O dts /boot/firmware/bcm2712-rpi-5-b.dtb -o ~/test.dts
# Edit the file
nano ~/test.dts
# Change the line: msi-parent = &LT0x2f>; (under `pcie@110000`)
# To: msi-parent = &LT0x66>;
# Then save the file.
# Recompile the dtb and move it back to the firmware directory
dtc -I dts -O dtb ~/test.dts -o ~/test.dtb
sudo mv ~/test.dtb /boot/firmware/bcm2712-rpi-5-b.dtb
</code></pre><p>Note: msi- parent sems to carry the value &LT0x2c> nowadays, cost me a few hours. {: .notice}<h3 id=install_apex_driver>install apex driver</h3><p>following instructions from <a href=https://coral.ai/docs/m2/get-started#2a-on-linux>coral.ai</a><pre class=language-zsh data-lang=zsh><code class=language-zsh data-lang=zsh>echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt-get update
sudo apt-get install gasket-dkms libedgetpu1-std
sudo sh -c "echo 'SUBSYSTEM==\"apex\", MODE=\"0660\", GROUP=\"apex\"' >> /etc/udev/rules.d/65-apex.rules"
sudo groupadd apex
sudo adduser $USER apex
</code></pre><p>Verify with<pre class=language-zsh data-lang=zsh><code class=language-zsh data-lang=zsh>lspci -nn | grep 089a
</code></pre><ul><li>should display the connected tpu</ul><pre class=language-zsh data-lang=zsh><code class=language-zsh data-lang=zsh>sudo reboot
</code></pre><p>confirm with, if the output is not /dev/apex_0, something went wrong<pre class=language-zsh data-lang=zsh><code class=language-zsh data-lang=zsh>ls /dev/apex_0
</code></pre><h3 id=Docker>Docker</h3><p>Install docker, use the official instructions for debian.<pre class=language-zsh data-lang=zsh><code class=language-zsh data-lang=zsh>curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
</code></pre><pre class=language-zsh data-lang=zsh><code class=language-zsh data-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}<pre class=language-zsh data-lang=zsh><code class=language-zsh data-lang=zsh>sudo reboot
</code></pre><pre class=language-zsh data-lang=zsh><code class=language-zsh data-lang=zsh># verify with
docker run hello-world
</code></pre><h3 id=set_docker_to_start_on_boot>set docker to start on boot</h3><pre class=language-zsh data-lang=zsh><code class=language-zsh data-lang=zsh>sudo systemctl enable docker.service
sudo systemctl enable containerd.service
</code></pre><h3 id=Test_the_edge_tpu>Test the edge tpu</h3><pre class=language-zsh data-lang=zsh><code class=language-zsh data-lang=zsh>mkdir coraltest
cd coraltest
sudo nano Dockerfile
</code></pre><p>Into the new file, paste:<pre class=language-Dockerfile data-lang=Dockerfile><code class=language-Dockerfile data-lang=Dockerfile>FROM debian:10
WORKDIR /home
ENV HOME /home
RUN cd ~
RUN apt-get update
RUN apt-get install -y git nano python3-pip python-dev pkg-config wget usbutils curl
RUN echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" \
| tee /etc/apt/sources.list.d/coral-edgetpu.list
RUN curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
RUN apt-get update
RUN apt-get install -y edgetpu-examples
</code></pre><pre class=language-zsh data-lang=zsh><code class=language-zsh data-lang=zsh># build the docker container
docker build -t "coral" .
</code></pre><pre class=language-zsh data-lang=zsh><code class=language-zsh data-lang=zsh># run the docker container
docker run -it --device /dev/apex_0:/dev/apex_0 coral /bin/bash
</code></pre><pre class=language-zsh data-lang=zsh><code class=language-zsh data-lang=zsh># run an inference example from within the container
python3 /usr/share/edgetpu/examples/classify_image.py --model /usr/share/edgetpu/examples/models/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite --label /usr/share/edgetpu/examples/models/inat_bird_labels.txt --image /usr/share/edgetpu/examples/images/bird.bmp
</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<h3 id=Portainer>Portainer</h3><p>This is optional, gives you a browser gui for your various docker containers {: .notice}<p>Install portainer<pre class=language-zsh data-lang=zsh><code class=language-zsh data-lang=zsh>docker volume create portainer_data
docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest
</code></pre><p>open portainer in browser and set admin password<ul><li>should be available under <a href=https://airaspi.local:9443>https://airaspi.local:9443</a></ul><h3 id=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}<pre class=language-zsh data-lang=zsh><code class=language-zsh data-lang=zsh>sudo raspi-config
</code></pre><p>-- interface otions, enable vnc<h3 id=connect_through_vnc_viewer>connect through vnc viewer</h3><p>Install vnc viewer on mac.<br> Use airaspi.local:5900 as address.<h3 id=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}<pre class=language-yaml data-lang=yaml><code class=language-yaml data-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
- type: tmpfs # Optional: 1GB of memory, reduces SSD/SD Card wear
target: /tmp/cache
tmpfs:
size: 1000000000
ports:
- "5000:5000"
- "8554:8554" # RTSP feeds
- "8555:8555/tcp" # WebRTC over tcp
- "8555:8555/udp" # WebRTC over udp
environment:
FRIGATE_RTSP_PASSWORD: "******"
</code></pre><h3 id=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}<pre class=language-yaml data-lang=yaml><code class=language-yaml data-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><h3 id=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}<pre class=language-zsh data-lang=zsh><code class=language-zsh data-lang=zsh>mkdir mediamtx
cd mediamtx
wget https://github.com/bluenviron/mediamtx/releases/download/v1.5.0/mediamtx_v1.5.0_linux_arm64v8.tar.gz
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<h3 id=working_paths_section_in_mediamtx.yml>working paths section in mediamtx.yml</h3><pre class=language-yaml data-lang=yaml><code class=language-yaml data-lang=yaml>paths:
cam1:
runOnInit: bash -c 'rpicam-vid -t 0 --camera 0 --nopreview --codec yuv420 --width 1280 --height 720 --inline --listen -o - | ffmpeg -f rawvideo -pix_fmt yuv420p -s:v 1280x720 -i /dev/stdin -c:v libx264 -preset ultrafast -tune zerolatency -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH'
runOnInitRestart: yes
cam2:
runOnInit: bash -c 'rpicam-vid -t 0 --camera 1 --nopreview --codec yuv420 --width 1280 --height 720 --inline --listen -o - | ffmpeg -f rawvideo -pix_fmt yuv420p -s:v 1280x720 -i /dev/stdin -c:v libx264 -preset ultrafast -tune zerolatency -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH'
runOnInitRestart: yes
</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.<pre class=language-zsh data-lang=zsh><code class=language-zsh data-lang=zsh>./mediamtx
2025-05-23 22:05:50 +02:00
</code></pre><p>If there is no error, you can verify your stream through vlc under rtsp://airaspi.local:8900/cam1 (default would be 8554, but we changed it in the config file)<h3 id=Current_Status>Current Status</h3><p>I get working streams from both cameras, sending them out at 30fps at 720p. frigate, however limits the display fps to 5, which is depressing to watch, especially since the tpu doesnt even break a little sweat.<p>Frigate claime that the TPU is good for up to 10 cameras, so there is headroom.<p>The stram is completely errant and drops frames left and right. I have sometimes seen detect fps of 0.2, but the TPU speed should definitely not be the bottleneck here. Maybe attach the cameras to a separate device and stream from there?<p>The biggest issue here is that the google folx seems to have abandoned the coral, even though they just released a new piece of hardware for it. Their most RECENT python build is 3.9. Specifically, pycoral seems to be the problem there. without a decent update, I will be confined to debian 10, with python 3.7.3. That sucks. There are custom wheels, but nothing that seems plug and play.<p>About the rest of this setup: The decision to go for m.2 E key to save money, instead of spending more on the usb version was a huge mistake. Please do yourself a favor and spend the extra 40 bucks. Technically, its probably faster and better with continuous operation, but i have yet to feel the benefit of that.<h3 id=TODOs>TODOs</h3><ul><li>add images and screenshots to the build log<li>Check whether vdo.ninja is a viable way to add mobile streams. then Smartphone stream evaluation would be on the horizon.<li>Bother the mediamtx makers about the libcamera bump, so we can get rid of the rpicam-vid hack. I suspect there is quirte a lot of performance lost there.<li>tweak the frigate config to get snapshots and maybe build an image / video database to later train a custom model.<li>worry about attaching an external ssd and saving the video files on it.<li>find a way to export the landmark points from frigate. maybe send them via osc like in pose2art?<li>find a different hat that lets me access the other TPU? I have the dual version, but can currently only acces 1 of the 2 TPUs due to hardware restrictions.</ul></article><hr><nav id=post-nav><a class="post-nav-item post-nav-prev" href=https://aron.petau.net/de/project/commoning-cars/> <div class=nav-arrow>Vorherige</div> <span class=post-title>Übersetzung: Commoning Cars</span> </a><a class="post-nav-item post-nav-next" href=https://aron.petau.net/de/project/aethercomms/> <div class=nav-arrow>Nächstes</div> <span class=post-title>aethercomms</span> </a></nav><span class=hidden id=copy-code-text>Code kopieren</span><span class=hidden id=search-index>https://aron.petau.net/de//search_index.en.json</span><span class=hidden id=more-matches-text>$MATCHES mehr Treffer</span></main><footer id=site-footer><div class=carbonbadge id=wcb></div><script defer src=https://unpkg.com/website-carbon-badges@1.1.3/b.min.js></script><nav><ul><li><a href=https://aron.petau.net/de/project/>Projekte</a><li><a href=https://aron.petau.net/de/pages/privacy/>Privacy</a><li><a class=external href=https://kaesewerkstatt.petau.net>Käsewerkstatt</a><li><a class=external href=https://www.newpractice.net/author/aron-petau>New Practice Network</a></ul></nav><p>© Aron Petau, 2025<p><a class=external href=https://forgejo.petau.net/aron/awebsite>Website-Quelle</a><ul id=socials><li><a rel=" me" href=https://github.com/arontaupe title=GitHub> <i style="--icon:url(&#34data:image/svg+xml,%3Csvg role='img' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Ctitle%3EGitHub%3C/title%3E%3Cpath d='M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0