Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

README

Before running our notebooks

  • Install the packages in requirements.txt:

    python -m pip install -r requirements.txt jupyterlab
  • If you are running the notebooks on Windows, set any num_workers or NUM_WORKERS value to 0 in the notebook configuration cells before training or evaluation. This avoids common DataLoader multiprocessing issues on Windows.

  • Keep the notebooks in the project root.

  • Make sure the dataset folders are available locally.

    • Dataset_Splits/
    • Task2_Test_Set/

Datasets

If the dataset folders aren't available locally but you have the zip files, please run 0_Extract_Provided_Datasets.ipynb notebook first to extract the zip files to ./Dataset_Splits and ./Task2_Test_Set. However, we assume that the markers already have the extracted folders, so this notebook may not be needed in that case.

Path variables to change in each file

Most of our notebooks have an Update These Paths if Needed cell. Those paths may need to be updated if Dataset_Splits and Task2_Test_Set folders are not located in the root of our repository.

./models - Some of our notebooks will save models to this directory, which may be used by another notebook. For example, 1b_Segmentation.ipynb uses the model saved by 1b_Autoencoder.ipynb notebook. Unless there have been changes to the model paths within any of our notebooks, there is no need to update these paths.

Recommended notebook order

Task 1: Tissue segmentation

  1. 1_Dataset_Investigation.ipynb Use this first to inspect the image, tissue, and nuclei data.
  2. 1a_UNet.ipynb End-to-end UNet tissue segmentation. Saves a best checkpoint to ./models/unet_final_best.pth.
  3. 1b_Autoencoder.ipynb Train the autoencoder / encoder pretraining stage. Saves an autoencoder checkpoint such as ./models/autoencoder_weights_large.pth.
  4. 1b_Segmentation.ipynb Final segmentation model using the pretrained encoder. encoder_weights_path_custom points to the checkpoint saved by 1b_Autoencoder.ipynb at ./models/autoencoder_weights_large.pth. Saves a best checkpoint to ./models/segmentation_final_best.pth.

Task 2: Nuclei classification

  1. 2_DatasetCreation.ipynb Creates the patch dataset from Dataset_Splits and writes it to ./Task2_Patches/.
  2. 2a_Classification.ipynb End-to-end classification using ./Task2_Patches/train, ./Task2_Patches/val, and ./Task2_Test_Set. Saves ./models/efficientnet_best.pth.
  3. 2b_Contrastive.ipynb Contrastive pretraining on ./Task2_Patches/contrastive. Produces a contrastive checkpoint such as ./models/contrastive_temp03_<time>.pth. The later classification stage in this notebook saves ./models/contrastive_b64_SimCLR.pth.
  4. 2b_Contrastive_Supervised.ipynb Supervised contrastive pretraining + classification fine-tuning. Saves ./models/contrastive_b64_SupCon_60+.pth and then ./models/SupCon_PreTrain_FrozenEnc_best.pth.
  5. 2x_Visualise_Contrastive.ipynb Run this after contrastive training to visualize embeddings and nearest neighbours.

Recommended workflow

  • If only the zip files are available, start with 0_Extract_Provided_Datasets.ipynb. Otherwise, start with the next step.
  • Run the dataset investigation notebook 1_Dataset_Investigation.ipynb.
  • Run the Task 1 notebooks. For Task 1 Part a model, run 1a_UNet.ipynb. For Task 1 Part b model, first run 1b_Autoencoder.ipynb and then run 1b_Segmentation.ipynb.
  • Run the Task 2 notebooks. First, run 2_DatasetCreation.ipynb to create the patch dataset. For Task 2 Part a model, run 2a_Classification.ipynb. For Task 2 Part b models, run 2b_Contrastive.ipynb and 2b_Contrastive_Supervised.ipynb.
  • Run 2x_Visualise_Contrastive.ipynb.

Expected outputs

After running all notebooks, the project may contain the following output directories:

  • ./Dataset_Splits/
  • ./Task2_Test_Set/
  • ./models/
  • ./runs/
  • ./Task2_Patches/
  • ./Task2_Patches/train/
  • ./Task2_Patches/train/tumor/
  • ./Task2_Patches/train/lymphocyte/
  • ./Task2_Patches/train/histiocyte/
  • ./Task2_Patches/val/
  • ./Task2_Patches/val/tumor/
  • ./Task2_Patches/val/lymphocyte/
  • ./Task2_Patches/val/histiocyte/
  • ./Task2_Patches/contrastive/
  • ./Task2_Patches/contrastive/tumor/
  • ./Task2_Patches/contrastive/lymphocyte/
  • ./Task2_Patches/contrastive/histiocyte/
  • ./task1a_figures/
  • ./task2a_figures/

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages