This project implements a state-of-the-art Camouflage Object Detection system using deep learning to identify objects that blend seamlessly with their surroundings. The system uses the SINet V2 architecture with Res2Net backbone for accurate detection and segmentation of camouflaged objects.
Deployed Application: https://cod-769q.onrender.com
Upload any image and watch the AI detect camouflaged objects in real-time!
- Python 3.11 or higher
- Git
- 8GB+ RAM recommended
- CUDA-capable GPU (optional, CPU works too)
git clone https://github.com/shashhii/COD.git
cd COD# Windows
python -m venv venv
venv\Scripts\activate
# macOS/Linux
python3 -m venv venv
source venv/bin/activatepip install -r requirements.txtThe application will automatically download required model files on first run:
- Res2Net backbone: ~100MB
- Trained COD model: ~400MB
python app.pyOpen your browser and navigate to:
- Local URL:
http://localhost:8000 - Alternative:
http://127.0.0.1:8000
Port Already in Use:
# Use different port
set PORT=8001 && python app.py # Windows
export PORT=8001 && python app.py # macOS/LinuxModel Download Issues:
- Ensure stable internet connection
- Models download automatically on first startup
- Check
COD10K Trained model/directory for downloaded files
Memory Issues:
- Close other applications
- Use CPU-only mode (default)
- Reduce image size if processing fails
- Model: SINet V2 (Search & Identification Network V2)
- Backbone: Res2Net-50 with multi-scale feature extraction
- Framework: PyTorch for deep learning, FastAPI for web service
- Frontend: HTML/CSS/JavaScript with drag-and-drop interface
- Image Upload: User uploads an image through the web interface
- Preprocessing: Image is resized to 320x320 and normalized
- Feature Extraction: Res2Net backbone extracts multi-scale features
- Detection: SINet V2 identifies camouflaged regions
- Post-processing: Generates bounding boxes, masks, and confidence scores
- Visualization: Creates three types of output:
- Detection View: Bounding boxes with confidence scores
- Segmentation View: Pixel-perfect masks overlay
- Heatmap View: Probability distribution visualization
- Real-time Detection: Fast inference on CPU/GPU
- Multi-scale Analysis: Detects objects of various sizes
- High Accuracy: Trained on COD10K dataset
- Interactive Interface: Drag-and-drop image upload
- Multiple Visualizations: Bounding boxes, segmentation masks, heatmaps
- Responsive Design: Works on desktop and mobile devices
COD/
โโโ app.py # Main FastAPI application
โโโ requirements.txt # Python dependencies
โโโ runtime.txt # Python version specification
โโโ render.yaml # Render deployment configuration
โโโ download_models.py # Model download script
โโโ Front End/ # Web interface
โ โโโ index.html # Main HTML page
โ โโโ style.css # Styling
โ โโโ script.js # Frontend JavaScript
โโโ Back End/ # AI model implementation
โ โโโ sinetv2_model.py # SINet V2 model wrapper
โ โโโ Network_Res2Net_GRA_NCD.py # Network architecture
โ โโโ Res2Net_v1b.py # Res2Net backbone
โโโ COD10K Trained model/ # Pre-trained model weights (auto-downloaded)
โ โโโ Net_epoch_best.pth # Main trained model
โ โโโ res2net50_v1b_26w_4s-3cf99910.pth # Backbone weights
โโโ uploads/ # Temporary upload directory
- FastAPI: High-performance web framework
- PyTorch: Deep learning framework
- OpenCV: Computer vision operations
- NumPy: Numerical computations
- Pillow: Image processing
- HTML5: Structure and layout
- CSS3: Styling and animations
- JavaScript: Interactive functionality
- Drag & Drop API: File upload interface
- Render: Cloud hosting platform
- Git: Version control
- Dropbox: Model file hosting
- Trained SINet V2 model on COD10K dataset
- Uploaded model weights to Dropbox for reliable downloading
- Configured automatic model download during deployment
- Converted from GPU to CPU-only PyTorch for cloud deployment
- Added error handling for model loading failures
- Implemented fallback mechanisms for robust operation
- Platform: Render.com (free tier)
- Runtime: Python 3.11.9
- Build Command:
pip install -r requirements.txt - Start Command:
uvicorn app:app --host 0.0.0.0 --port $PORT
- Models download automatically on first startup
- Res2Net backbone: Downloaded from official source
- Trained weights: Downloaded from Dropbox
- Validation checks ensure model integrity
requirements.txt: CPU-optimized PyTorch dependenciesruntime.txt: Python version specificationrender.yaml: Deployment configuration.gitignore: Excludes large model files from Git
- Visit: https://cod-769q.onrender.com or run locally
- Upload: Drag and drop an image or click "Browse Files"
- Analyze: Click "Analyze Image" button
- View Results: See detection, segmentation, and heatmap outputs
- Download: Click on any result image to view full-screen and download
GET /: Main web interfacePOST /upload: Image processing endpointGET /health: Service health checkGET /style.css: CSS stylesheetGET /script.js: JavaScript functionality
- Dataset: COD10K (10,000+ camouflaged object images)
- Architecture: SINet V2 with Res2Net-50 backbone
- Input Size: 320ร320 pixels
- Inference Time: ~2-3 seconds per image (CPU)
- Confidence Threshold: 0.01 (highly sensitive detection)
- Multi-Scale Detection: Handles objects of various sizes
- Attention Mechanisms: Focuses on relevant image regions
- Neighbor Connection Decoder: Improves boundary accuracy
- Group-Reversal Attention: Enhances feature representation
- Real-time Processing: Optimized for web deployment
- Problem: Git can't handle large PyTorch models
- Solution: Automatic download from cloud storage during deployment
- Problem: Local model trained on GPU, deployment on CPU
- Solution: Added
map_location='cpu'andweights_only=Falseparameters
- Problem: PyTorch 2.6 changed default loading behavior
- Solution: Explicit
weights_only=Falsefor backward compatibility
- Problem: Google Drive blocks direct downloads
- Solution: Switched to Dropbox with
dl=1parameter
- GPU acceleration for faster inference
- Batch processing for multiple images
- Video processing capabilities
- Mobile app development
- Advanced visualization options
- Custom model training interface
Contributions are welcome! Please feel free to submit issues and enhancement requests.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin features/AmazingFeature) - Open a Pull Request
This project is for educational and research purposes. Model weights and architecture are based on published research papers.
If you encounter any issues:
- Check the Issues page
- Create a new issue with detailed description
- Include error logs and system information
Built with โค๏ธ using PyTorch, FastAPI, and deployed on Render
โญ Star this repository if you found it helpful!