FitAI: Raspberry Pi Fitness Assistant Using YOLOv8

by NoahL in Living > Health

39 Views, 0 Favorites, 0 Comments

FitAI: Raspberry Pi Fitness Assistant Using YOLOv8

53fd310e-ff07-478d-87c9-e88312d4988546.jpg

FitAI is a smart fitness assistant powered by AI and Raspberry Pi. It detects whether your biceps or quads are strong or weak using an image, video, or webcam feed. But it doesn't stop at detection. It also helps you train and improve.

When the system detects, for example, a Weak Bicep, it:

  1. Displays “Weak Bicep” on a 16x2 I²C LCD.
  2. Plays a specific training video on a 7-inch touchscreen showing how to strengthen that muscle.

You get instant AI feedback + personalized fitness advice in one compact setup!

Supplies

c1be4e15-43b7-4b69-b355-22bf86349d80.jpg
fc549964-356f-4711-aaa6-23f9364e41c0.jpg
2b55dda3-de31-4629-93a0-496fb581efb2.jpg
cac9f9b7-eb80-470a-b97f-aa1afe921cd3.jpg

Raspberry Pi 5: Hosts the LCD screen and 7-inch video display. Receives detection labels from the PC and plays the correct workout video.

USB Webcam: Captures live video of the user for muscle detection.

I²C LCD Display (16x2): Displays detection output (e.g., "Weak Bicep") based on YOLOv8 results sent from the PC.

7-inch Touchscreen: Shows a full-screen workout video (e.g., how to strengthen weak biceps) based on the detected label.

PC or Laptop: Runs the Gradio interface and YOLOv8 detection model. It handles image/video/webcam input and sends muscle labels (like "strong quad") to the Raspberry Pi via HTTP.

Python + YOLOv8: Python is used to write all backend logic. YOLOv8 is the object detection model that classifies the muscles as strong or weak.

Gradio: Provides a user interface for uploading an image, video, or using the webcam live. Displays the detection label before sending it to the Raspberry Pi.

Flask (on Raspberry Pi): Receives the detection label from the PC and plays the corresponding video using ffplay.

ffplay (part of ffmpeg): Lightweight video player used on the Raspberry Pi to show videos in fullscreen on the touchscreen.


Total estimated cost: €309,42. Full Bill of Materials with links and sources is included in the attached BOM PDF.

Take Photos & Record Videos

IMG20250527162052.jpg
IMG20250527174709.jpg
IMG20250527175942.jpg
IMG20250527175534.jpg

Take multiple photos of your arms and legs.

Vary the backgrounds and maintain a consistent pose.

Create 4 exercise videos, one for each category:

  1. Weak Bicep
  2. Strong Bicep
  3. Weak Quad
  4. Strong Quad

Upload to Roboflow

Create a new Instance Segmentation project in Roboflow.

Upload your photos.

Annotate Your Dataset

Use Roboflow’s segmentation tool to label each image accurately.

Create a Version

Go to the Versions tab → click Create New Version.

In Preprocessing, enable:

  1. Grayscale

In Augmentations, enable:

  1. Flip, Crop, Rotation, Shear, Brightness, Exposure, Blur

Click Create Version.

Export Your Dataset

Screenshot 2025-06-17 135343.png

Choose YOLOv8 format.

Click Show Download Code and copy it.

Download Dataset in Python

Paste the code into a Python script in VS Code.

Run the script to download your dataset locally.

Train Your Model

Start with:

  1. Model: yolov8n-seg.pt (nano version)
  2. Epochs: 50

After successful testing, switch to:

  1. Model: yolov8m-seg.pt (medium version)

Test the Model

Screenshot 2025-06-17 140140.png

Write a script to:

  1. Open your webcam.
  2. Run real-time predictions using the trained YOLOv8 model.

Set Up Raspberry Pi Hardware

47a91e1e-30bf-4761-a53e-bb8aea250fa2.jpg

Required:

  1. Raspberry Pi 5
  2. 16x2 I²C LCD
  3. 7-inch HDMI Touchscreen
  4. Freenove GPIO expansion board (optional for easier connections)

Write Raspberry Pi Scripts

Create the following Python files:

  1. lcd_server.py – Displays the detected label (e.g., “Strong Quad”) on the LCD.
  2. video_server.py – Plays the correct training video based on the label.
  3. client_pi.py – Streams the Pi’s webcam over HTTP.

All these use Flask to receive requests from the PC.

Create the Gradio UI (on PC)

Screenshot 2025-06-17 141302.png
Screenshot 2025-06-17 141250.png
Screenshot 2025-06-17 141237.png
  1. Your Gradio app has 3 tabs:
  2. Image – Upload and detect from a photo.
  3. Video – Upload and process a video (first frame triggers feedback).
  4. Webcam – View live detection and press "Take Photo" to trigger feedback.

Each mode:

  1. Sends the label to the LCD and
  2. Plays the matching training video on the Pi touchscreen.

Connect the 7-inch Display

5d63f483-a43c-4136-840b-497a1a6764bd.jpg

Plug:

  1. USB power cable into the Pi
  2. HDMI (or micro HDMI) from Pi to screen
  3. USB-C for touchscreen capability

Connect the I²C LCD Screen

c8d88566-15c8-4b52-9d4d-2a92292eb450.jpg
  1. Connect the pins:
  2. GND → Ground
  3. VCC → 5V or 3.3V
  4. SDA/SCL → to correct GPIO pins

Use a library like smbus.

Auto-Start on Boot

Create these systemd service files:

  1. client_pi.service
  2. lcd_server.service
  3. video_server.service

This makes the Pi start everything automatically on boot—no manual scripts needed!

Build a Wooden Enclosure (Maker Skills)

d6df309a-bc38-430b-bb01-64393e3fa4e2.jpg
34a7588b-b579-44ab-b9bd-8cdb114c0bfd.jpg
c970f113-4723-49f0-bce0-2ec2e6f48cd9.jpg
53fd310e-ff07-478d-87c9-e88312d4988546.jpg
6d30065c-eeca-4ba0-af8c-69f43f1e667e.jpg
cc763ead-3c1b-4452-a04a-37585246859e.jpg
add26551-b8a1-42b7-964c-a39a04ef3399.jpg

I built a custom wooden enclosure using planks cut to the following size:

  1. 30 cm (width) x 25 cm (depth) x 9 cm (height)

Assembly Instructions:


  1. Cut your wooden panels to form a box with those iner dimensions.
  2. The top panel should be the same size (30x25 cm), but:
  3. Cut out ~75% of it (leaving a hingeable flap).
  4. Attach this movable top section with hinges so it can open and close like a lid.
  5. On the inside, attach a small support stick to prop the lid open when needed.

Mounting the Touchscreen:


  1. Mount the 7-inch HDMI touchscreen on the movable top panel.
  2. Use small screws to secure it firmly in place.
  3. The screen will tilt open when the top is lifted, making it easy to interact with or inspect.

Cutouts and Openings:


  1. Webcam opening:
  2. Cut a small hole on the front bottom panel.
  3. This allows the webcam (mounted below it) to see straight out the front.
  4. LCD screen opening:
  5. Cut a rectangular hole in the front panel in one of the corners.
  6. Align it with your mounted 16x2 I²C LCD, so the result text (e.g., “Weak Bicep”) is visible from the outside.

📦 Final Look & Functionality:


  1. From the front the webcam can see you and you can see the lcd and the 7-inch display.


Final Testing

47a91e1e-30bf-4761-a53e-bb8aea250fa2.jpg
b52364d3-b374-4c8f-bffd-39252a2c7d68.jpg
  1. Boot the Raspberry Pi (services start automatically).
  2. Run the Python detection app on your PC.
  3. Open Gradio in your browser.
  4. Try all 3 tabs and verify:
  5. LCD shows label
  6. Correct video plays
  7. Webcam stream + "Take Photo" works

You now have a working AI-powered fitness assistant!