Code Monkey home page Code Monkey logo

vit-breast-cancer's Introduction

Visualizing Transformers for Breast Histopathology

This repository contains code for Visualizing Transformers for Breast Histopathology. This work was completed as part of CPSC 482: Current Topics in Applied Machine Learning.

Abstract

Transfer learning is a common way of achieving high performance on downstream tasks with limited data. Simultaneously, the success of vision transformers has opened up a wider range of image model options than previously available. In this report, we explore the application of transfer learning in the context of breast histopathology using state-of-the-art vision transformer models: ViT, BeiT, and CaiT. We focus on ways of presenting model prediction and behavior in human-interpretable ways, such that a pathologist could leverage this information to aid with their diagnosis. Through experiments, we show how attention maps and latent representations can be used to interpret model behavior.

Quickstart

  1. Clone the repository.
$ git clone https://github.com/jaketae/vit-breast-cancer.git
  1. Create a Python virtual enviroment and install package requirements.
$ cd vit-breast-cancer
$ python -m venv venv
$ pip install -r requirements.txt
  1. To train a model, run python train.py; for evaluation, python evaluate.py with appropriate flags. For instance,
$ CUDA_VISIBLE_DEVICES=1 python evaluate.py --device cuda --checkpoint checkpoints/vit_freeze

Dataset

We used the Breast Histopathology Images dataset. You can either download the dataset directly from the website, or use Kaggle's Python API to download it via the command line. For detailed instructions on how to use the Kaggle API, refer to the documentation.

$ kaggle datasets download paultimothymooney/breast-histopathology-images

Create a subfolder within the directory, such as raw, then unzip the dataset via

$ unzip breast-histopathology-images.zip -d raw

Training

To evaluate a model checkpoint, run train.py. The full list of supported arguments are shown below.

$ python train.py -h
usage: train.py [-h] [--name NAME] [--device DEVICE] [--log_path LOG_PATH] [--data_path DATA_PATH] [--save_path SAVE_PATH]
                [--model MODEL] [--freeze FREEZE] [--epochs EPOCHS] [--lr LR] [--classifier_lr CLASSIFIER_LR] [--split SPLIT]
                [--threshold THRESHOLD] [--batch_size BATCH_SIZE] [--num_workers NUM_WORKERS]

optional arguments:
  -h, --help            show this help message and exit
  --name NAME
  --device DEVICE
  --log_path LOG_PATH
  --data_path DATA_PATH
  --save_path SAVE_PATH
  --model MODEL
  --freeze FREEZE
  --epochs EPOCHS
  --lr LR
  --classifier_lr CLASSIFIER_LR
  --split SPLIT
  --threshold THRESHOLD
  --batch_size BATCH_SIZE
  --num_workers NUM_WORKERS

Default configurations are specified in config.py.

Running this command will create a folder under checkpoints and logs according to the name field specified in the configuration file. checkpoints will contain model weights, and logs will contain tensorboard logs for model training inspection.

Evaluation

To evaluate a model checkpoint, run evaluate.py. The full list of supported arguments are shown below.

$ python evaluate.py -h
usage: evaluate.py [-h] [--device DEVICE] [--checkpoint CHECKPOINT]

optional arguments:
  -h, --help            show this help message and exit
  --device DEVICE
  --checkpoint CHECKPOINT

For example, assuming a vit_freeze checkpoint and a CUDA-enabled local machine, run

$ CUDA_VISIBLE_DEVICES=1 python evaluate.py --device cuda --checkpoint checkpoints/vit_freeze

If CUDA is not available, you can also set the device flag to cpu.

References

License

Released under the MIT License.

vit-breast-cancer's People

Contributors

jaketae avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.