File size: 5,600 Bytes
e435266
44d1643
 
e435266
 
 
44d1643
 
 
 
 
 
 
 
e435266
 
44d1643
30d5634
44d1643
30d5634
44d1643
1bdf0ed
44d1643
 
 
 
 
1bdf0ed
44d1643
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30d5634
 
 
 
 
44d1643
 
 
 
 
30d5634
44d1643
30d5634
44d1643
 
 
30d5634
 
44d1643
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1bdf0ed
 
44d1643
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
---
title: NemaQuant
emoji: πŸ”¬
colorFrom: indigo
colorTo: blue
sdk: docker
license: apache-2.0
short_description: "YOLO-based nematode egg detection with real-time processing"
tags:
  - microscopy
  - object-detection
  - yolo
  - biology
  - image-processing
---

# NemaQuant Flask App

A modern web application for automated nematode egg detection and counting using deep learning. This application provides an intuitive interface to process microscope images and identify nematode eggs using the YOLO object detection model.

## Quick Performance Guide
- **Free Tier** (2 vCPU): 100 images β‰ˆ 6-7 minutes
- **CPU Upgrade** ($0.03/hr): 3-4x faster
- **GPU Option** ($0.40/hr): 8-10x faster

Process 500 images for:
- FREE on basic tier (β‰ˆ 35 min)
- $0.005 with CPU upgrade (β‰ˆ 10 min)
- $0.03 with GPU (β‰ˆ 4 min)

## Features

- **Multiple Input Modes**:
  - Single image processing
  - Batch processing of multiple images
  - Directory/folder processing
- **Real-time Progress Tracking**: Monitor processing progress for large batches
- **Interactive Results**:
  - Sortable results table
  - Pagination for large datasets
  - Export functionality for annotated images
- **Flexible Image Support**:
  - Supports PNG, JPG, JPEG, TIF, and TIFF formats
  - Automatic conversion of TIF/TIFF to PNG for web viewing
- **Confidence Threshold Adjustment**: Fine-tune detection sensitivity
- **Batch Export**: Download all annotated images as a ZIP file

## Project Structure

```
/
β”œβ”€β”€ app.py                  # Flask application with REST endpoints and core logic
β”œβ”€β”€ nemaquant.py           # YOLO-based image analysis script
β”œβ”€β”€ requirements.txt       # Python dependencies
β”œβ”€β”€ Dockerfile            # Container configuration
β”œβ”€β”€ README.md            
β”œβ”€β”€ templates/
β”‚   └── index.html        # Modern, responsive web interface
β”œβ”€β”€ static/
β”‚   β”œβ”€β”€ style.css        # CSS styling
β”‚   └── script.js        # Frontend interactivity and async processing
└── weights.pt           # YOLO model weights (required)
```

## Technical Requirements

- Python 3.9+
- Key Dependencies:
  - Flask >= 2.0.0
  - PyTorch >= 2.0.0
  - Ultralytics >= 8.0.0
  - OpenCV Python >= 4.7.0
  - Pandas >= 1.5.0
  - NumPy >= 1.21.0

## Setup and Deployment

### Local Development

1. **Clone the Repository**:
   ```bash
   git clone <repository-url>
   cd nemaquant-flask
   ```

2. **Install Dependencies**:
   ```bash
   pip install -r requirements.txt
   ```

3. **Prepare Model Weights**:
   - Place your `weights.pt` file in the root directory
   - Ensure it's a compatible YOLO model trained for egg detection

4. **Run the Application**:
   ```bash
   python app.py
   ```
   The application will be available at `http://localhost:7860`

### Docker Deployment

1. **Build the Container**:
   ```bash
   docker build -t nemaquant-flask .
   ```

2. **Run the Container**:
   ```bash
   docker run -p 7860:7860 -v $(pwd)/results:/app/results nemaquant-flask
   ```

### Hugging Face Spaces Deployment

1. Create a new Space on [Hugging Face](https://huggingface.co/new-space)
2. Select Docker as the SDK
3. Configure the Space:
   - Set app_port to 7860
   - Enable Git LFS for the weights file
4. Push your code:
   ```bash
   git lfs install
   git lfs track "*.pt"
   git add .gitattributes weights.pt
   git add .
   git commit -m "Initial deployment"
   git push
   ```

## Usage

1. **Select Input Mode**:
   - Choose between single image, multiple images, or folder processing
   - For folder mode, ensure images follow the expected structure

2. **Upload Images**:
   - Drag and drop or use the file browser
   - Supported formats: PNG, JPG, JPEG, TIF, TIFF

3. **Configure Processing**:
   - Adjust confidence threshold if needed (default: 0.6)
   - Click "Process Images" to start

4. **View Results**:
   - Monitor real-time progress
   - View detected egg counts in the results table
   - Sort and paginate through results
   - Download annotated images individually or as a batch

## Processing Time & Cost Estimates

### Free Tier (CPU Basic - 2 vCPU, 16GB RAM)
- **Processing Time**:
  - 19 images: ~1:13 (actual measured time)
  - 100 images: ~6-7 minutes
  - 500 images: ~30-35 minutes
- **Cost**: FREE
- **Limitations**: 
  - Slower processing speed
  - 48 hour inactivity timeout
  - Shared resources may affect performance
  - Processing time may increase with server load

### CPU Upgrade Option (8 vCPU, 32GB RAM)
- **Processing Time** (estimated 3-4x faster than free tier):
  - 100 images: ~2 minutes
  - 500 images: ~10 minutes
- **Cost**:
  - $0.03/hour for CPU Upgrade
  - Estimated cost for 100 images: ~$0.001
  - Estimated cost for 500 images: ~$0.005 (0.17 hours * $0.03/hour)

### GPU Options (Optional)
- **Nvidia T4 Small (4 vCPU, 16GB VRAM)**:
  - Processing Time (estimated 8-10x faster than free tier):
    - 100 images: ~45 seconds
    - 500 images: ~4 minutes
  - Cost: $0.40/hour (~$0.01 for 100 images, ~$0.03 for 500 images)

**Note**: These estimates are approximate and may vary based on:
- Image size and complexity
- Server load and availability
- Network conditions for upload/download
- Time of day (free tier performance varies with overall platform usage)

For most users, the free tier is sufficient for small to medium batches (< 200 images), while the CPU upgrade offers a good balance of cost and performance for larger datasets. GPU options are recommended only for time-sensitive processing of large batches or when processing thousands of images.

## License

[Specify your license here]