Skip to main content

Finetune segment-anything

Project description

Fine-tune Segment-Anything Model

This library allows you to fine-tune the powerful Segment-Anything model from MetaAI for your custom COCO-format datasets. The library is built on top of Lightning AI's Fabric framework, providing an efficient and easy-to-use implementation for achieving state-of-the-art instance segmentation results.

This repo is an experiment; A PoC to see if fine-tuning SAM using bounding boxes as prompts would increase the IoU or improve the quality of the masks in general. One can use a COCO format dataset to fine-tune SAM for a specific task where SAM does not perform well (e.g., segmenting text on documents) and then use that model with interactive prompts just like SAM.

For generating bboxes from text and prompt them to SAM you may check: wow-ai-segment-anything

Features

  • Supports custom COCO-format datasets
  • Built on Lightning AI's Fabric framework
  • Efficient fine-tuning of Segment-Anything model from MetaAI
  • Includes training and validation loops

Results

Using bbox prompt, the table below shows the mask quality of the original and fine-tuned models.

Dataset Type Mean IoU Mean F1 Epoch
COCO2017 Original SAM 0.7978 0.8749
COCO2017 Fine-tuned 0.8070 0.8816 2
TrashCan 1.0 Original SAM 0.6643 0.7808
TrashCan 1.0 Fine-tuned 0.7888 0.8738 5
TrashCan 1.0 Fine-tuned 0.8000 0.8795 14
WGISD Original SAM 0.8536 0.9178
WGISD Fine-tuned 0.8732 0.9298 19
Comparison images
TrashCan 1.0 GT | 6 Epochs Fine-tuned SAM | Original SAM

Installation

git clone https://github.com/wow-ai-ml/wow-ai-segment-anything
cd wow-ai-sam
pip install .

Quick Start

  1. Prepare your custom COCO-format dataset. The dataset should include a JSON file with annotations and an images folder with corresponding images.

  2. Edit src/config.py with your dataset paths.

  3. Run src/train.py.

Notes

  • Uses the original implementation of SAM.
  • Loss calculated as stated on the paper (20 * focal loss + dice loss + mse loss).
  • Only supports bounding box input prompts.

Resources

License

This project is licensed same as SAM model.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wow_ai_sam-0.0.2.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wow_ai_sam-0.0.2-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file wow_ai_sam-0.0.2.tar.gz.

File metadata

  • Download URL: wow_ai_sam-0.0.2.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for wow_ai_sam-0.0.2.tar.gz
Algorithm Hash digest
SHA256 e13130ca2cb251b2c20027e299ef9ae6dbe4378b424dff48e50f337d6235f95f
MD5 de52775576094cf167e880293cc1b1f7
BLAKE2b-256 ffa0f48b1a19cef2eeea74e67eea191e3ecb3fb1e7add29e1a2327378683b333

See more details on using hashes here.

File details

Details for the file wow_ai_sam-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: wow_ai_sam-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for wow_ai_sam-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 56e4a94d25ed4af386497a507431cd0554d86eeb601beea66d38baa461a35c22
MD5 bcb296f624ceaed58bcf72588ddfbf0f
BLAKE2b-256 f8c73d54cbdb302224b117020d85e5eb95727b94a199d4cb54c47ca2a1acb01e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page