Code Monkey home page Code Monkey logo

visual-contrastive-learning-for-few-shot-image-classification's Introduction

Visual Contrastive Learning for Few-shot Image Classification

This repository provides the code to classify images in two different categories, i.e. Similar (1) and Dissimilar (0) based on the image similarity task performed by utilizing a Contrastive Learning-based approach (including employing a custom contrastive loss). Furthermore, Siamese Networks is being used in n-way k-shot settings considered in the current implementation.

Requirements

  • Python 3.9
  • PyTorch 1.10.2
  • TorchVision 0.11.3
  • numpy 1.22.3
  • matplotlib 3.5.1

Usage

Data

Omniglot dataset is being used which is a collection of 1623 hand drawn characters from 50 different alphabets. For every character there are just 20 examples, each drawn by a different person. Each image is a gray scale image of resolution 105x105. Please clone this repo and then extract the images_background and images_evaluation folders. Finally, run DataGeneration.py file to create pickle files train.pickle and val.pickle files and store them in data folder. Here, train.pickle file contains characters from 30 different alphabets, whereas val.pickle contains characters from remaining 20 different alphabets.

Model Building and Training

  • The SiameseNetwork model class for n-way k-shot learning can be found in Model.py file.
  • To train the network, run Training.py file.
  • The average loss for the trained model is printed after every epoch.
  • All hyperparameters to control training and testing of the model are provided in the given Training.py file.

Output Samples

Image Similarity Scores

Image Comparison 1 Image Comparison 2 Image Comparion 3
alt text alt text alt text
Image Comparison 4 Image Comparison 5 Image Comparion 6
alt text alt text alt text
Image Comparison 7 Image Comparison 8 Image Comparion 9 Image Comparison 10
alt text alt text alt text alt text

Results for Image Classification

Image Comparison 1 Image Comparison 2 Image Comparion 3
alt text alt text alt text

Analysis

Among all the 10 comparisons made under Image Similarity Scores sub-section, images 1, 6, and 8 appear more similar, thereby having predicted labels as 1, as shown in the Results for Image Classification sub-section. This way, the current implementation frames the image similarity task as the image classification task.

visual-contrastive-learning-for-few-shot-image-classification's People

Contributors

fork123aniket avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.