Coder Social home page Coder Social logo

iris-sam's Introduction

Iris Segmentation Using a Foundation Model

This repository contains the code for training and inference of Iris-SAM.

Requirements

First, we need to make a conda environment with the following command:

conda create -n iris-sam python=3.8
conda activate iris-sam

Then, we need to install the requirements:

pip install -r requirements.txt

Dataset

The dataset is provided in data directory along with images and masks. The images are in .jpg format.

Training

To train the model, run the following command:

python sam_train_losses.py --data_dir data  --epochs 100 --loss focal --lr 0.0001 --save_dir checkpoints/ND


Model checkpoints will be saved in `save_dir` (default: `checkpoints/ft`). The program will save two checkpoints, one with optimizer and one without optimizer. The optimizer checkpoint is used for resuming training.
The checkpoint without optimizer (`model.pt`) is used for inference. We already provide a fine-tuned checkpoint in `google drive` and suggest to use model.pt.

Testing

We also provide a script to test the model on the val set. To test the model, run the following command:

python sam_test.py --data_dir data --pretrained_model *path_to_model/model.pt --save_dir *path_to_output/ND_test

Inference

To run inference, we need to provide bbox coordinates for the segmentation region in the image (automated). This is how SAM works,i.e. it requires a prompt along with image for prediction. In our case, the prompt is the bbox coordinates. We provide a script to run inference on a single image. To run inference, run the following command:

python sam_infer.py --image_path {PATH_TO_IMAGE_OR_DIR} --pretrained_model weights/model.pt --save_dir results

when you run the above command, an image window will be opened. You will be asked to draw (click) the top left and bottom right coordinates of the bbox using mouse pointer. Results will be saved in save_dir (default: outputs/results). The results include the overlay of predicted and ground truth masks.

The inference command can either take a single image or a directory containing multiple images as input. In case of directory, also provide the extension of the images. For example, if the images are in .jpg format, run the following command:

python sam_infer.py --image_path {PATH_TO_IMAGE_DIR} -extension jpg --pretrained_model weights/model.pt --save_dir results

If you get errors with cv2 while plotting bboxes on the image, uninstall and install OpenCV as follows:

pip uninstall opencv-python-headless -y 
pip install opencv-python --upgrade

Citations

If you find this repository useful, please consider giving a star โญ and a citation. (https://arxiv.org/abs/2402.06497).

@article{farmanifard2024iris,
  title={Iris-SAM: Iris Segmentation Using a Foundation Model},
  author={Farmanifard, Parisa and Ross, Arun},
  journal={arXiv preprint arXiv:2402.06497},
  year={2024}
}

Acknowledgmenets

  • We thank the University of Salzburg and Halmstad University for providing the ground truth datasets.
  • We thank Meta AI for making the source code of SAM publicly available.
  • MedSAM.

iris-sam's People

Contributors

parisafarmanifard avatar

Stargazers

Phumipas Namjaidee avatar cgnerds avatar Nikita Vasilev avatar cjkangme avatar

Watchers

Kostas Georgiou avatar  avatar

iris-sam's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.