This document provides an overview of the CNN components used in the Map Action project. These components are responsible for preprocessing images, configuring the CNN model, and performing image classification.
The preprocessing of images is handled by the cnn_preprocess.py
file. It defines a function preprocess_image
that resizes images to 224x224 pixels, converts them to PyTorch tensors, and optionally normalizes them. This preprocessing is tailored for models expecting input images in this format.
The CNN model is configured in the cnn_model.py
file. It defines a function m_a_model
that initializes and modifies a ResNet50 model for multi-label classification. The model’s fully connected layer is adjusted to match the number of tags to predict.
The image classification process is managed by the cnn.py
file. It integrates the preprocessing and model components to perform multi-label image classification using the ResNet50 model. The file includes functions to load the model and perform predictions on images, returning the top predictions and their probabilities.
preprocess_image:
image
(bytes) - The image data to be processed.m_a_model:
num_tags
(int) - The number of tags to predict.predict:
image
(bytes) - The image data to be classified.For more detailed information on each component, refer to the respective files in the app/services/cnn/
directory.