项目 / nitrain/nitrain

nitrain/nitrain

行业候选
语言 Python标签 pytorchdeep-learningkerasneuroimagingmedical-imaging数据更新 2026-11-20 06:49:16 · 仓库 2026-11-19

一段话介绍

面向医学影像的 Python 库(曾用名 torchsample),用来对医学影像做采样与增强、在医学影像数据集上训练模型,并在医学影像语境下查看结果。它提供较高层的抽象和合理默认值,以简化训练流程,并支持 PyTorch、TensorFlow 和 Keras 等多种框架。关键依赖是 ANTsPy,用来高效读取、处理和可视化医学影像。完整训练示例见教程仓库。安装可用 `pip install nitrain`。说明见[教程](https://github.com/nitrain/tutorials)和[仓库 README](https://github.com/nitrain/nitrain)。本页按研究用途介绍,不涉及诊疗判断。

本站整理,非 GitHub 官方 description。

官方 description(GitHub API 原样)
Train AI models efficiently on medical images using any framework
1,880累计星
299Fork
—峰值日增
0上榜次数
总榜
暂未入榜
日榜
暂未入榜
周榜
暂未入榜
月榜
暂未入榜

官方快照(gh_history.db,2026-11-25):总榜 未进 Top50 · 日榜 未进 Top50 · 周榜未满 7 天基线(官方不生成) · 月榜暂无官方口径;下方四卡为站内趋势聚合(周卡按上榜次数,非官方 7 日增量窗)。

行业与场景 医疗 暂无可用场景

更多信息

以下三段按该项目自己的 GitHub README 章节摘录(可合理截断并标明);README 没有对应章节的留空,不编造。

我的用法
可运行 python -m pip install git+github.com/nitrain/nitrain.git。
特点或设计要点
可用 Dataset 从影像文件夹与被试信息表组织输入和输出,并在读取时施加归一化、尺寸调整等变换;Loader 可按批次取样,并配合切片采样器和随机变换。可用 `fetch_architecture` 按名称取得如 U-Net 等结构,再用 Trainer 按分割等任务拟合。教程覆盖入门、分割、分类和配准。
星标走势还差一天的数据,明天就能看到曲线
每天 10:30 记一次星标,连续两天后自动生成曲线
首次发现 — · 最近在榜 2026-11-06 · 语言 Python · 贡献者 —
image

GitHub 项目主页介绍

来自 GitHub 仓库 README / 主页介绍正文,原样摘录,共 4,076 字节。

# Nitrain: a medical imaging-native AI framework

[![Coverage Status](https://coveralls.io/repos/github/nitrain/nitrain/badge.svg?branch=main)](https://coveralls.io/github/nitrain/nitrain?branch=main)
[![Build](https://github.com/nitrain/nitrain/actions/workflows/test.yml/badge.svg)](https://github.com/nitrain/nitrain/actions/workflows/test.yml)

Nitrain (formerly <i>torchsample</i>) is a framework-agnostic python library for sampling and augmenting medical images, training models on medical imaging datasets, and visualizing results in a medical imaging context.

The nitrain library is unique in that it makes training models as simple as possible by providing reasonable defaults and a high-level of abstraction. It also supports multiple frameworks - torch, tensorflow, and keras - with a goal to add even more.

Full examples of training medical imaging AI models using nitrain can be found at the [Tutorials](https://github.com/nitrain/tutorials) page. If you are interested more generally in medical imaging AI, check out [Practical medical imaging AI techniques with Python](https://book.nitrain.dev) (expected early 2025).

<br />

## Quickstart

Here is an example of using nitrain to a semantic segmentation model that demonstrates much of the core functionality.

```python
import nitrain as nt
from nitrain.readers import ImageReader, ColumnReader

# create dataset from folder of images + participants file
dataset = nt.Dataset(inputs=ImageReader('sub-*/anat/*_T1w.nii.gz'),
                     outputs=ImageReader('sub-*/anat/*_aparc+aseg.nii.gz'),
                     transforms={
                         'inputs': tx.NormalizeIntensity(0,1),
                         ('inputs', 'outputs'): tx.Resize((64,64,64))
                     },
                     base_dir='~/desktop/ds004711/')

# create loader with random transforms
loader = nt.Loader(dataset,
                   images_per_batch=4,
                   sampler=nt.SliceSampler(batch_size = 32, axis = 2)
                   transforms={
                           'inputs': tx.RandomNoise(sd=0.2)
                   })

# create model from architecture
arch_fn = nt.fetch_architecture('unet', dim=2)
model = arch_fn(input_image_size=(64,64,1),
                mode='segmentation')

# create trainer and fit model
trainer = nt.Trainer(model, task='segmentation')
trainer.fit(loader, epochs=100)
```

<br />

## Installation

The latest release of nitrain can be installed from pypi:

```
pip install nitrain
```

Or you can install the latest development version directly from github:

```
python -m pip install git+github.com/nitrain/nitrain.git
```

### Dependencies

The [ants](https://www.github.com/antsx/antspy) python package is a key dependency that allows you to efficiently read, operate on, and visualize medical images. Additionally, you can use keras (tf.keras or keras3), tensorflow, or pytorch as backend for creating your models.

<br />

## Resources

The following links can be helpful in becoming more familiar with nitrain.

- Introduction tutorials [[Link](https://github.com/nitrain/tutorials/tree/main/introduction)]
- Segmentation examples [[Link](https://github.com/nitrain/tutorials/tree/main/segmentation)]
- Classification examples [[Link](https://github.com/nitrain/tutorials/tree/main/classification)]
- Registration examples [[Link](https://github.com/nitrain/tutorials/tree/main/registration)]

You can also visit the [ANTsPy](https://github.com/antsx/antspy) repo to learn more about handling medical images and performing traditional medical imaging analysis.

<br />

## Contributing

If you have a question or bug report the best way to get help is by posting an issue on the GitHub page. I would be happy to welcome any new contributors or ideas to the project. If you want to add code, the best way to get started is by posting an issue or contacting me at nickcullen31@gmail.com.

You can support this work by starring the repository or posting a feature request in the issues tab. These actions help increase the project's impact and community reach.
↑