Giter VIP home page Giter VIP logo

smaranjitghose / big_cat_classifier Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 1.0 76.11 MB

Using Visual Transformers to train a basic image classification model to classify images of lions, tigers, cheetahs, tigers and leopards

Home Page: https://huggingface.co/smaranjitghose/big-cat-classifier

License: MIT License

Jupyter Notebook 99.96% Python 0.03% Dockerfile 0.01%
visual-transformers big-cats big-cat-classifer huggingface huggingface-transformers pytorch pytorch-lightning image-classification deep-learning computer-vision

big_cat_classifier's Introduction

An image classifier built using Vision Transformers that categories images of the big cats into the following classes:

  1. Cheetah
  2. Jaguar
  3. Leopard
  4. Lion
  5. Tiger

Note:

  • Since jaguars and leopards have similar appearances, the model might confuse the two. These [1] [2] two articles throw some light on the difference between the two species.
  • Theoretically the model should be able to accurately identify geographical population variants of each species. However, in practical scenarios this may not be true as during the training phases this was not kept in mind while collecting the dataset.
    • For example: images of Bengal Tigers, Siberian Tigers, Indochinese Tigers, and Malayan Tigers should be identified as Tigers
  • Lastly, the performance of the model in categorizing certain rare variants in the populations of big cats such as white tigers, snow leopards, or black panther has not been determined exclusively. Although some of the tests performed gave satisfactory results.

Training and Inference

Training: Open In Colab

Inference: Open In Colab

Usage

from PIL import Image
import matplotlib.pyplot as plt
from transformers import ViTFeatureExtractor, ViTForImageClassification

def identify_big_cat(img_path:str)->str:
  """
  Function that reads an image of a big cat (belonging to Panthera family) and returns the corresponding species
  """
  img = Image.open(img_path)
  model_panthera = ViTForImageClassification.from_pretrained("smaranjitghose/big-cat-classifier")
  feature_extractor = ViTFeatureExtractor.from_pretrained('smaranjitghose/big-cat-classifier')
  inputs = feature_extractor(images=img, return_tensors="pt")
  outputs = model_panthera(**inputs)
  logits = outputs.logits
  predicted_class_idx = logits.argmax(-1).item()
  return model_panthera.config.id2label[predicted_class_idx]


 our_big_cat = identify_big_cat("path_of_the_image")
 print(f"Predicted species: {our_big_cat}" )

Hosted API:

Check it out here

Library App Usage:

  • Clone this repository
git clone https://github.com/smaranjitghose/Big_Cat_Classifier.git
  • Move inside the cloned repository
cd Big_Cat_Classifier
  • Now follow either of following two routes:

A) Without using Docker:

Make sure you have installed the latest stable version Python 3 and added it to PATH

  • Install the python dependencies
pip install -r requirements.txt
  • Start the streamlit app on local server
streamlit run app.py

B) Using Docker:

Make sure you have installed Docker

  • Build the Docker Image
docker build -t smaranjitghose/big-cat-classifier:latest .
  • Check if the image is available
docker images
  • Create a Docker container from the image and Run it
docker run -t -i -p 8080:8080 --name "big-cat-classifier" smaranjitghose/big-cat-classifier
  • Open your browser and visit localhost:8080

Streamlit App

Hosting

  1. Heroku
  • Remove the lines that exposed the particular port in the docker container
  • Make sure the startup command is exposed with a variable Port Number
ENTRYPOINT ["streamlit", "run", "app.py", "--server.port=$PORT"]
  • Login to Heroku
heroku login -i
  • Create a new Heroku app
heroku create
  • Login in to Container Registry
heroku container:login
  • Build the Docker image and push it to Container Registry
heroku container:push web
  • Release the app
heroku container:release web
  • Check the hosted version and dashboard
heroku open

Reference and Acknowledgement:

Hugging Pics

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.