Atish020/butterfly-semantic-segmentation-unet
π¦ Semantic Image Segmentation of Butterfly Images using U-Net
  ![U-Net]()  ![HTML5]() ![CSS3]() ![JavaScript]() ![Docker]() ![Mean IoU]() ![Dice]()
This project implements a Computer Visionβbased semantic image segmentation system to accurately extract butterfly regions from complex backgrounds at the pixel level. The solution uses a U-Net architecture, deployed as a real-time web application using FastAPI, HTML/CSS/JavaScript, Docker, and Hugging Face Spaces.
π Demo
- Upload a butterfly image
- Get real-time segmentation mask
- View original image & predicted mask side-by-side
The application runs fully inside a Docker container and exposes a FastAPI backend for inference.
π Problem Statement
Traditional object detection methods provide only bounding boxes, which are insufficient for tasks requiring precise object boundaries. Butterfly images pose additional challenges due to:
- Complex and cluttered backgrounds (flowers, leaves, sky)
- Color similarity between butterfly wings and background
- Fine-grained wing structures
The goal is to classify each pixel as either:
- Butterfly (foreground)
- Background
π§ Proposed Solution
This problem is solved using Semantic Image Segmentation with a U-Net architecture, which combines:
- Encoder path for contextual feature extraction
- Decoder path for precise spatial localization
- Skip connections to preserve fine details
The trained model predicts a binary segmentation mask highlighting only the butterfly region.
π§© Model Architecture
- Architecture: U-Net
- Input size: 256 Γ 256 Γ 3
- Loss Function: Binary Cross-Entropy
- Metrics: Accuracy, Dice Coefficient, Mean IoU
- Framework: TensorFlow / Keras
π Performance
- Validation Accuracy: ~96%
- Mean IoU (Validation): ~0.89
- Dice Coefficient: ~0.94
- Inference Time: ~100 ms per image (CPU)
ποΈ Dataset
Leeds Butterfly Dataset (BMVC 2009)
- 832 butterfly images
- Pixel-level segmentation masks
- 10 butterfly species
- Images collected from Google Images and manually filtered
π§± Project Structure
Semantic-image-segmentation-using-UNet/
β
βββ app.py
βββ Dockerfile
βββ requirements.txt
βββ README.md
β
βββ backend/
β βββ main.py # FastAPI backend logic
β
βββ frontend/
β βββ index.html # UI
β βββ style.css # Styling
β βββ script.js # Client-side logic
β
βββ saved_model/
β βββ final_UNET_Butterfly_Segmentation.keras
=======
title: Butterfly Semantic Segmentation Unet
emoji: π
colorFrom: yellow
colorTo: blue
sdk: docker
pinned: false
license: apache-2.0
short_description: Pixel-level butterfly image segmentation using U-Net
---
