Ever wanted to distinguish between majestic big cats like tigers, lions, and leopards? With modern machine learning techniques, specifically using Vision Transformers (ViTs), you can build an image classifier that identifies these fascinating species from images. In this guide, we will take you through the setup, usage, and troubleshooting processes of creating your very own Big Cat Classifier.
Overview of the Big Cat Classifier
The Big Cat Classifier is a remarkable image classification model designed to categorize various species of big cats, including:
- Cheetah
- Jaguar
- Leopard
- Lion
- Tiger
Here’s the accuracy of the model:
Accuracy: 0.9107
Training Process
To harness the power of this model, you will first need to train it. The training process involves working with datasets that contain images of big cats. You can conveniently use Google Colab to streamline this process. Click the following link to open the training notebook:
Open In ColabInference Process
Once the model is trained, you can test its performance on new images by running an inference. Use the following link to access the inference notebook:
Open In ColabUsage Guidelines
To classify an image using the Big Cat Classifier, you can follow these steps:
python
from PIL import Image
import matplotlib.pyplot as plt
from transformers import ViTFeatureExtractor, ViTForImageClassification
def identify_big_cat(img_path: str) -> str:
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]
path_of_the_image = "path/to/your/big_cat_image.jpg"
our_big_cat = identify_big_cat(path_of_the_image)
print(f"Predicted species: {our_big_cat}")
Understanding the Code with an Analogy
Consider the identify_big_cat function as a well-trained zookeeper at a wildlife sanctuary. Here’s how they operate:
- Opening the Cage: When the zookeeper accesses an image, it’s like opening the cage when a visitor wants to see a big cat.
- Getting the Model Ready: The zookeeper has a guidebook, which represents our pre-trained model, ready to recognize the various cats.
- Viewing the Cat: The feature extractor prepares the image for analysis just as if the zookeeper cleans and prepares the environment for a closer look.
- Identifying the Species: After examining the cat, our proficient zookeeper can identify the species using their guidebook by matching observations to descriptions.
Running the Application
You can run the application either without Docker or using Docker. Follow the steps accordingly:
Without Using Docker
- Ensure you have the latest version of Python 3 installed.
- Install the Python dependencies:
pip install -r requirements.txt
streamlit run app.py
Using Docker
- Ensure you have Docker installed.
- Build the Docker image:
docker build -t smaranjitghose/big-cat-classifier:latest .
docker run -t -i -p 8080:8080 --name big-cat-classifier smaranjitghose/big-cat-classifier
Hosting on Heroku
If you’re interested in hosting your application on Heroku, here’s a quick guide:
- Remove any lines exposing a specific port in the Docker container.
- Ensure the startup command is exposed with a variable port number:
ENTRYPOINT [streamlit, run, app.py, --server.port=$PORT]
heroku login -i
heroku create
heroku container:login
heroku container:push web
heroku container:release web
heroku open
Troubleshooting
If you encounter any issues while using the Big Cat Classifier, consider the following troubleshooting suggestions:
- Ensure that your image path is correct.
- Double-check that all necessary dependencies are installed.
- If using Docker, verify that the Docker daemon is running properly.
For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.