Smart Book Genre Identifier: Classify Books by Their Covers Using AI

by RodrigoSousa in Living > Education

69 Views, 2 Favorites, 0 Comments

Smart Book Genre Identifier: Classify Books by Their Covers Using AI

image_2024-06-18_133010304.png

The Smart Book Genre Identifier uses AI to automatically identify the genre of a book just by analyzing its cover. Whether you're a librarian, bookseller, or book lover, this project will help you quickly organize your book collection.

Why Did I Make This? I created this project to solve a common problem: the time-consuming task of manually sorting books by genre. By automating this process, I aimed to make it easier for anyone with a large book collection to manage their inventory efficiently.

What Is This Project? The Smart Book Genre Identifier is a simple device powered by a Raspberry Pi and a USB camera, with an lcd. It uses a trained AI model to predict a book's genre based on its cover image. Just place a book in front of the camera, and the device will tell you its genre.

How Did I Make It? I combined the Raspberry Pi with machine learning tools. I trained a model using a dataset of book covers, fine-tuned it for genre recognition, and optimized it to run smoothly on the Raspberry Pi.

This guide will take you through each step to build your own Smart Book Genre Identifier. By the end, you'll have a handy tool that simplifies book categorization with just a snap of a picture!

Supplies

Hardware

  1. Raspberry Pi 4 (or any compatible model)
  2. USB Camera
  3. 16x2 I2C LCD Display
  4. Power Supply for Raspberry Pi
  5. MicroSD Card (with Raspberry Pi OS installed)
  6. Breadboard and Jumper Wires (optional, for connecting LCD)
  7. HDMI monitor and keyboard (optional, for initial setup)

Software

  1. Python 3 (pre-installed on Raspberry Pi)
  2. OpenCV
  3. PyTorch
  4. Ultralytics YOLOv8
  5. SMBus
  6. Necessary Python libraries: smbus2, RPi.GPIO

Setting Up the Raspberry Pi


  1. Download and Install Raspberry Pi OS:
  2. Download Raspberry Pi Imager from the official website.
  3. Insert the MicroSD card into your computer and use the Imager to install Raspberry Pi OS.
  4. Insert the MicroSD card into the Raspberry Pi and power it on.
  5. Initial Setup:
  6. Connect your Raspberry Pi to a monitor, keyboard, and mouse, or to your computer.
  7. Setup the settings of your Raspberry Pi.
  8. Install the necessary libraries

Preparing the Dataset

Download the Dataset:

  1. Download the book cover dataset from Uchida Labs or another source.
  2. Download a dataset with images cointaing books, for the detection model

Data Preprocessing:

  1. Use roboflow to prepare the data and preprocess it.
  2. Test the dataset using roboflow.
  3. Remember to keep the data for the classification model and the detection model in two seperate datasets.

My approach:

  1. I first downloaded the dataset to my local laptop, and then to google drive. After that I used the attached code do download the data to the google colab enviornment where I trained the model.
  2. For the classification model I organized the 30 available genres into 2 major genres to make it easier for the model to classify with greater accuracy
  3. For the detection model I download the data from a robflow detection project

Model Selection and Training

Choose a Pre-trained Model:

  1. Use a pre-trained model like Yolov8 for classification and detection,.

Fine-tune the Model:

  1. Load the pre-trained model in Python.
  2. Use the datasets to train the two different models, one for classification and another for detection.

Save the Trained Model:

  1. After training, save both models in TensorFlow Lite format for deployment on the Raspberry Pi.

My approach:

  1. For the classification model I wrote a code to agument and improve the data for training, and after used a yolov8 model to trian my model.
  2. For the detection model the process was the same as the classification


Final Setup

IMG-1304.jpg
IMG-1305.jpg

Write the Prediction Script:

  1. Create a Python script that loads the trained model, captures an image from the USB camera, and predicts the genre based on the book cover.
  2. Display the predicted genre on the LCD screen or monitor.

Integrate the Hardware:

  1. Connect the USB camera to the Raspberry Pi.
  2. Connect the LCD display or monitor.
  3. Test the system to ensure everything is working correctly.

My approach:

  1. I created a python script on my raspberry pi thats uses both models, but only when the detection model has a confidence of more than 80% does it classify the book.

Final Optional Step

IMG-1306.jpg
  1. If needed create a smal box or whatever shaped cointainer to hold the components, making the project more organised and visually pleasing