Skip to main content

Portable and lightweight brain segmentation using tinygrad

Project description

BrainChop

BrainChop is a lightweight tool for brain segmentation that runs on pretty much everything.


Installation

pip install brainchop

For development (includes docs, testing):

pip install -e ".[all]"

CLI Usage

# Segment a brain MRI
brainchop input.nii.gz -o output.nii.gz

# List available models
brainchop --list

# Use a specific model
brainchop input.nii.gz -m subcortical -o output.nii.gz

# Skull stripping
brainchop input.nii.gz --skull-strip -o brain.nii.gz

# With BEAM optimization
brainchop input.nii.gz -m tissue_fast --beam 2 -o output.nii.gz

Python API

import brainchop as bc

# List available models
print(bc.list_models())

# Load, segment, save
vol = bc.load("input.nii.gz")
result = bc.segment(vol, "subcortical")
bc.save(result, "output.nii.gz")

# With BEAM optimization
bc.optimize("tissue_fast", beam=2)
result = bc.segment(vol, "tissue_fast")

# Export to WebGPU
bc.export("tissue_fast", "/tmp/export")

Documentation

Serve docs locally:

mkdocs serve -w brainchop/

Docker

git clone git@github.com:neuroneural/brainchop-cli.git
cd brainchop-cli
docker build -t brainchop .

Then to run:

docker run --rm -it --device=nvidia.com/gpu=all -v [[output directory]]:/app brainchop [[input nifti file]] -o [[output nifti file]]

Requirements

  • Python 3.10+
  • tinygrad
  • numpy
  • requests

to use the WEBGPU export backend, also install dawn

brew tap wpmed92/dawn
brew install dawn

License

MIT License

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

brainchop-0.2.2.tar.gz (37.0 kB view details)

Uploaded Source

Built Distribution

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

brainchop-0.2.2-py3-none-any.whl (34.0 kB view details)

Uploaded Python 3

File details

Details for the file brainchop-0.2.2.tar.gz.

File metadata

  • Download URL: brainchop-0.2.2.tar.gz
  • Upload date:
  • Size: 37.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for brainchop-0.2.2.tar.gz
Algorithm Hash digest
SHA256 5551fc8354085ee47689eaa60a94dadb27221eb69f7bd9096319150f0fa64239
MD5 b294f205d0b22e587d2c9b87b113be27
BLAKE2b-256 e40e6410afefe27e7ddd5c446eadf84aecd3107ebd7cba2ee6bc5a039d6a19ad

See more details on using hashes here.

File details

Details for the file brainchop-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: brainchop-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 34.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for brainchop-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 25deeaff71494ad5233728232451e6facbf28120c9d2713790d2c2f791499c8a
MD5 1eba4a56996d65f76eb36e2fcbfe9f3c
BLAKE2b-256 fefb00b87035610f586d73878e3f56088edc2482fda543d8e970326c8a280645

See more details on using hashes here.

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