Search This Blog

Thursday, September 30, 2021

Coral TPU for Computer Vision on Raspberry Pi

 The CORAL TPU can be used to speed up Tensorflow on the RPi to give a fairly reasonable rate for computer vision tasks such as object detection, pose estimation, speech recognition.

For examples see:  https://coral.ai/models/object-detection/ 




Assuming Python3 is already installed.....

Install Tensorflow Lite

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 python3-tflite-runtime

Source info: https://www.tensorflow.org/lite/guide/python


Install Python Coral

sudo apt-get install python3-pycoral


Clone the Coral Examples into a new folder

mkdir pycoral

cd pycoral

git clone https://github.com/google-coral/pycoral.git

source: https://github.com/google-coral/pycoral 


Clone the test data:

git clone https://github.com/google-coral/test_data.git


Give it a go with an image:

pi@pi3:~/code/pycoral/pycoral $ python3 examples/detect_image.py   --model test_data/ssd_mobilenet_v2_coco_quant_postprocess_edgetpu.tflite   --labels test_data/coco_labels.txt   --input ~/images/20211001/images/A21100100192512.jpg



----INFERENCE TIME----

Note: The first inference is slow because it includes loading the model into Edge TPU memory.

274.20 ms

81.01 ms

91.19 ms

72.09 ms

69.50 ms

-------RESULTS--------

car

  id:     2

  score:  0.671875

  bbox:   BBox(xmin=-6, ymin=138, xmax=697, ymax=560)

car

  id:     2

  score:  0.6171875

  bbox:   BBox(xmin=97, ymin=220, xmax=1165, ymax=975)

Thursday, February 18, 2021

Moving PostgreSQL WAL file to a new drive on an Ubuntu server

Sometimes you may need to move PostgreSQL's WAL (write ahead log) file to a new drive. For example to gain better speed if you put it on an SSD or NVME drive, or to gain additional space.

 

First stop PostgreSQL service:

sudo service postgresql stop

Now make a new folder on the new drive, and move (or copy if have room) the pg_wal directory across:


mkdir -p /mnt/newdrive/pg_wal
su postgres
cp /var/lib/postgresql/11/main/pg_wal/* /mnt/newdrive/pg_wal/

Make a back up for now of the WAL directory:

mv /var/lib/postgresql/11/main/pg_wal   /var/lib/postgresql/11/main/pg_wal_bck

Create a link and start the DB again:
ln -s /mnt/newdrive/pg_wal /var/lib/postgresql/11/main/pg_wal
sudo service postgresql start

psql -U postgres -W
 >> should now ask for your password and you can log in

Any issues check the LOG file:


tail postgresql/postgresql-11-main.log -n 100


When you are happy it's all working then you can remove the WAL back up directory:
rmdir -r /var/lib/postgresql/11/main/pg_wal_bck


Notes:


any permission issues try chown to postgres and chmod 777 on the new dir

sudo chown postgres /mnt/newdrive/pg_wal

sudo chmod 777 /mnt/newdrive/pg_wal

Saturday, February 6, 2021

sudo apt-get update error for older Ubuntu (e.g. Ubuntu 19)


For older Ubuntu where you get an error when:

sudo apt-get update

E: The repository 'http://security.ubuntu.com/ubuntu eoan-security Release' no longer has a Release file. 


Try this:

sudo sed -i -re 's/([a-z]{2}\.)?archive.ubuntu.com|security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list

then try
 sudo apt-get update

Thursday, February 4, 2021

Audible to MP3

It's frustrating when you purchase an audio book on Audible but can then only play it back from their apps - which isn't possible if you want to put it on a basic MP3 player to take jogging, cycling, etc.

To get around this you can strip away the DRM using your activation code. So this isn't cracking the code but just removing it, meaning you need to know your own 4bit Audible key.

Steps:

1) download the .aax file from your Audible account

2) use this tool to find your key  (drag the .aax file to this page and copy the key it returns)

https://audible-tools.github.io/ 


3) Install ffmpeg on your PC and then run this command:


ffmpeg -activation_bytes your-key-here -i input.aax -vn -c:a copy output.mp4

where you switch your-key-here to the value you got from the web tool, and the input.aax to the filename of the .aax you downloaded. This generates an output MP4 file in a few seconds which is free from the DRM. 

Now you can move it to any suitable player! 



---

Shell script to chop .aax into mp3 chapters

#!/bin/bash
# Author: http://crunchbang.org/forums/viewtopic.php?id=38748#p414992
# m4bronto
#     Chapter #0:0: start 0.000000, end 1290.013333
#       first   _     _     start    _     end
while [ $# -gt 0 ]; do
ffmpeg -i "$1" 2> tmp.txt
while read -r first _ _ start _ end; do
  if [[ $first = Chapter ]]; then
    read  # discard line with Metadata:
    read _ _ chapter
    
    ffmpeg -vsync 2 -i "$1" -ss "${start%?}" -to "$end" -vn -ar 44100 -ac 2 -ab 128  -f mp3 "$chapter.mp3" </dev/null
  fi
done <tmp.txt
rm tmp.txt
shift
done