Skip to content

Latest commit

 

History

History
122 lines (82 loc) · 5.33 KB

README.md

File metadata and controls

122 lines (82 loc) · 5.33 KB

BIOSCAN - IMAGE FILTER

A specialized image filtering tool that categorizes images into 'good' and 'bad' based on insect visibility, reducing the need for manual labeling while enhancing overall robustness.

Overview

Overview

The image filtering tool leverages a pre-trained ResNet-18 CNN to automatically classify images as "good" or "bad" based on bounding box accuracy, resolution, and fragmentation. By automating the annotation process, it enhances efficiency and consistency in large-scale datasets, minimizing manual labeling. This ensures dataset integrity by filtering out invalid images, which is crucial for training high-quality machine learning models. ResNet-18’s proven robustness guarantees precise classification, making this tool indispensable for streamlined data preparation and reliable model performance.

The Dataset

The filtering tool has been trained on 1172 images from the "failed crop dataset" subset from Bioscan-1M, focusing on images that failed initial cropping attempts. This allows us to tackle the most challenging instances where our current image processing pipeline may struggle, whether due to genuine quality issues or processing failures. Some images may be easily identifiable while others may be of poor quality. Integrating this dataset aims to improve the overall performance and accuracy of our image processing system, ensuring robustness across diverse image types and conditions.

Failed crop dataset - subset of images
Failed crop subset

i) Annotations

The dataset has been annotated to include bounding boxes identifying objects. Every image containing any object, regardless of its quality, size, or type, is annotated with a bounding box. Only completely empty dish images are not annotated with a bounding box.

ii) Good vs Bad image distinction

Good images are classified as having all of the following characteristics:

  • Bounded object (image with a valid bounding box)
  • Clear resolution
  • Whole/not fragmented

Good Images

Bad images are classifed as having any of the following characteristics:

  • Unbounded objects (image without a bounded object)
  • Blurry resolution
  • Fragmented (ie: majority of the image is cut off, only a wing/leg depicted, etc)

Bad Images

iii) Data Preprocessing Pipeline

Sample Dataset

The dataset initially consisted of mixed "good" and "bad" images. The images were processed through the following steps:

1) Cropping - bounding box evaluation:

  • No Bounding Box: Classified as "bad" (no insects).
  • Bounding Box Present: Cropped to the bounding box to focus on the insect.

2) Resolution evaluation:

  • Blurry Images: Classified as "bad".
  • Clear Images: Mapped to their respective uncropped image versions for the next step.

3) Fragmentation evaluation:
Note: Fragmentation detection classifies an insect as fragmented if it is too small or located on the edge of the image. Therefore, the uncropped, original versions of the previously cropped clear images are needed for this evaluation.

  • Fragmented/Cut-off Insects: Classified as "bad".
  • Whole/Mostly Visible Insects: Classified as "good".

Finally, all "bad" images are stored in the bad_images directory, while images that passed all checks are stored in the good_images directory.


The Model

The ResNet-18 CNN, pretrained on the ImageNet dataset was used for binary classification. ResNet-18 is less computationally intensive and faster to train compared to deeper versions, making it a suitable choice for binary classification tasks, which typically do not require extremely deep networks.

i) Performance

The model demonstrates robust performance, achieving high accuracy and F1 scores (approximately 90% each) with correspondingly low losses for both the training and validation splits, indicating effective learning and reliable real-world performance.

Performance


Implement Tool

1. Setup Environment

Download Anaconda onto your computer

conda create -n Bioscan-ImgFilter python=3.10
conda activate Bioscan-ImgFilter
pip install -r requirements.txt 

2. Train and evaluate the model

The model is trained over 937 labeled images and validated over 237 previously unseen images that have been classified as good/bad.

Training with wandb ENABLED

python scripts/training.py --use_wandb True 
  • 2.1) Activate wandb
    Register/Login for a free wandb account
    This enables tracking of training and evaluation metrics over time.
    wandb login
    # Paste your wandb API key

Training with wandb DISABLED

python scripts/training.py

3. To view the model's inference

An image randomly chosen from the validation set is classified as either 'good' or 'bad' based on the model's prediction. The resulting classification and corresponding image are displayed, offering visual confirmation of the model's accuracy.

python scripts/inference.py 


Other pre-trained models to try:

Model Link
Content Cell Content Cell
Content Cell Content Cell