Automated Action ab0e9b973a Implement tomato severity segmentation model API
- Set up FastAPI project structure with SQLite database
- Create database models for tomato images and severity classifications
- Implement image upload and processing endpoints
- Develop a segmentation model for tomato disease severity detection
- Add API endpoints for analysis and results retrieval
- Implement health check endpoint
- Set up Alembic for database migrations
- Update project documentation
2025-05-27 06:22:15 +00:00

142 lines
3.6 KiB
Markdown

# Tomato Severity Segmentation Model API
A FastAPI-based application for detecting and analyzing disease severity in tomato plants using image segmentation techniques.
## Overview
This API allows users to upload tomato plant images and analyze them for various diseases and their severity. The system uses a segmentation model to identify affected areas and classify the severity of diseases such as early blight, late blight, bacterial spot, and septoria leaf spot.
## Features
- **Image Upload**: Upload tomato plant images for analysis
- **Disease Detection**: Identify multiple disease types in a single image
- **Severity Classification**: Classify the severity of detected diseases
- **Segmentation Maps**: Generate segmentation maps highlighting affected areas
- **Health Monitoring**: Built-in health endpoint for monitoring application status
## Installation
### Prerequisites
- Python 3.8+
- pip (Python package manager)
### Setup
1. Clone the repository:
```bash
git clone <repository-url>
cd tomatoseveritysegmentationmodel
```
2. Install dependencies:
```bash
pip install -r requirements.txt
```
3. Run database migrations:
```bash
alembic upgrade head
```
4. Start the application:
```bash
uvicorn main:app --reload
```
The API will be available at `http://localhost:8000`
## API Endpoints
### Health Check
- `GET /health`: Check the health of the application
### Image Management
- `POST /api/tomatoes/upload`: Upload a tomato image
- `GET /api/tomatoes`: List all uploaded tomato images
- `GET /api/tomatoes/{image_id}`: Get details of a specific image
- `DELETE /api/tomatoes/{image_id}`: Delete an image and its analysis data
### Analysis
- `POST /api/model/analyze/{image_id}`: Analyze a tomato image for disease severity
- `GET /api/model/results/{image_id}`: Get all analysis results for a specific image
- `GET /api/model/info`: Get information about the segmentation model
## Database Schema
The application uses SQLite with the following main tables:
- `tomato_images`: Stores uploaded image metadata
- `analysis_results`: Stores analysis results for each image
- `severity_details`: Stores detailed severity data for each analysis
## Segmentation Model
The current implementation uses conventional computer vision techniques for segmentation as a proof of concept. In a production environment, this would be replaced with a trained deep learning model like U-Net or DeepLabV3.
The model classifies the following disease categories:
- Healthy
- Early Blight
- Late Blight
- Bacterial Spot
- Septoria Leaf Spot
## Example Usage
### Upload an image
```bash
curl -X POST "http://localhost:8000/api/tomatoes/upload" \
-H "accept: application/json" \
-H "Content-Type: multipart/form-data" \
-F "file=@tomato_plant.jpg"
```
### Analyze the image
```bash
curl -X POST "http://localhost:8000/api/model/analyze/{image_id}" \
-H "accept: application/json"
```
## Development
### Project Structure
```
tomatoseveritysegmentationmodel/
├── app/
│ ├── api/
│ │ └── routes/
│ ├── core/
│ ├── db/
│ ├── models/
│ ├── schemas/
│ ├── services/
│ └── utils/
├── migrations/
├── storage/
│ ├── db/
│ ├── images/
│ └── models/
├── alembic.ini
├── main.py
└── requirements.txt
```
### Adding New Features
To add new features:
1. Define models in `app/models/`
2. Create Pydantic schemas in `app/schemas/`
3. Add database migrations with Alembic
4. Implement routes in `app/api/routes/`
5. Update tests
## License
This project is licensed under the MIT License - see the LICENSE file for details.