# Pico-Faces On Fruit Jam

## Overview

https://youtube.com/shorts/u42icBlD7JY

> In the future, every microcontroller will be able to run models with 1.5 million parameters.

The&nbsp;[Pico-Faces](https://github.com/cpldcpu/pico-faces) project is an image generation model that can run on a microcontroller. The model implements a latent flow diffusion transformer (DiT). Similar to techniques used by some larger GenAI image models, but with some tricks and efficiencies that pack it down to 5000 times fewer parameters than typical larger image gen models. The model runs on the RP2350 and generates 128x128 pixel images of faces.

The original project supports two output modes: 1) USB serial link with image data transferred in it and rendered on a host PC with help from the Python Imaging Library. 2) VGA output using the [Pimoroni Pico VGA Demo Base](https://shop.pimoroni.com/products/pimoroni-pico-vga-demo-base). I have added support for the Fruit Jam and HSTX/DVI video output.

In the ethos of "Art is what you can get away with", I also added a fun 2x2 color grid effect inspired by Andy Warhol's artwork.&nbsp;

## Parts
Featured
### Adafruit Fruit Jam - Mini RP2350 Computer

[Adafruit Fruit Jam - Mini RP2350 Computer](https://www.adafruit.com/product/6200)
We were catching up on a recent [hackaday hackchat with eben upton](https://hackaday.io/event/202122-raspberry-pi-hack-chat-with-eben-upton)&nbsp;and learned some fun facts: such as the DVI hack for the RP2040 was inspired by <a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/6200)
[Related Guides to the Product](https://learn.adafruit.com/products/6200/guides)
![Angled shot of assembled mini computer PCB with plate.](https://cdn-shop.adafruit.com/640x480/6200-10.jpg)

Featured
### Snap-on Enclosure for Adafruit Fruit Jam

[Snap-on Enclosure for Adafruit Fruit Jam](https://www.adafruit.com/product/6425)
Here is a cool&nbsp;and minimal enclosure for your [Fruit Jam](https://www.adafruit.com/product/6200)&nbsp;to keep it safe during use and transport. This case has been custom-designed and 3D printed to accommodate all&nbsp;connection ports of the Fruit Jam. No screws or...

In Stock
[Buy Now](https://www.adafruit.com/product/6425)
[Related Guides to the Product](https://learn.adafruit.com/products/6425/guides)
![Angled Demo Shot of the Assembled Snap-on Enclosure with the Fruit Jam inside and powered on showing a rainbow effect of the LED's.](https://cdn-shop.adafruit.com/640x480/6425-02.jpg)

Featured
### USB Type A to Type C Cable - approx 1 meter / 3 ft long

[USB Type A to Type C Cable - approx 1 meter / 3 ft long](https://www.adafruit.com/product/4474)
As technology changes and adapts, so does Adafruit. This&nbsp;&nbsp; **USB Type A to Type C** cable will help you with the transition to USB C, even if you're still totin' around a USB Type A hub, computer or laptop.

USB C is the latest industry-standard connector for...

In Stock
[Buy Now](https://www.adafruit.com/product/4474)
[Related Guides to the Product](https://learn.adafruit.com/products/4474/guides)
![Angled shot of a coiled black, USB-C to USB-A cable.](https://cdn-shop.adafruit.com/640x480/4474-02.jpg)

Featured
### HDMI Cable - 1 meter

[HDMI Cable - 1 meter](https://www.adafruit.com/product/608)
Connect two HDMI devices together with this basic HDMI cable. It has nice molded grips for easy installation, and is 1 meter long (about 3 feet). This is a HDMI 1.3 cable.

We're now stocking a very fancy Official Raspberry Pi cable with overmolding and a Pi logo. Please note...

In Stock
[Buy Now](https://www.adafruit.com/product/608)
[Related Guides to the Product](https://learn.adafruit.com/products/608/guides)
![Official Raspberry Pi HDMI Cable - 1 meter](https://cdn-shop.adafruit.com/640x480/608-03.jpg)

Featured
### 7" Display 1280x800 (720p) IPS + Speakers - HDMI/VGA/NTSC/PAL

[7" Display 1280x800 (720p) IPS + Speakers - HDMI/VGA/NTSC/PAL](https://www.adafruit.com/product/1667)
Yes, this is an adorable small HDMI television with incredibly high resolution **and built in 3W stereo speakers**! We tried to get the smallest possible HDMI/VGA display with high-res, high-contrast visibility. The visible display measures only 7" (17.8cm) diagonal, and the TFT comes...

In Stock
[Buy Now](https://www.adafruit.com/product/1667)
[Related Guides to the Product](https://learn.adafruit.com/products/1667/guides)
![Front view of assembled and powered on HDMI 4 Pi - 7" Display. The monitor displays a desktop background with a raspberry logo.](https://cdn-shop.adafruit.com/640x480/1667-00.jpg)

# Pico-Faces On Fruit Jam

## Code

Info: It's possible to run the Pico-Faces demo on the Fruit Jam without diving into the code and building from source. The UF2 files linked on the Install Firmware page are ready to go if you just want to try it out. This page contains links and build instructions in case you want to inspect the code, or modify the behavior.

There a two branches with code relevant to this project:

- The&nbsp;[fruit\_jam branch](https://github.com/adafruit/pico-faces/tree/fruit_jam), which contains the bare minimum to run Pico-Faces on the Fruit Jam and control it over USB serial. It does not display a face by default on boot up. To render a face, connect via USB serial to the device and send a capital "G" then press enter. This would be the best branch to build from if you want to take the bare Pico-Faces image generation and make something different from it on the Fruit Jam.
- The [color\_grid\_mode branch](https://github.com/adafruit/pico-faces/tree/color_grid_mode), which contains the full 2x2 color grid demo. This one does render the first face on boot up automatically. It also provides controls using the built-in buttons to change rendering modes and color style, so it can be used without a host computer or USB serial. Start from this branch if you want to customize the demo behavior or make custom color styles.

## Building
Building the Pico-Faces project is a two step process. First configure the build, and then run it to make the firmware files. There are a few requirements to set up before the first build.

Clone a specified branch of the project using the following command. Replace `color_grid_mode` with `fruit_jam` if you want the bare Fruit Jam and DVI support without the 2x2 grid demo with button controls.&nbsp;

```terminal
git clone -b color_grid_mode https://github.com/adafruit/pico-faces.git
```

### Requirements

Clone the [pico-sdk repo](https://github.com/raspberrypi/pico-sdk) and fetch the [tinyusb](https://github.com/hathach/tinyusb/) submodule inside of it using the following commands.

```terminal
git clone https://github.com/raspberrypi/pico-sdk.git

cd pico-sdk
git submodule update --init lib/tinyusb
cd ../
```

### Configure & Build

These commands will let the environment know where to find pico-sdk, configure a build, and then make the build.

Update the value of `PICO_SDK_PATH` to point to the pico-sdk repo that was cloned in the previous step if it isn't in home directory at `~/pico-sdk/`.

```terminal
export PICO_SDK_PATH=~/pico-sdk/

# building on x86_64
cmake -S firmware -B build/fruitjam -G "Unix Makefiles" -DPICO_BOARD=adafruit_fruit_jam -DRF_DVI=1 -DRF_VGA=0 -DMODEL_BIN=$PWD/checkpoints/m3_decD_deep_full/model.bin -DCMAKE_BUILD_TYPE=Release -DPICOTOOL_FORCE_FETCH_FROM_GIT=1

# building on ARM like RPi
# cmake -S firmware -B build/fruitjam -DCMAKE_BUILD_TYPE=Release -DRF_DVI=1 -DRF_VGA=0 -DPICO_BOARD=adafruit_fruit_jam -DMODEL_BIN=$PWD/checkpoints/m3_decD_deep_full/model.bin

cmake --build build/fruitjam -j4
```

When the build is complete, the firmware file will be output as `build/fruitjam/pico_faces.uf2`. That file is ready to be copied to the RP2350 bootloader drive of the Fruit Jam.

# Pico-Faces On Fruit Jam

## Install Firmware

Installing the Pico-Faces Fruit Jam demo is a breeze thanks to the RP2350's UF2 bootloader.

## Download

Click the button below to download the Pico-Faces Fruit Jam demo firmware UF2 file.

[pico_faces_fruit_jam.uf2](https://cdn-learn.adafruit.com/assets/assets/000/146/285/original/pico_faces_fruit_jam.uf2?1789048655)
## Bootloader
![Fruit Jam with rest and boot buttons highlighted](https://cdn-learn.adafruit.com/assets/assets/000/146/282/medium800/microcontrollers_fruit_jam_bootloader_btns.jpg?1789047536 )

Connect your Fruit Jam board to your computer via a known good USB data+power cable. Go to Explorer or Finder (depending if you use Windows or Mac respectively).

To enter the Fruit Jam bootloader, hold down the **BOOT/**** BOOTSEL button**(highlighted in red above), and while continuing to hold it (don't let go!), press and release the**reset button**(highlighted in red or blue above).&nbsp;**Continue to hold the BOOT/BOOTSEL button until the RP2350 drive appears in File Explorer or Finder!**

If the drive does not appear, release all the buttons, and then repeat the process above.

You can also start with your board unplugged from USB, press and hold the BOOTSEL button (highlighted in red above), continue to hold it while plugging it into USB, and wait for the drive to appear before releasing the button.

A lot of people end up using charge-only USB cables and it is very frustrating! **Make sure you have a USB cable you know is good for data sync.**

You will see a new disk drive appear called **RP2350**.

&nbsp;

Drag or copy/paste the&nbsp; **pico\_faces\_fruit\_jam.uf2** file to&nbsp; **RP2350.**

&nbsp;

The firmware file is relatively large, it will take 30-60 seconds to copy to the bootloader drive. After copying is complete the Fruit Jam will reset automatically. When it starts up it will show a face grid on the connected display.

![File manager showing the RP2350 bootloader drive](https://cdn-learn.adafruit.com/assets/assets/000/146/283/medium640/microcontrollers_RP2350_drive.png?1789047661)

![RP2350 bootloader drive with pico_faces_fruit_jam.uf2 firmware file pasted onto it](https://cdn-learn.adafruit.com/assets/assets/000/146/286/medium640/microcontrollers_firmware_pasting.png?1789048772)

![pico-faces Fruit Jam demo showing a 2x2 grid of colored faces generated by the model.](https://cdn-learn.adafruit.com/assets/assets/000/146/287/medium800/microcontrollers_screenshot_after_firmware_install.png?1789049064 )

# Pico-Faces On Fruit Jam

## Use

Connect the Fruit Jam to a DVI compatible display and then connect a USB C cable to power it. The demo project will start automatically.

The demo can be controlled by the built-in buttons. If you want more fine grained control over specific configurations, the&nbsp;[USB serial control](https://github.com/cpldcpu/pico-faces/tree/main/viewer) implemented by the original pico-faces project is also supported.

&nbsp;

## Button 1
This button controls refreshing.

A single short press will trigger it to generate a new face and refresh the display to show it.

Pressing and holding button #1 will toggle between automatic and manual refresh modes. The demo starts in manual mode. When changed to automatic mode, it will generate a new face every 15 seconds without any button pressing.

![Fruit Jam demo showing button #1 being pressed and a manual refresh of the generated faces](https://cdn-learn.adafruit.com/assets/assets/000/146/289/medium640thumb/microcontrollers_manual_refresh.jpg?1789050562)

![Fruit Jam with button #1 highlighted](https://cdn-learn.adafruit.com/assets/assets/000/146/288/medium640/microcontrollers_fruit_jam_btn1.png?1789050524)

## Button 2
This button controls the color style and toggles the color grid mode on and off.

Single short presses on button #2 will cycle between the different available color styles in the color grid mode.&nbsp;

Pressing and holding the button will toggle between color grid mode and plain output mode. In plain output mode the face is rendered as it was output by the model.

![Fruit Jam button #2 being pressed to cycle through color styles](https://cdn-learn.adafruit.com/assets/assets/000/146/294/medium640thumb/microcontrollers_color_style.jpg?1789051748)

![Fruit Jam with button #2 highlighted](https://cdn-learn.adafruit.com/assets/assets/000/146/295/medium640/microcontrollers_fruit_jam_btn2.png?1789051841)

![Fruit Jam button #2 being long pressed to change from plain output mode to color grid mode.](https://cdn-learn.adafruit.com/assets/assets/000/146/296/medium640thumb/microcontrollers_plain_to_grid_mode.jpg?1789051997)

## Button 3
This button gives basic control over the model configuration. There are 8 configuration presets available to cycle between. The current preset is shown as a fraction in the lower left corner.

Single short presses on button #3 advances forward to the next config preset.

Pressing and holding button #3 will go backwards to the previous config preset.

The 8 config presets are shown in the table below.

- **K** is how many Euler steps the model will use. More steps takes longer to render, and makes a more refined and detailed image.
- **Class** is what type of face the model will be guided towards. The possibilities are the 4 permutations of female/male and neutral/smiling, as well as null class for unguided model output. The first two presets select one of the classes at random.
- **w** is the guidance strength. Higher **w** will be more strongly guided towards the specified class. When the model is unguided, the guidance strength will have no effect.

![Fruit Jam button #3 being long pressed to go to the previous config preset.](https://cdn-learn.adafruit.com/assets/assets/000/146/299/medium640thumb/microcontrollers_config_backwards.jpg?1789052887)

![Fruit Jam button #3 being pressed to advance to the next config preset](https://cdn-learn.adafruit.com/assets/assets/000/146/300/medium640thumb/microcontrollers_config_forwards.jpg?1789053592)

![Fruit Jam with button #3 highlighted](https://cdn-learn.adafruit.com/assets/assets/000/146/301/medium640/microcontrollers_fruit_jam_btn3.png?1789053612)

| Name               | K | Class            | w |
|--------------------|:-:|------------------|:-:|
| 1 `soft K2 w4 rnd`   | 2 | Random           | 4 |
| 2 `strong K8 w8 rnd` | 8 | Random           | 8 |
| 3 `unconditional`    | 4 | Null             | 0 |
| 4 `sketch K1`        | 1 | Null             | 0 |
| 5 `female neutral`   | 4 | Female, neutral  | 6 |
| 6 `female smiling`   | 4 | Female, smiling  | 6 |
| 7 `male neutral`     | 4 | Male, neutral    | 6 |
| 8 `male smiling`     | 4 | Male, smiling    | 6 |


## Guide Products

### Adafruit Fruit Jam - Mini RP2350 Computer

[Adafruit Fruit Jam - Mini RP2350 Computer](https://www.adafruit.com/product/6200)
We were catching up on a recent [hackaday hackchat with eben upton](https://hackaday.io/event/202122-raspberry-pi-hack-chat-with-eben-upton)&nbsp;and learned some fun facts: such as the DVI hack for the RP2040 was inspired by <a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/6200)
[Related Guides to the Product](https://learn.adafruit.com/products/6200/guides)
### Snap-on Enclosure for Adafruit Fruit Jam

[Snap-on Enclosure for Adafruit Fruit Jam](https://www.adafruit.com/product/6425)
Here is a cool&nbsp;and minimal enclosure for your [Fruit Jam](https://www.adafruit.com/product/6200)&nbsp;to keep it safe during use and transport. This case has been custom-designed and 3D printed to accommodate all&nbsp;connection ports of the Fruit Jam. No screws or...

In Stock
[Buy Now](https://www.adafruit.com/product/6425)
[Related Guides to the Product](https://learn.adafruit.com/products/6425/guides)
### USB Type A to Type C Cable - approx 1 meter / 3 ft long

[USB Type A to Type C Cable - approx 1 meter / 3 ft long](https://www.adafruit.com/product/4474)
As technology changes and adapts, so does Adafruit. This&nbsp;&nbsp; **USB Type A to Type C** cable will help you with the transition to USB C, even if you're still totin' around a USB Type A hub, computer or laptop.

USB C is the latest industry-standard connector for...

In Stock
[Buy Now](https://www.adafruit.com/product/4474)
[Related Guides to the Product](https://learn.adafruit.com/products/4474/guides)
### HDMI Cable - 1 meter

[HDMI Cable - 1 meter](https://www.adafruit.com/product/608)
Connect two HDMI devices together with this basic HDMI cable. It has nice molded grips for easy installation, and is 1 meter long (about 3 feet). This is a HDMI 1.3 cable.

We're now stocking a very fancy Official Raspberry Pi cable with overmolding and a Pi logo. Please note...

In Stock
[Buy Now](https://www.adafruit.com/product/608)
[Related Guides to the Product](https://learn.adafruit.com/products/608/guides)
### 7" Display 1280x800 (720p) IPS + Speakers - HDMI/VGA/NTSC/PAL

[7" Display 1280x800 (720p) IPS + Speakers - HDMI/VGA/NTSC/PAL](https://www.adafruit.com/product/1667)
Yes, this is an adorable small HDMI television with incredibly high resolution **and built in 3W stereo speakers**! We tried to get the smallest possible HDMI/VGA display with high-res, high-contrast visibility. The visible display measures only 7" (17.8cm) diagonal, and the TFT comes...

In Stock
[Buy Now](https://www.adafruit.com/product/1667)
[Related Guides to the Product](https://learn.adafruit.com/products/1667/guides)

## Related Guides

- [Adafruit Fruit Jam](https://learn.adafruit.com/adafruit-fruit-jam.md)
- [Microsoft Azure Cost Monitor](https://learn.adafruit.com/azure-cost-monitor.md)
- [Color Mixing QT Py Cuff Bracelet](https://learn.adafruit.com/color-mixing-qt-py-cuff.md)
- [MagTag Lists From Google Spreadsheets](https://learn.adafruit.com/collaborative-spreadsheets-to-magtag.md)
- [Mini GIF Players](https://learn.adafruit.com/mini-gif-players.md)
- [Feather RP2040 DVI Video Synth](https://learn.adafruit.com/feather-rp2040-dvi-video-synth.md)
- [Use Blinka in Ubuntu Core on Raspberry Pi](https://learn.adafruit.com/use-blinka-with-ubuntu-core-on-raspberry-pi.md)
- [Expressive Pixels for Adafruit Matrix Portal](https://learn.adafruit.com/expressive-pixels-for-matrix-portal.md)
- [DOOM on Fruit Jam](https://learn.adafruit.com/doom-on-fruit-jam.md)
- [Shadow Box Internet Clock with NeoPixel Visualization](https://learn.adafruit.com/shadow-box-internet-clock-with-neopixel-visualization.md)
- [Fruit Jam Chyron](https://learn.adafruit.com/fruit-jam-chyron.md)
- [CircuitPython Audio FX](https://learn.adafruit.com/circuitpython-audio-fx.md)
- [Fruit Jam Case](https://learn.adafruit.com/fruit-jam-case.md)
- [Hacking the Teenage Engineering EP-2350 Ting](https://learn.adafruit.com/hacking-the-teenage-engineering-ep-2350-ting.md)
- [50 Cent CPI Tracker for MagTag](https://learn.adafruit.com/50-cent-cpi-tracker-for-magtag.md)
- [USB MIDI Host2Host](https://learn.adafruit.com/usb-midi-host2host.md)
