lbrejon / Localization-of-Asian-hornets-with-CNN-using-CAM

Detection and localization of Asian hornets with a CNN using PyTorch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Localization-of-Asian-hornets-with-CNN-using-CAM

Detection and localization of Asian hornets using PyTorch

Table of contents πŸ“

Estimated reading time : ⏱️ 2min

My goals 🎯

  • Deepen knowledge in Computer Vision with CNNs (ResNet18)
  • Learn how to fine-tune and train a model to classify elements (Asian hornets detection)
  • Localize elements (Asian hornets) with Class Activation Mapping (CAM)

Technologies πŸ–₯️

Programming languages:

- Python (framework PyTorch)

Project composition πŸ“‚

.
β”œβ”€β”€ README.md
β”‚
β”œβ”€β”€ data
β”‚   β”œβ”€β”€ test
β”‚   β”‚   β”œβ”€β”€ presence
β”‚   β”‚   β”‚    β”œβ”€β”€ img1.jpg
β”‚   β”‚   β”‚    β”œβ”€β”€ img7.jpg
β”‚   β”‚   β”‚    └──  ..
β”‚   β”‚   β”‚
β”‚   β”‚   └── absence
β”‚   β”‚        β”œβ”€β”€ img2.jpg
β”‚   β”‚        β”œβ”€β”€ img5.jpg
β”‚   β”‚        └──  ..
β”‚   β”‚
β”‚   └── train
β”‚       β”‚    β”œβ”€β”€ img3.jpg
β”‚       β”‚    β”œβ”€β”€ img4.jpg
β”‚       β”‚    └──  ..
β”‚       β”‚
β”‚       └── absence
β”‚            β”œβ”€β”€ img6.jpg
β”‚            β”œβ”€β”€ img8.jpg
β”‚            └──  ..
β”‚
β”œβ”€β”€ models
β”‚   └── model.ckpt
β”‚
└── notebooks
    β”œβ”€β”€ CustomDataSet.py
    └── main.ipynb

Description πŸ“‹

  • The Asian hornet is a highly invasive bee predator that arrived in France by boat in a shipment from Asia in the early 2000s. While this invader exterminates gradually the bees of their apiaries, the beekeepers have only few means to to fight them. The objective of this project is to develop a method to automatically detect an Asian hornet in an image from a camera installed at the entrance of a hive

  • In order to make the classification phase as efficient as possible (class 0: "hornet presence", class 1: "hornet absence"), the CNN (pre-trained on ImageNet) was fine-tuned with the hornet dataset. An annotated database is available in the data/ folder (download data here). To fine-tune the model, the fully connected nodes at the end of the network (where the actual class label predictions are made) was replaced with initialized ones: resnet.fc = nn.Linear(resnet.fc.in_features, 2). In this project, I seek to classify images with the presence/abscene of an Asian hornet that's why out_features=2.

  • In my case, I decided to work with a ResNet18 because of its good performances. During the training phase, the hyper-parameters have been chosen so that they do not induce under-learning or over-learning. Indeed, the training loss gradually dropped (the model learned more efficiently) whereas the validation accuracy increased from 0.7 to almost 0.90.



[Figure 1]: Training loss and validation accuracy graph

  • Once the training model was completed, the model spots (predicts) whether or not there was an Asian hornets in the image as shown in Figure 2.



[Figure 2]: Prediction (absence:0, presence:1)

  • Let's focus on hornets localization in the image using Class Activation Mapping (CAM). CNNs have led to impressive performance on a variety of visual recognition tasks and especially the remarkable ability to localize object and to identify exactly which regions of an image are being used for discrimination. A class activation map for a particular category indicates the discriminative image regions used by the CNN to identify that category.



[Figure 3]: Localization of Asian hornets with CAM

Sources βš™οΈ

About

Detection and localization of Asian hornets with a CNN using PyTorch


Languages

Language:Jupyter Notebook 99.9%Language:Python 0.1%