An AI-powered web application for detecting fish diseases from images using an InceptionV3 deep learning model.
- π€ AI-Powered Detection: Uses InceptionV3 model trained for fish disease classification
- β‘ FastAPI Backend: High-performance REST API with automatic documentation
- π¨ Modern Web Interface: Responsive, user-friendly interface with drag-and-drop support
- π Real-time Analysis: Instant predictions with confidence scores
- π Non-Fish Detection: Intelligent filtering to reject non-fish images
- π Multiple Disease Classes: Detects 7 different fish diseases
- Bacterial Red disease
- Bacterial diseases - Aeromoniasis
- Bacterial gill disease
- Fungal diseases Saprolegniasis
- Healthy Fish
- Parasitic diseases
- Viral diseases White tail disease
- Python 3.8 or higher
- Model file:
inceptionv3_fish_final.h5(should be in/Users/riyadafromspace/Documents/)
# Navigate to project directory
cd /Users/riyadafromspace/Documents/api_integration
# Create virtual environment
python3 -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt# Create virtual environment
python3 -m venv venv
source venv/bin/activate # On macOS/Linux
# or
venv\Scripts\activate # On Windows
# Install required packages
pip install fastapi uvicorn tensorflow pillow python-multipart numpy# Make sure virtual environment is activated
source venv/bin/activate
# Run the server
python main.pyOr using uvicorn directly:
uvicorn main:app --reload --host 0.0.0.0 --port 8000- Web Interface: http://localhost:8000
- API Documentation: http://localhost:8000/docs
- Alternative Docs: http://localhost:8000/redoc
curl http://localhost:8000/healthResponse:
{
"status": "healthy",
"model_loaded": true,
"num_classes": 7
}Using cURL:
curl -X POST "http://localhost:8000/predict" \
-H "Content-Type: multipart/form-data" \
-F "file=@/path/to/fish/image.jpg"Using Python:
import requests
url = "http://localhost:8000/predict"
files = {'file': open('fish_image.jpg', 'rb')}
response = requests.post(url, files=files)
print(response.json())Response:
{
"success": true,
"predicted_class": "Bacterial gill disease",
"confidence": 0.8523,
"confidence_percentage": "85.23%",
"is_fish": true,
"is_uncertain": false,
"entropy": 0.42,
"top_2_diff": 0.65,
"image_std": 45.3,
"all_predictions": [...],
"message": "Bacterial gill infection detected..."
}curl http://localhost:8000/classes- Open http://localhost:8000 in your browser
- Upload a fish image by clicking or dragging and dropping
- Analyze the image by clicking the "Analyze Image" button
- View detailed results including:
- Disease prediction
- Confidence score
- Treatment recommendations
- All class probabilities
By default, the model is loaded from:
/Users/riyadafromspace/Documents/inceptionv3_fish_final.h5
To change the model location, update main.py:
MODEL_PATH = os.getenv("MODEL_PATH", "/path/to/your/model.h5")Adjust detection sensitivity in main.py (around line 165):
is_non_fish = (
(confidence < 0.40) or # Minimum confidence threshold
(confidence < 0.55 and normalized_entropy > 0.75) or
(img_std < 15) or # Image uniformity threshold
(confidence < 0.50 and top_2_diff < 0.15)
)api_integration/
βββ main.py # FastAPI application
βββ requirements.txt # Python dependencies
βββ README.md # This file
βββ .env.example # Environment variables template
βββ .gitignore # Git ignore rules
βββ run.sh # Quick start script (Unix)
βββ setup.sh # Setup script (Unix)
βββ static/
β βββ index.html # Web interface
β βββ style.css # Styling
β βββ script.js # Client-side logic
βββ venv/ # Virtual environment (created on setup)
The system uses multiple indicators to detect non-fish images:
- Confidence Score: Model's certainty (< 40% = likely not fish)
- Entropy: Prediction uncertainty (high entropy = random/confused)
- Image Uniformity: Pixel variance (too uniform = solid color/pattern)
- Prediction Spread: Gap between top predictions (small gap = confused)
- Convert to RGB (if needed)
- Resize to 224x224 pixels
- Apply InceptionV3 preprocessing (scales to -1 to 1)
- Add batch dimension for model input
- Upload image via web interface or API
- Validate file type
- Preprocess image
- Predict using InceptionV3 model
- Validate if image is actually a fish
- Return results with confidence scores and recommendations
Issue: Model not loaded error
Solutions:
- Check model file path in
main.py - Ensure model file exists:
ls -lh /Users/riyadafromspace/Documents/inceptionv3_fish_final.h5 - Verify file permissions
Issue: Port already in use
Solutions:
# Find process using port 8000
lsof -ti:8000
# Kill the process
kill -9 $(lsof -ti:8000)
# Or use a different port
uvicorn main:app --port 8001Issue: Real fish images rejected
Solutions:
- Check image quality (blur, lighting, resolution)
- Review server logs for metrics
- Lower confidence threshold in
main.py
Issue: All predictions < 50%
Solutions:
- Use clearer, well-lit images
- Ensure fish is clearly visible
- Check if model was trained on similar images
- Verify preprocessing matches training
fastapi>=0.100.0
uvicorn[standard]>=0.23.0
tensorflow>=2.13.0
pillow>=10.0.0
python-multipart>=0.0.6
numpy>=1.24.0
Feel free to submit issues and enhancement requests!
This project is for educational and research purposes.
Once the server is running, visit:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Interactive API documentation with request/response examples.
- Best Results: Use clear, well-lit photos of fish showing visible symptoms
- Image Quality: Higher resolution images (but will be resized to 224x224)
- File Formats: JPEG, PNG, JPG supported
- Non-Fish Images: System will automatically reject images that don't appear to be fish
For Unix/Linux/macOS:
chmod +x run.sh
./run.shThis will activate the virtual environment and start the server.
Model: InceptionV3 (21.8M parameters, 130MB)
Framework: TensorFlow 2.x
API: FastAPI
Preprocessing: InceptionV3 standard preprocessing
For questions or issues, check the logs or API documentation.