CoolFace
Apppublic

louiecerv/testapp_cats_dogs_torch_nn

sourceHugging Facemitupdated 2y agoView on Hugging Face
0likes
App README

Cats vs Dogs Classifier

This is a simple web application that classifies images of cats and dogs using a pre-trained neural network model. The app is built using Streamlit and PyTorch, and the model is hosted on Hugging Face.

Features

  • —Upload an image of a cat or dog.
  • —The app preprocesses the image and displays the preprocessed version.
  • —The model predicts whether the image is of a cat or a dog and displays the prediction with confidence.

Installation

  1. 1.Clone the repository:
bash
    git clone https://github.com/yourusername/cats_dogs_classifier.git
    cd cats_dogs_classifier
  1. 1.Create a virtual environment and activate it:
bash
    python -m venv venv
    source venv/bin/activate  # On Windows, use `venv\Scripts\activate`
  1. 1.Install the required packages:
bash
    pip install -r requirements.txt
  1. 1.Set your Hugging Face token as an environment variable:
bash
    export HF_TOKEN=your_huggingface_token  # On Windows, use `set HF_TOKEN=your_huggingface_token`

Usage

  1. 1.Run the Streamlit app:
bash
    streamlit run app.py
  1. 1.Open your web browser and go to http://localhost:8501.
  1. 1.Upload an image of a cat or dog, and the app will display the preprocessed image and the prediction.

Code Overview

  • —app.py: The main application file that contains the Streamlit UI and the model loading and prediction logic.
  • —requirements.txt: The list of required Python packages.

Model

The model is a simple neural network defined as follows:

python
class SimpleNN(nn.Module):
    def __init__(self, input_size, n_classes):
        super(SimpleNN, self).__init__()
        self.model = nn.Sequential(
            nn.Flatten(),
            nn.Linear(input_size, 512),  # Input
            nn.ReLU(),  # Activation for input
            nn.Linear(512, 512),  # Hidden
            nn.ReLU(),  # Activation for hidden
            nn.Linear(512, n_classes)  # Output
        )

    def forward(self, x):
        return self.model(x)