Close
0%
0%

TensorFlow Processing Unit investigation

What is it all about?

Similar projects worth following
Google wanted to be able to categorise and search images, so it developed technology to recognise objects in images, with less time and energy than conventional processors. Their software is called TensorFlow, and their specialised machine learning chip is called a TensorFlow Processing Unit. It can process images at video rates. It is also good for general-purpose machine learning too.

Google have many TPUs in their servers and sell machine-learning time 'inside' the cloud. Through a company called Coral, you can buy a TPU to work at the 'edge' of the cloud - i.e. your PC. Hence their product is called an EdgeTPU.

I bought a couple of USB TPU dongles for myself and a data scientist to try out.
We have got as far as running the Python demonstration program.

The first photo shows modules from Coral.

The first module looks like a Raspberry Pi with a TPU built in (with a different CPU).

The second module talks through a USB port.

I'm not a fan of fans because they make noise, consume power, collect dust, wear out. 

The USB modules get warm in normal use, and very warm if overclocked.

I bolted the modules I bought to an aluminium heatsink from a scrapped PC PSU, and a milled aluminium case from a scrap box. CPU thermal paste. Zero cost, silent, and the modules don't get hot.

  • Coral Dev Board

    Keith03/18/2023 at 18:23 0 comments

    USB modules take 0.9 amps peak, and 0.5 amps typical. That is 2.5 watts typical.

    The Coral Dev Board single-board computer with Edge TPU specifies a USB-C source with up to 3A, that's 15W or as much as my first soldering iron. The heatsink and fan are rated at 0.65 watts, so I don't know where the rest of it is going. Maybe it has a high inrush current.

    It looks similar to the R-Pi. 85 x 56 mm is the same bank-card size. The mounting holes are on the corners of a 49 x 58 mm rectangle for the R-Pi.

    The header pinout has the power and ground positions as the R-Pi.

    Pins 27 and 28 are I2C SDA and SCL, where they are reserved (DNC) on the R-Pi.

    So I'd cautiously say this is not a coincidence, and that they intended it to be compatible in order to make interfacing easy. You must check this for yourself!

    The chipset is not the Broadcom device used in the Pi, but a similar sort of thing. CPU, GPU, and VPU.

    It has something the Pi does not: a Microchip ATECC608A cryptographic coprocessor. It is a small (SOIC) 8-pin chip, so not a massive power drain.

    I expect the advantage of having the TPU integrated on the board is that it avoids the overhead of USB traffic. You even get a pair of TPUs on a Mini PCIe or M.2 cards that can fit in laptops.

    2023-04-08

    The get-started guide is here: https://coral.ai/docs/dev-board/get-started/

    It was fairly easy to follow. It does not boot the OS from an SD card (as the Raspberry Pi does), but stores it on-board. To get it there, you can load it either from an SD card or a serial port.

    I avoided faffing around making an SD card (which would only be needed once), and loaded it from the serial port. You need to jump ahead to here: https://coral.ai/docs/dev-board/reflash/#first-time-setup then jump back to get-started.

    The board is also designed to run "headless" - you talk to it via the serial port instead of needing a keyboard, mouse and monitor. There is an HDMI video output, but this is meant for showing processed video, not a user interface.

    The parrot image recognition demo runs about the same speed as TPU USB dongle.

    The vehicle video recognition demo recognises cars and trucks in a record video of motorway traffic. It can display the results through either the HDMI port or an internet browser window. You can press 'n' to see the performance difference between using the microprocessor (about 3 frames per second) or the TPU (about 74 frames per second). 

    I notice the fan is not on all the time, and I assume this is to conserve fan life by only running when the TPU is busy.

    There are some interesting example projects, such as a bird feeder that recognises squirrels trying to steal bird food!

    https://coral.ai/projects/bird-feeder/

    2023-04-09

    Having got it up and running, eventually it will need some video input. The camera connections are not compatible with the Raspberry Pi camera module, but the Coral camera is only about $20. Unfortunately everywhere is out of stock at this moment.

    2023-04-15

    I bought a case for £22 which turned out to be two rather flimsy (1 mm thin aluminium) bits of punched and folded metal, held together by slots in the top and tabs on the bottom. The slots are bigger than the tabs, so top will rattle if you shake the bottom. The micro-SD slot just about lines up with the socket if you pull the top upwards. Due to the looseness of the tabs, if you put a card in and press the top of the case, the top will press on the card and damage the card or push the socket off the PCB. This could be fixed by filing the slot wider. It will then merge with the headphone socket hole, which is probably what the designers were trying to avoid. The sides of the top have to bend out to get over the headphone/USB-C/HDMI connectors, take care not to bend it beyond its elastic limit. 

    A bit disappointing quality but it does the job of protecting the board from finger-borne electrostatic discharge,...

    Read more »

  • Heatsinking

    Keith03/11/2023 at 18:36 0 comments

    I'm not a fan of fans because they make noise, consume power, collect dust, wear out. 

    The USB modules get warm in normal use, and very warm if overclocked.

    I bolted the modules on bits of metal from my scrap box, with CPU thermal paste.
    Zero cost, silent, and the modules don't get hot.

    Unit 1 - an aluminium heatsink from a scrapped PC PSU:

    Unit 2 - a milled aluminium case from a old project box:

  • Bibliography

    Keith09/11/2022 at 13:44 0 comments

    Hands-On Machine Learning with SciKit-Learn, Keras and TensorFlow

    by Aurélien Géron 

  • Installing the Coral TPU software

    Keith09/04/2022 at 17:56 0 comments

    Installation on Linux laptop

    Fairly easy, follow the instructions here:

    https://coral.ai/docs/accelerator/get-started/#1-install-the-edge-tpu-runtime

    https://coral.ai/docs/accelerator/get-started/#runtime-on-linux

    We got side-tracked when the initial attempt failed and we tried to continue. This was because the installation commands change directory in places, and if you are in the wrong directory and try to continue, it won't find the files it expects and will then throw errors.

    Eventually it installed correctly. 

    Installation on Linux floortop

    It says you need a USB 3 port, but I only have USB 2 ports right now.

    I plugged the TPU in anyway, to see if it would work.

    Running the demo code on the laptop

    The instructions say you should get results like this:

    ----INFERENCE TIME----
    Note: The first inference on Edge TPU is slow because it includes loading the model into Edge TPU memory.
    11.8ms
    3.0ms
    2.8ms
    2.9ms
    2.9ms
    -------RESULTS--------
    Ara macao (Scarlet Macaw): 0.75781

    And indeed we did.

    Running the demo code on the floortop

    I got these results:

    136.7ms
    16.3ms
    16.3ms
    16.2ms
    16.4ms
    

    This shows it still works but runs slower. Nearly 12 times slower for initial loading of the model, and nearly 6 times slower thereafter.

    Just to check it was the TPU and not the CPU, I pulled the TPU out and tried running the program again. I got various errors like: Failed to load delegate from libedgetpu.so.1
    Plugging the TPU back in restored working operation.

    I had hoped that the software would notice the TPU was not there and assign the work to the CPU. That would make speed comparison tests much easier. 

    The TPU did not get warm, so presumably it is in a low-power idle mode when not doing work. I expect it will get warm recognising objects in real-time video.

    Okay, all I need to do is order a USB 3 card for my PC. I ordered one. This gave the following times:

    15.5ms
    4.7ms
    4.7ms
    4.7ms
    4.7ms

     This is with standard speed. After installing with maximum speed:

    sudo apt-get install libedgetpu1-max

    I got the following times:

    14.1ms
    3.2ms
    3.2ms
    3.2ms
    3.1ms

    Which is much more satisfactory, 68% of the slow times. 

  • Installing Keras, Tensorflow, Jupyter, and Coral Software

    Keith08/29/2022 at 21:23 0 comments

    2020-08-12

    Software failed to install on my Linux Mint 17.3 drive, perhaps too out of date?

    2022-08-29

    Now on Linux Mint 20. Project reactivated. In the software manager, searching for "TensorFlow" returns "Python3-keras" so presumably TensorFlow is part of Keras. Installed without problems.

    In a console,

    pip install tensorflow

     reports nothing to do, so I'll assume it is installed.

    Next, installed Jupyter-notebook without problems. The Launch button does nothing. Need to use the command line:

    jupyter notebook

     which returns the error 

    ImportError: cannot import name 'soft_unicode' from 'markupsafe' (/home/keith/.local/lib/python3.8/site-packages/markupsafe/__init__.py)

     Googling this error returns the suggestion to enter this command:

    pip install -U flask

    This gets jupyter working.

    I then tried installing the Tensorflow Accelerator software from Coral

    https://coral.ai/docs/accelerator/get-started/#1-install-the-edge-tpu-runtime

    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 libedgetpu1-std

    No errors reported.

    Now installing the pycoral library as per:
    https://coral.ai/docs/accelerator/get-started/#2-install-the-pycoral-library 

    sudo apt-get install python3-pycoral

    No errors. Looks like  success.

    There is an option to run at 'full speed', which is advised against as it will get very hot. I presume the chip runs slower to keep within the limited heat dissipation capacity of the package. However, I have bolted my dongles onto large pieces of aluminium for passive heat-sinking. If they still run hot I can find larger heat sinks, or even fit fans if required.

    2022-09-01

    Overnight, it has stopped working, with the error:

    Jupyter Notebook – 500 : Internal Server Error

    Googling solutions, https://clay-atlas.com/us/blog/2021/09/14/jupyter-notebook-en-internal-server-error/
    s
    ays to type:

    pip3 install --upgrade --user nbconvert

    This fixes the problem. 

  • What is it?

    Keith08/28/2022 at 00:47 0 comments

    I had no idea what the fuss was all about, and not much now. However, I shall write what I think it is about. I may be wrong of course.

    Search engines collect and index text easily, but not images. To identify objects in images requires much more complex computing. Google wrote a software library for machine learning and artificial intelligence, called TensorFlow.

    They then developed an application-specific integrated circuit, optimised to do much of the TensorFlow work in specialised hardware at a much faster rate and lower power. 

    I have only a passing interest in the tasks it was designed for, mainly because I can't think of killer applications that would interest me... yet. I just have a few nascent ideas.

    In the mean time, I do know a data scientist who is a maths geek and is able to write machine learning programs. I helped install TensorFlow and Keras software on her Linux laptop. Tip: just use the Linux software manager.

    Keras is a software library that provides a Python interface for artificial neural networks, and acts as an interface for the TensorFlow library. 

    The Keras website recommends a book called "Deep Learning with Python" which recommends using an NVIDIA graphics card, I presume to use the GPU(s) for acceleration. This is impossible on the Linux laptop which has an Intel CPU with integrated graphics. Maybe on my floortop PC which has a NVIDIA G96C [GeForce 9500 GT] graphics card, which I think has 32 CUDA cores. Whatever the case, I think the accelerator dongle will beat the graphics card acceleration. We shall run tests to measure just how much faster they make programs.

  • Hardware

    Keith08/09/2020 at 23:41 0 comments

    2020-08-09

    Ordered two dongles, one for me and one for a friend who is a natural maths wiz and has used TensorFlow. 
    £60 each, including VAT.

    2020-08-12

    Dongles arrive. Data sheet says they get hot so I attached mine to a heatsink salvaged from an old PC PSU. With heat-sinking compound of course.

    I attached the second dongle to an old black aluminium case. It looks neater.

    Software failed to install on my Linux Mint 17.3 drive, perhaps too out of date?

    Windows version needs Windows 10, and so my Windows 7 laptop is too old.

    I hope one of my Raspberry Pi boards is up to the job.

    2022-08-29

    Software installed correctly.

View all 7 project logs

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates