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
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
- Raspberry Pi 4 (or any compatible model)
- USB Camera
- 16x2 I2C LCD Display
- Power Supply for Raspberry Pi
- MicroSD Card (with Raspberry Pi OS installed)
- Breadboard and Jumper Wires (optional, for connecting LCD)
- HDMI monitor and keyboard (optional, for initial setup)
Software
- Python 3 (pre-installed on Raspberry Pi)
- OpenCV
- PyTorch
- Ultralytics YOLOv8
- SMBus
- Necessary Python libraries: smbus2, RPi.GPIO
Setting Up the Raspberry Pi
- Download and Install Raspberry Pi OS:
- Download Raspberry Pi Imager from the official website.
- Insert the MicroSD card into your computer and use the Imager to install Raspberry Pi OS.
- Insert the MicroSD card into the Raspberry Pi and power it on.
- Initial Setup:
- Connect your Raspberry Pi to a monitor, keyboard, and mouse, or to your computer.
- Setup the settings of your Raspberry Pi.
- Install the necessary libraries
Preparing the Dataset
Download the Dataset:
- Download the book cover dataset from Uchida Labs or another source.
- Download a dataset with images cointaing books, for the detection model
Data Preprocessing:
- Use roboflow to prepare the data and preprocess it.
- Test the dataset using roboflow.
- Remember to keep the data for the classification model and the detection model in two seperate datasets.
My approach:
- 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.
- 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
- For the detection model I download the data from a robflow detection project
Model Selection and Training
Choose a Pre-trained Model:
- Use a pre-trained model like Yolov8 for classification and detection,.
Fine-tune the Model:
- Load the pre-trained model in Python.
- Use the datasets to train the two different models, one for classification and another for detection.
Save the Trained Model:
- After training, save both models in TensorFlow Lite format for deployment on the Raspberry Pi.
My approach:
- 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.
- For the detection model the process was the same as the classification
Final Setup
Write the Prediction Script:
- 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.
- Display the predicted genre on the LCD screen or monitor.
Integrate the Hardware:
- Connect the USB camera to the Raspberry Pi.
- Connect the LCD display or monitor.
- Test the system to ensure everything is working correctly.
My approach:
- 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
- If needed create a smal box or whatever shaped cointainer to hold the components, making the project more organised and visually pleasing