File size: 1,797 Bytes
965ab8e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
title: Red Spider Mite Detection (Streamlit)
emoji: 🕷️
colorFrom: green
colorTo: yellow
sdk: streamlit
sdk_version: 1.36.0
app_file: streamlit_app.py
pinned: false
---

# Hugging Face Gradio Demo: Red Spider Mite Detection

This application detects potential red spider mite infections on leaves in videos.

## How it Works

1.  Upload a video or select an example.
2.  Click the "Detect" button.
3.  The application processes every 100th frame.
4.  It uses SAM 2 (Segment Anything Model 2) to generate masks for potential objects.
5.  Masks are filtered based on:
    *   Non-Maximum Suppression (NMS) to remove overlaps.
    *   Aspect Ratio (to remove likely branches).
    *   Color (HSV range check within the mask).
    *   Sharpness (Laplacian variance).
6.  Segments passing all filters are classified as 'Infected' or 'Not Infected' using a fine-tuned MobileNetV3 model.
7.  Results are displayed in two galleries:
    *   Top: Cropped images of the filtered leaf segments with their classification.
    *   Bottom: Full processed frames showing bounding boxes around detected infected leaves.

## Setup (Local)

1.  Ensure Python 3.9+ is installed.
2.  Clone the repository (if not already done).
3.  Install dependencies: `pip install -r requirements.txt`
4.  Run the app: `python app.py`
5.  Open the local URL provided in your browser.

## Files

*   `app.py`: Main Gradio application script.
*   `requirements.txt`: Python dependencies.
*   `checkpoints/`: Contains the SAM 2 model checkpoint.
*   `models/`: Contains the classification model.
*   `sam2/`: Contains the necessary SAM 2 library source code.
*   `test_videos/`: Contains example videos for the demo.
*   `README.md`: This file.
*   `LICENSE`: Copied license file.
*   `.gitignore`: Standard Python gitignore.