Giter Site home page Giter Site logo

autoprom_sam's Introduction

autoprom-sam

autoprom-sam network architecture

This repository contains the code for the paper:

'PATHOLOGICAL PRIMITIVE SEGMENTATION BASED ON VISUAL FOUNDATION MODEL WITH ZERO-SHOT MASK GENERATION'

Authors:

  • Abu Bakor Hayat Arnob
  • Xiangxue Wang
  • Yiping Jiao
  • Xiao Gan
  • Wenlong Ming
  • Jun Xu

Digital Slide Archive Plugin

autoprom-sam can also be converted into a Digital Slide Archive plugin.

Below is the demo for the modified version of DSA called AIM UI.

AIM UI Demo

Folder Structure

This project structure is given below. and some important files are also mentioned.

๐Ÿ“ .
โ”œโ”€โ”€ ๐Ÿ“ autoprom_sam
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ configs
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ dataloaders
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ datasets
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ dataset_utils
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ model
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ training
โ”‚   โ””โ”€โ”€ ๐Ÿ“ utils
โ”œโ”€โ”€ ๐Ÿ“„ LICENSE
โ”œโ”€โ”€ ๐Ÿ“ notebooks
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ check_pannuke_dataloader.ipynb
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ inference_on_pannuke.ipynb
โ”œโ”€โ”€ ๐Ÿ“ runs
โ”œโ”€โ”€ ๐Ÿ“ sam_weights
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ sam weights path
โ””โ”€โ”€ ๐Ÿ“„ setup.py
  • the training.py script could be found under training folder:
๐Ÿ“ training
โ”œโ”€โ”€ ๐Ÿ“„ trainer.py
  • the Bounding Box Generator decoder can be found here Detmodel.py:
๐Ÿ“ model
~
โ”œโ”€โ”€ ๐Ÿ“„ Detmodel.py
~

Environment Setup

To setup the environment, first create a conda environment and install all the necessary packages.

Note: This code only supports single GPU training for now. It was developed on a local computer with only a single GPU so multi-GPU training and inference haven't been tested.

Clone this repository and from the root folder run the following commands to install the package.

conda activate autoprom_sam
python -m pip install -e .

Inference

For inference, we have compiled a Jupyter notebook which can be found here.

Example Inference

Bounding Box Overlay

Dataset Preparation

While any dataset could be adopted to work with autoprom-sam, for training the Bounding Box decoder, the boxes need to be in the format [cx,cy,w,h].

For reference, you can look at the file here.

If you choose to use a CSV file like ours, then it should have the following columns:

  • Image_File: Contains the absolute/ relative path of the image file
  • BBox: Contains the bounding box coordinates in [cx,cy,w,h] format
  • Label: Class labels list in integer

Note: For our purpose, we have obtained the mask file from Image_File path during inference. In order to use the training scripts, it is necessary that the dataloader returns (id, img, mask, inst_mask, annot), but only the img and annot is used during training. So, if you use a custom dataloader, you can fill these values using None. For example: (None, img, None, None, annot,)

Training

To train the network, follow these steps:

  1. Navigate to the root directory by executing the following command in your terminal:

    cd /home/{the directory where the repo was cloned}
  2. Once in the root directory, run the training script:

    python autoprom_sam/training/trainer.py

You can modify the hyperparameters for training using config.py. The configurations for both the pannuke and FTU datasets are provided in this file. Here are some important configuration options:

  • train_filename: Path to the training data file.
  • test_filename: Path to the testing data file.
  • most_recent_model: Path to the most recent model checkpoint file.
  • recent_optimizer: Optimizer used in the most recent training.
  • sam_checkpoint: Path to the SAM checkpoint file.
  • check_points_dir: Directory where model checkpoints will be saved.
  • log_dir: Directory where logs will be saved.
  • resume: Boolean value indicating whether to resume training from the most recent checkpoint.
  • use_transposed: Boolean value indicating whether to use transposed convolutions in the model.
  • record: Boolean value indicating whether to record training progress.
  • load_sam_weights: Boolean value indicating whether to load weights from the SAM checkpoint.
  • device: The device to use for training.
  • num_workers: Number of worker processes to use for data loading.
  • train_batch_size: Batch size to use for training.

Note: To train the network, you must have downloaded the SAM-B model's checkpoint. If you don't have the weights, the encoder will output random values since we froze the network during training.

Reference

@article{kirillov2023segany,
  title={Segment Anything},
  author={Kirillov, Alexander and Mintun, Eric and Ravi, Nikhila and Mao, Hanzi and Rolland, Chloe and Gustafson, Laura and Xiao, Tete and Whitehead, Spencer and Berg, Alexander C. and Lo, Wan-Yen and Doll{\'a}r, Piotr and Girshick, Ross},
  journal={arXiv:2304.02643},
  year={2023}
}

@article{graham2019hover,
  title={Hover-net: Simultaneous segmentation and classification of nuclei in multi-tissue histology images},
  author={Graham, Simon and Vu, Quoc Dang and Raza, Shan E Ahmed and Azam, Ayesha and Tsang, Yee Wah and Kwak, Jin Tae and Rajpoot, Nasir},
  journal={Medical Image Analysis},
  pages={101563},
  year={2019},
  publisher={Elsevier}
}

autoprom_sam's People

Contributors

arnob-98 avatar learner-codec avatar

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.