Skip to main content

MMV Im2Im Transformation

Build Status

A generic python package for deep learning based image-to-image transformation in biomedical applications

The main branch will be further developed in order to be able to use the latest state of the art techniques and methods in the future. To reproduce the results of our manuscript, we refer to the branch paper_version. (We are actively working on the documentation and tutorials. Submit a feature request if there is anything you need.)


Overview

The overall package is designed with a generic image-to-image transformation framework, which could be directly used for semantic segmentation, instance segmentation, image restoration, image generation, labelfree prediction, staining transformation, etc.. The implementation takes advantage of the state-of-the-art ML engineering techniques for users to focus on researches without worrying about the engineering details. In our pre-print arxiv link, we demonstrated the effectiveness of MMV_Im2Im in more than ten different biomedical problems/datasets.

  • For computational biomedical researchers (e.g., AI algorithm development or bioimage analysis workflow development), we hope this package could serve as the starting point for their specific problems, since the image-to-image "boilerplates" can be easily extended further development or adapted for users' specific problems.
  • For experimental biomedical researchers, we hope this work provides a comprehensive view of the image-to-image transformation concept through diversified examples and use cases, so that deep learning based image-to-image transformation could be integrated into the assay development process and permit new biomedical studies that can hardly be done only with traditional experimental methods

Installation

Before starting, we recommend to create a new conda environment or a virtual environment with Python 3.10+.

conda create -y -n im2im -c conda-forge python=3.11
conda activate im2im

Please note that the proper setup of hardware is beyond the scope of this pacakge. This package was tested with GPU/CPU on Linux/Windows and CPU on MacOS. [Special note for MacOS users: Directly pip install in MacOS may need additional setup of xcode.]

Install MONAI

To reproduce our results, we need to install MONAI's code version of a specific commit. To do this:

git clone https://github.com/Project-MONAI/MONAI.git
cd ./MONAI
git checkout 37b58fcec48f3ec1f84d7cabe9c7ad08a93882c0
pip install .

We will remove this step for the main branch in the future to ensure a simplified installation of our tool.

Install MMV_Im2Im for basic usage:

(For users only using this package, not planning to change any code or make any extension):

Option 1: core functionality only pip install mmv_im2im
Option 2: advanced functionality (core + logger) pip install mmv_im2im[advance]
Option 3: to reproduce paper: pip install mmv_im2im[paper]
Option 4: install everything: pip install mmv_im2im[all]

For MacOS users, additional ' ' marks are need when using installation tags in zsh. For example, pip install mmv_im2im[paper] should be pip install mmv_im2im'[paper]' in MacOS.

Install MMV_Im2Im for customization or extension:

git clone https://github.com/MMV-Lab/mmv_im2im.git
cd mmv_im2im
pip install -e .[all]

Note: The -e option is the so-called "editable" mode. This will allow code changes taking effect immediately. The installation tags, advance, paper, all, are be selected based on your needs.

(Optional) Install using Docker

It is also possible to use our package through docker. The installation tutorial is here. Specifically, for MacOS users, please refer to this tutorial.

(Optional) Use MMV_Im2Im with Google Colab

We provide a web-based demo, if cloud computing is preferred. you can Open a 2D labelfree DEMO in Google Colab. The same demo can de adapted for different applications.

Quick start

You can try out on a simple example following the quick start guide

Basically, you can specify your training configuration in a yaml file and run training with run_im2im --config /path/to/train_config.yaml. Then, you can specify the inference configuration in another yaml file and run inference with run_im2im --config /path/to/inference_config.yaml. You can also run the inference as a function with the provided API. This will be useful if you want to run the inference within another python script or workflow. Here is an example:

from pathlib import Path
from bioio import BioImage
from bioio.writers import OmeTiffWriter
from mmv_im2im.configs.config_base import ProgramConfig, parse_adaptor, configuration_validation
from mmv_im2im import ProjectTester

# load the inference configuration
cfg = parse_adaptor(config_class=ProgramConfig, config="./paper_configs/semantic_seg_2d_inference.yaml")
cfg = configuration_validation(cfg)

# define the executor for inference
executor = ProjectTester(cfg)
executor.setup_model()
executor.setup_data_processing()

# get the data, run inference, and save the result
fn = Path("./data/img_00_IM.tiff")
img = BioImage(fn).get_image_data("YX", Z=0, C=0, T=0)
# or using delayed loading if the data is large
# img = BioImage(fn).get_image_dask_data("YX", Z=0, C=0, T=0)
seg = executor.process_one_image(img)
OmeTiffWriter.save(seg, "output.tiff", dim_orders="YX")

Tutorials, examples, demonstrations and documentations

The overall package aims to achieve both simplicty and flexibilty with the modularized image-to-image boilerplates. To help different users to best use this package, we provide documentations from four different aspects:

Contribute models to BioImage Model Zoo

We highly appreciate the BioImage Model Zoo's initiative to provide a comprehensive collection of pre-trained models for a wide range of applications. To make MMV_Im2Im trained models available as well, the first step involves extracting the state_dict from the PyTorch Lightning checkpoint. This can be done via:

import torch

ckpt_path = "./lightning_logs/version_0/checkpoints/last.ckpt"
checkpoint = torch.load(ckpt_path, map_location=torch.device('cpu'))
state_dict = checkpoint['state_dict']
torch.save(state_dict, "./state_dict.pt")

All further steps to provide models can be found in the official documentation.

Development

See CONTRIBUTING.md for information related to developing the code.

MIT license

Metadata

Release files for mmv-im2im 0.8.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mmv-im2im 0.8.1
File Size Uploaded Provenance Actions
mmv_im2im-0.8.1.tar.gz 130.7 kB Without provenance Details for mmv_im2im-0.8.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mmv-im2im 0.8.1
File Interpreter ABI Platform Actions
mmv_im2im-0.8.1-py3-none-any.whl Python 3 none any Details for mmv_im2im-0.8.1-py3-none-any.whl

Total release size: 295.8 kB

Release files / mmv_im2im-0.8.1.tar.gz

Download URL mmv_im2im-0.8.1.tar.gz
Size 130.7 kB
Tags Source
SHA-256 checksum
How to use checksums
fd566761574334288368daa37a9c6f4130d9b0edc0084ef4d177671c5942bfbc
BLAKE2b-256 checksum
How to use checksums
d084dd841611eacd6cee8f88bd08bc8d5acef6a98e9d28008332c41e45e93e62
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / mmv_im2im-0.8.1-py3-none-any.whl

Download URL mmv_im2im-0.8.1-py3-none-any.whl
Size 165.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
68edd91f48b56e0abddfb1285d91ed862cf299995961ad812e722675802b6c40
BLAKE2b-256 checksum
How to use checksums
8c15974070d8c5724f195726c94921399a55195faae27d2eb792b9870068aad8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Security for mmv-im2im 0.8.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page