CoolFace
Apppublic

Atish020/butterfly-semantic-segmentation-unet

sourceHugging Faceapache-2.0updated 9mo agoView on Hugging Face
1likes
App README

πŸ¦‹ Semantic Image Segmentation of Butterfly Images using U-Net

![Python](https://www.python.org/) ![TensorFlow](https://www.tensorflow.org/) ![U-Net]() ![FastAPI](https://fastapi.tiangolo.com/) ![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 [image]

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

text
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
---