This project uses a fine-tuned MobileNetV2 model to classify recycling objects in real-time using a webcam.
Make sure you have the following libraries installed:
- OpenCV
- NumPy
- TensorFlow
- Keras
You can install them using pip:
pip install opencv-python-headless numpy tensorflow kerasThe script captures video from the webcam, processes each frame, and uses a pre-trained MobileNetV2 model to classify the objects into one of 10 recycling categories:
- Plastic
- Glass
- Metal
- Paper
- Cardboard
- Trash
- Battery
- Electronic
- Compost
- Other
-
Load Pre-trained Model: The script uses MobileNetV2 pre-trained on ImageNet and fine-tunes it for classifying recycling objects. The model expects weights to be loaded if available.
Uncomment the following line if you have pre-trained weights saved as
recycling_model.h5:model.load_weights('recycling_model.h5')
-
Run the Script: To start the recycling object detection, simply run the script:
python og_code.py
-
Webcam Feed: The script will open a webcam feed window where it will display the detected object and its confidence score. To quit, press the
qkey.
preprocess_frame(frame): Resizes the frame to 224x224, converts it to an array, preprocesses it using thepreprocess_inputfunction from MobileNetV2, and expands the dimensions to match the input shape of the model.
The model classifies objects into the following classes:
- Plastic
- Glass
- Metal
- Paper
- Cardboard
- Trash
- Battery
- Electronic
- Compost
- Other
- Ensure your webcam is properly connected.
- The frame size for the webcam feed is set to 1240x720. Adjust these settings if necessary.
- This project uses the MobileNetV2 architecture from TensorFlow/Keras.
- OpenCV is used for capturing and displaying the webcam feed.
Feel free to contribute to this project by improving the model, adding new features, or fixing any bugs.
This project is licensed under the MIT License.