Skip to main content

HocusPOCUS Collection

arXiv License PyPI version

⚡ An OOD benchmark for point-of-care ultrasound 🚀 ⚡


💴 About the Data

Description Train/Val/Test
HP-Atlas Crowd-sourced POCUS videos from 11 different views 176/217/461 videos
HP-Quality Pairs of POCUS vs. non-POCUS images 426/520/1154 images
HP-Noise Generated images with different foreground shapes 480/480/960 images

🔧 Installation

(Automatic) Installation:

# Option 1. Available on PyPI
pip install hocuspocus_ood

# Option 2. Local Pip Install
git clone https://github.com/stan-hua/hocuspocus
pip install -e .

🏃 Quickstart

Load HocusPOCUS Datasets:

from hocuspocus_ood import HocusPocusDataset, load_hocuspocus_metadata

# Parameters
dataset_name = "atlas"          # or "quality" or "noise"

# Optional parameters
hparams = {
    "transform": ...                # Torchvision transforms
    "load_image_func": ...,         # Custom calling function to load image given image path
    "load_image_kwargs": ...,       # Keyword arguments for custom image loading function
    "img_mode": 3,                  # 3 = RGB, 1 = Grayscale
    "img_size": (224, 224),         # Image size to resize to
    "scale": True,                  # If True, perform min-max normalization
}

# 1. HP-Atlas dataset               # NOTE: Both the extracted foreground and background are loaded
dataset = HocusPocusDataset("atlas", **hparams)
# 1.1. HP-Atlas dataset with background details kept
# dataset = HocusPocusDataset("atlas", separate_background=False, **hparams)
print(dataset[0])
# {
#   'id': 'pocus_atlas-renal-3-1',
#   'video_id': 'pocus_atlas-renal-3',
#   'img': tensor([[[0.0000, 0.0000, 0.0000,  ..., 0.0000, 0.0157, 0.1569]]]),
#   'background_img': tensor([[[0.0118, 0.0118, 0.0118,  ..., 0.0118, 0.0078, 0.0000]]]),
#   'label': 'renal',
# }

# 2. HP-Quality dataset
dataset = HocusPocusDataset("quality", **hparams)
print(dataset[0])
# {
#   'id': '0001-0',
#   'img': tensor([[[0.4235, 0.4510, 0.5020,  ..., 0.4627, 0.4471, 0.4549]]]),
#   'label': 'thyroid',
#   'quality': 'low_quality',
# }

# 3. HP-Noise dataset
dataset = HocusPocusDataset("noise", **hparams)
print(dataset[0])
# {
#   'id': 'hp_noise-1',
#   'img': tensor([[[0., 0., 0.,  ..., 0., 0., 0.]]]),
#   'label': 'noise-solid',
# }

🔧 Additional Utilities

A. Transformations

  1. SquarePad - zero pads image to 1:1 aspect ratio
from hocuspocus_ood import SquarePad

# Example 1. On image
img = ...
transform = SquarePad()
img_padded = transform(img)

# Example 2. In a composed transform
import torchvision
transforms = torchvision.transforms.Compose([SquarePad(), ...])

B. Augmentations

  1. MixBackground - shuffles and overlays batch of foreground and background images (assuming images are the same size)
from hocuspocus_ood import MixBackground

# Example 1. On batches of images
foreground_imgs = ...
background_imgs = ...
transform = MixBackground()
overlayed_imgs = transform(foreground_imgs, background_imgs)
  1. IgnoreEmptyRandomResizedCrop - crops in a region where >= 50% of pixels are non-zero
from hocuspocus_ood import IgnoreEmptyRandomResizedCrop

# Example 1. In a composed transform
import torchvision
transforms = torchvision.transforms.Compose([IgnoreEmptyRandomResizedCrop(), ...])

C. Data Samplers

  1. ImbalancedDatasetSampler - samples data points equally from each class in each batch
from torch.utils.data import DataLoader
from hocuspocus_ood import ImbalancedDatasetSampler

# Example 1. Given a Dataset object
dataset = ...
sampler = ImbalancedDatasetSampler(dataset)
dataloader = DataLoader(dataset, sampler=sampler, shuffle=False)
  1. InfiniteBatchSampler - samples batches infinitely from the dataset
from torch.utils.data import DataLoader
from hocuspocus_ood import ImbalancedDatasetSampler

# Example 1. Given a Dataset object
dataset = ...
batch_size = 32
batch_sampler = InfiniteBatchSampler(dataset, batch_size=batch_size)
dataloader = DataLoader(dataset, batch_sampler=batch_sampler, shuffle=False)

⭐ Advanced

Re-create HocusPOCUS datasets:

from hocuspocus_ood.scripts.create_dataset import *

# (Optional) Change save directory
save_dir = None

# 1. HP-Atlas (scrape from POCUS Atlas then process video)
download_pocus_atlas(save_dir)
process_pocus_atlas_dataset(save_dir, save_dir, extract_background=False)

# 2. HP-Quality (manually download from GrandChallenge - USEnhance 2023)
download_pocus_quality(save_dir)
create_pocus_quality_metadata(save_dir)

# 3. HP-Noise (generate data)
create_pocus_noise_dataset(save_dir)

👏 Acknowledgements

Team Members:

  1. Stanley Hua
  2. Lauren Erdman

Collaborators:

  1. SickKids, Urology Clinic
  2. Stanford Health Lucille Packard Children's, Urology Clinic
  3. Sinai Health, Maternal-Fetal Clinic
  4. Ontario Fetal Centre

Citation

If you find our work useful, please consider citing our paper!

@article{YourName,
  title={Your Title},
  author={Your team},
  journal={Location},
  year={Year}
}
``

Metadata

Release files for hocuspocus-ood 0.0.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 hocuspocus-ood 0.0.1
File Size Uploaded
hocuspocus_ood-0.0.1.tar.gz 4.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hocuspocus-ood 0.0.1
File Interpreter ABI Platform
hocuspocus_ood-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.1 kB

Release files / hocuspocus_ood-0.0.1.tar.gz

Download URL hocuspocus_ood-0.0.1.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
e6edcc0ec46668d61925aa121edc8f84bd6cf7921025e0d5284493cf66149b7f
BLAKE2b-256 checksum
How to use checksums
92ac159d919fdd5b6b7930aecd33da292fa4eb670bbc6112fea2c42848e31e2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.9.19

Release files / hocuspocus_ood-0.0.1-py3-none-any.whl

Download URL hocuspocus_ood-0.0.1-py3-none-any.whl
Size 4.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cd50edc3d4d3af90d024bd9b1db07a2a6f48faf2a20adfc26b2dbba027f77d80
BLAKE2b-256 checksum
How to use checksums
fda88bb7e1aac01458dbb54f5daed869b22931ffaf98e63ef1e2406b7e85ec31
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.9.19

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

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