
- 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
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
-
Clone the repository:
git clone <repository-url> cd tomatoseveritysegmentationmodel
-
Install dependencies:
pip install -r requirements.txt
-
Run database migrations:
alembic upgrade head
-
Start the application:
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 imageGET /api/tomatoes
: List all uploaded tomato imagesGET /api/tomatoes/{image_id}
: Get details of a specific imageDELETE /api/tomatoes/{image_id}
: Delete an image and its analysis data
Analysis
POST /api/model/analyze/{image_id}
: Analyze a tomato image for disease severityGET /api/model/results/{image_id}
: Get all analysis results for a specific imageGET /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 metadataanalysis_results
: Stores analysis results for each imageseverity_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
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
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:
- Define models in
app/models/
- Create Pydantic schemas in
app/schemas/
- Add database migrations with Alembic
- Implement routes in
app/api/routes/
- Update tests
License
This project is licensed under the MIT License - see the LICENSE file for details.