File size: 4,883 Bytes
29f6ccc
fd9cdee
29f6ccc
 
 
 
 
 
3ce4bfc
de71074
fd9cdee
 
29f6ccc
 
1b858e0
 
 
 
 
 
 
 
64dcedf
1b858e0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64dcedf
1b858e0
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
---
title: Image Classifier With CNN
emoji: πŸš€
colorFrom: red
colorTo: red
sdk: docker
app_port: 8501
tags:
  - streamlit
pinned: true
short_description: A CNN-based image classification with TensorFlow
license: mit
---

# πŸ–ΌοΈ Image Classification with ResNet50

## Table of Contents

1. [Project Description](#1-project-description)
2. [Methodology & Key Features](#2-methodology--key-features)
3. [Technology Stack](#3-technology-stack)
4. [Deployment Options](#4-deployment-options)
5. [Model](#5-model)

## 1. Project Description

This project implements an **image classification system** using a pre-trained **ResNet50 CNN** (trained on ImageNet with 1,000+ categories).

The repository includes **two versions**:

1. **Full Architecture (local, Dockerized):**

   - Built as a **multi-service ML system** with FastAPI (backend inference), Redis (queue/cache), and Streamlit (frontend).
   - Designed to demonstrate a scalable, production-like workflow.

2. **Lightweight Streamlit App (deployed):**
   - Adapted into a **single Streamlit app** for cost-effective deployment on **Hugging Face Spaces**.
   - Lets users upload an image and instantly see the **predicted category** with confidence.

This dual approach allows others to explore both a **realistic ML architecture** and a **lightweight, deployable demo**.

> [!IMPORTANT]
>
> - Check out the deployed app here: πŸ‘‰οΈ [Image Classification App](https://huggingface.co/spaces/iBrokeTheCode/Image_Classifier_with_CNN) πŸ‘ˆοΈ
> - Check out the source code for multi-service setup: πŸ‘‰οΈ [Multi-Service - Source Code](https://huggingface.co/spaces/iBrokeTheCode/Image_Classifier_with_CNN/tree/main) πŸ‘ˆοΈ
> - Check out the source code for lightweight Streamlit App: πŸ‘‰οΈ [Lightweight App - Source Code](https://huggingface.co/spaces/iBrokeTheCode/Image_Classifier_with_CNN/tree/main/src) πŸ‘ˆοΈ

![App Demo](./src/assets/app-demo.jpg)

## 2. Methodology & Key Features

- **Model:** ResNet50 (pre-trained on **ImageNet** with 1,000+ classes).
- **Pipeline:** Input images are resized, normalized, and passed to the model.
- **Output:** Top-1 prediction with **confidence score** is displayed.
- **Multi-service architecture:**
  - **FastAPI** serves inference requests.
  - **Redis** handles caching and task queueing.
  - **Streamlit** provides the interactive UI.
- **Lightweight deployment:** Direct **Streamlit-only** version for Hugging Face Spaces.

## 3. Technology Stack

This project was built using the following technologies:

**Deployment & Hosting:**

- [Docker](https://www.docker.com/) – containerization for the full architecture.
- [Hugging Face Spaces](https://huggingface.co/docs/hub/spaces) – for lightweight deployment.
- [Streamlit](https://streamlit.io/) – interactive web app frontend.

**Backend & Infrastructure:**

- [FastAPI](https://fastapi.tiangolo.com/) – high-performance inference API.
- [Redis](https://redis.io/) – caching and message queue.

**Modeling & Training:**

- [TensorFlow / Keras](https://www.tensorflow.org/) – ResNet50 model (pre-trained on ImageNet).

**Development Tools:**

- [Ruff](https://github.com/charliermarsh/ruff) – Python linter and formatter.
- [uv](https://github.com/astral-sh/uv) – fast Python package installer and resolver.

## 4. Deployment Options

You can run this project in two ways:

### A. Run the Lightweight Version (Streamlit-only)

1. Clone the repo:

   ```bash
   git clone https://huggingface.co/spaces/iBrokeTheCode/Image_Classifier_with_CNN

   cd Image_Classifier_with_CNN
   ```

2. Install dependencies:

   ```bash
   pip install -r requirements.txt
   ```

3. Run the app:

   ```bash
   streamlit run src/streamlit_app.py
   ```

### B. Run the Full Architecture (Dockerized)

The repository also contains **Dockerfiles** for each service.

1. Clone the repo:

   ```bash
    git clone https://huggingface.co/spaces/iBrokeTheCode/Image_Classifier_with_CNN

   cd Image_Classifier_with_CNN
   ```

2. Pre-configure your environment variables:

   ```bash
   cp .env.original .env
   ```

3. Create a network for containers

   ```bash
   docker network create shared_network
   ```

4. Build and start all services:

   ```bash
   docker compose up --build -d

   # Stop services
   docker compose down
   ```

5. Populate the database

   ```bash
   cd api
   cp .env.original .env
   docker-compose up --build -d
   ```

6. Access the app at:

   ```
   http://localhost:9090
   ```

   Then use this credentials to pass the login:

   - Username: admin@example.com
   - Password: admin

7. Access the FastAPI app at:

   ```
   http://localhost:8000/docs
   ```

## 5. Model

This project uses the pre-training model ResNet50.

- **Model:** [ResNet50](https://www.tensorflow.org/api_docs/python/tf/keras/applications/ResNet50)
- **Classes:** 1,000+ categories (objects, animals, everyday items).