Pytorch code for multi-Instance multi-label problem
The objective of this study is to develop a deep learning model that will identify the natural scenes from images. This type of problem comes under multi label image classification where an instance can be classified into multiple classes among the predefined classes.
The Complete dataset description can be found on http://lamda.nju.edu.cn/data_MIMLimage.ashx
The processed data is their in the repo Image_data.zip
The image data set consists of 2,000 natural scene images, where a set of labels is artificially assigned to each image. The number of images belonging to more than one class (e.g. sea+sunset). On average, each image is associated with 1.24 class labels.
The labels.json
file contains the labels in the form of list [1 -1 -1 1 -1], it means that the i-th image belongs to the 1st and 4th classes but do not belong to the 2nd, 3rd and 5th classes. The following is the order of classes desert, mountains, sea, sunset, trees
Download Data
Structure the data
Visulaize the data
Create Data pipeline
Model Definition (RESNET50)
Optimizer(Adam) and Criterion (nn.BCEWithLogitsLoss)
Training
Saving & Loading model
Model Finetuning
10 . Visualizing some end result
Note:- Refer sklearn doc for deeper understanding of the metric
As this is multi label image classification, the loss function was binary crossentropy logit and activation function used was sigmoid at the output layer. so after training there is one probabilistic threshold method which find out the best threshold value for each label seperately and based on the threshold value(0.5)
preds = torch.sigmoid(output).data > 0.5
preds = preds.to(torch.float32)
F1 score | Loss |
---|---|
88.85% | 0.1962 |