Skip to main content

A PyTorch implementation of the SPAGHETTI model for phase-contrast microscopy image transformation

Project description

SPAGHETTI - SSIM-restrained Phase Contrast Microscopy GAN for H&E Translation of Images

Implementation of the SPAGHETTI method for phase-contrast microscopy images pre-processing so that you can use your favourite H&E model on them.

Read the documentation at documentations.md

Installing SPAGHETTI

Installing using PyPI

SPAGHETTI is available on the Python Package Index (PyPI) to be installed with pip directly. To install, run:

pip install pcm-spaghetti

Installing Locally

Alternatively, you may also install SPAGHETTI from the GitHub repository directly. To do that, first create a virtual Python environment and install SPAHETTI locally.

virtualenv --no-download spaghetti
source spaghetti/bin/activate 
git clone https://github.com/schwartzlab-methods/spaghetti
cd spaghetti
python setup.py sdist bdist_wheel
pip install .

Inferences using SPAGHETTI

An example workflow of how to use SPAGHETTI to convert your phase-contrast microscopy images into H&E-like images can be found at ./tutorials/inference_example.py. Before running the example code, please ensure that you have cloned the default SPAGHETTI checkpoint file properly located at ./spaghetti_checkpoint.ckpt. If not, please go to the repository and directly download this checkpoint file.

Inferences with the CLI tool

Alternatively, you can also run inferences using the CLI interface to perform quick inferences. To do this, after you have installed SPAGHETTI, run:

python3 spaghetti --input path_to_directory_with_your_images \
--output path_to_directory_to_save_the_images --checkpoint path_to_the_checkpoint_file

The checkpoint file can either be the default checkpoint file (to be downloaded from ./spaghetti_checkpoint.ckpt), or can be the checkpoint files from your own training (see below for more details on how to train your own SPAGHETTI model).

Inferences with Docker

For a dependency-free and reproducible environment, the CLI inference tool of SPAGHETTI is available as a Docker image. To use it, ensure you have Docker installed, then run:

Option 1: Use the Pre-built Image from Docker Hub

The official image is hosted on Docker Hub.

  1. Pull the latest image:

    docker pull yinnikun/spaghetti:latest
    
  2. Run Inference:

    To run inference, you need to mount a local directory into the container. This directory should contain your input images and the model checkpoint. The container will write the output images back to this same directory.

    Let's say your local data is organized as follows:

    /path/to/your/data/
    ├── inputs/
    │   ├── image1.tif
    │   └── image2.tif
    ├── spaghetti_checkpoint.ckpt
    └── outputs/  <-- This will be created
    

    Execute the following command:

    docker run --rm -v "/path/to/your/data:/data" yinnikun/spaghetti:latest \
      --input /data/inputs \
      --output /data/outputs \
      --checkpoint /data/spaghetti_checkpoint.ckpt
    
    • --rm: Automatically removes the container when it exits.
    • -v "/path/to/your/data:/data": Mounts your local data directory into the /data directory inside the container. Remember to use absolute paths.

Option 2: Build the Image Locally

You can also build the Docker image directly from the dockerfile in this repository.

  1. Build the image:

    docker build -t spaghetti:latest .
    
  2. Run Inference: The docker run command is the same as above, just replace the image name:

    docker run --rm -v "/path/to/your/data:/data" spaghetti:latest \
      --input /data/inputs \
      --output /data/outputs \
      --checkpoint /data/spaghetti_checkpoint.ckpt
    

Training your own model

You can also train your own model to perform the inferences. See an example code at ./tutorials/train_example.py

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

pcm_spaghetti-1.0.2.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

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

pcm_spaghetti-1.0.2-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

File details

Details for the file pcm_spaghetti-1.0.2.tar.gz.

File metadata

  • Download URL: pcm_spaghetti-1.0.2.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pcm_spaghetti-1.0.2.tar.gz
Algorithm Hash digest
SHA256 03abb5975946eaef8b8890618531e09ef717e024741f08b8241c0faf800ae853
MD5 2ae2762264c7d5c01a8ac5597502a0a0
BLAKE2b-256 00ee52e019e54438893b287cd5868312f0cb77df95b105db4a181000e03c6d7b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pcm_spaghetti-1.0.2.tar.gz:

Publisher: python-publish.yml on schwartzlab-methods/spaghetti

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pcm_spaghetti-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: pcm_spaghetti-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 23.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pcm_spaghetti-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 53ff7300725b7c89bab9d179ab1ebb017f3bbe7ce462580a6b1fe1ca74ea8a23
MD5 666454c5c1ca32c4552fde76dcd14844
BLAKE2b-256 6748bef036cb432a71d42371ba8981e3802bddb48530fc23832df8e178391414

See more details on using hashes here.

Provenance

The following attestation bundles were made for pcm_spaghetti-1.0.2-py3-none-any.whl:

Publisher: python-publish.yml on schwartzlab-methods/spaghetti

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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