Models and methods to generate counterfactuals for computed tomography scans
Project description
CT Counterfactuals
The code and models here were used in the Paper 📄 Merlin: A Vision Language Foundation Model for 3D Computed Tomography .
Classifiers
A 1692 target classifier predicting phenotypes from CT scans
import ct_counterfactuals as ct_cf
model = ct_cf.classifiers.phecode.PheCodeClassifier()
x = torch.ones([1, 1, 224, 224, 174])
out = model(x)
out.shape # [1, 1692]
A lung segmentation model from CT slices
import ct_counterfactuals as ct_cf
model = ct_cf.classifiers.lungmask.LungMaskSegmenter()
x = torch.ones([1, 1, 224, 224, 174])
out = model(x)
out.shape # [1, 3, 224, 224, 1]
# Channels
# 0 = No lung
# 1 = Right lung
# 2 = Left lung
Autoencoders
A VQ-GAN autoencoder trained on CT slices
import ct_counterfactuals as ct_cf
ae = ct_cf.ae.VQGAN(weights='2023-12-25T10-26-40_ct2_vqgan256_sddd')
x = torch.ones([1, 1, 224, 224])
out = ae(x)
out.shape # [1, 1, 224, 224]
Utility code is provided to encode 3D volumes
import ct_counterfactuals as ct_cf
ae = ct_cf.ae.VQGAN(weights='2023-12-25T10-26-40_ct2_vqgan256_sddd')
slice_ae = SliceAEFull(ae, 45, 55) # range specified is where gradients can propigate
x = torch.ones([1, 1, 224, 224, 174])
out = ae(x)
out.shape # [1, 1, 224, 224, 174]
Example CF explainations of the classifier
Effusion (fluid in lungs) | Splenomegaly (enlarged spleen) |
---|---|
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
ct-counterfactuals-0.0.1.tar.gz
(26.1 kB
view details)
Built Distribution
File details
Details for the file ct-counterfactuals-0.0.1.tar.gz
.
File metadata
- Download URL: ct-counterfactuals-0.0.1.tar.gz
- Upload date:
- Size: 26.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3423debaae7366197e8026721ce53451cd5afbd1f75eaaad6b351f49c5b9c06 |
|
MD5 | 41ed121549bbf72cc91214623b30527a |
|
BLAKE2b-256 | 9a8a198ee6d3b8d51debf4c5369e512c37c0a5f4470e194747ed694a20ace262 |
File details
Details for the file ct_counterfactuals-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: ct_counterfactuals-0.0.1-py3-none-any.whl
- Upload date:
- Size: 27.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5d314853ef3d5a3cab447a7cb84c27b8c8ed01bba21fdab9a768e456670b1bf |
|
MD5 | 3d7776878f2d5d19d910c0077d6ad4a6 |
|
BLAKE2b-256 | 4161b48500456639d68d284d8c8d5a256a61dd4ee55c254fc490ddfa8e47f03a |