license: apache-2.0
tags:
- 视觉
- 图像分类
datasets:
- nih-pc-chex-mimic_ch-google-openi-rsna
densenet121-res224-rsna
DenseNet是一种卷积神经网络,通过密集块(Dense Blocks)利用层间的密集连接,将所有层(具有相同特征图尺寸)直接相互连接。为了保持前馈特性,每一层都会接收来自前面所有层的额外输入,并将其自身的特征图传递给后续所有层。
使用方法
以下是如何使用该模型对X光图像进行分类的示例:
注意:每个预训练模型有18个输出。all
模型训练了所有输出。但对于其他权重,某些目标未经过训练(因为训练数据集中不存在这些目标),将随机预测。有效的输出仅列在与权重对应的数据集的{dataset}.pathologies
字段中。
模型基准测试见:BENCHMARKS.md
import urllib.request
import skimage
import torch
import torch.nn.functional as F
import torchvision
import torchvision.transforms
import torchxrayvision as xrv
model_name = "densenet121-res224-rsna"
img_url = "https://huggingface.co/spaces/torchxrayvision/torchxrayvision-classifier/resolve/main/16747_3_1.jpg"
img_path = "xray.jpg"
urllib.request.urlretrieve(img_url, img_path)
model = xrv.models.get_model(model_name, from_hf_hub=True)
img = skimage.io.imread(img_path)
img = xrv.datasets.normalize(img, 255)
if len(img.shape) > 2:
img = img[:, :, 0]
if len(img.shape) < 2:
print("错误:图像维度低于2")
img = img[None, :, :]
transform = torchvision.transforms.Compose([xrv.datasets.XRayCenterCrop()])
img = transform(img)
with torch.no_grad():
img = torch.from_numpy(img).unsqueeze(0)
preds = model(img).cpu()
output = {
k: float(v)
for k, v in zip(xrv.datasets.default_pathologies, preds[0].detach().numpy())
}
print(output)
更多代码示例,请参考示例脚本。
引用
TorchXRayVision主要论文:https://arxiv.org/abs/2111.00595
Joseph Paul Cohen, Joseph D. Viviano, Paul Bertin, Paul Morrison, Parsa Torabian, Matteo Guarrera, Matthew P Lungren, Akshay Chaudhari, Rupert Brooks, Mohammad Hashir, Hadrien Bertrand
TorchXRayVision: 胸部X光数据集和模型库。
https://github.com/mlmed/torchxrayvision, 2020
@article{Cohen2020xrv,
author = {Cohen, Joseph Paul and Viviano, Joseph D. and Bertin, Paul and Morrison, Paul and Torabian, Parsa and Guarrera, Matteo and Lungren, Matthew P and Chaudhari, Akshay and Brooks, Rupert and Hashir, Mohammad and Bertrand, Hadrien},
journal = {https://github.com/mlmed/torchxrayvision},
title = {{TorchXRayVision: 胸部X光数据集和模型库}},
url = {https://github.com/mlmed/torchxrayvision},
year = {2020}
arxivId = {2111.00595},
}
以及该库开发的初始论文:https://arxiv.org/abs/2002.02497
Joseph Paul Cohen and Mohammad Hashir and Rupert Brooks and Hadrien Bertrand
关于自动化X光预测中跨域泛化的限制。
Medical Imaging with Deep Learning 2020 (在线: https://arxiv.org/abs/2002.02497)
@inproceedings{cohen2020limits,
title={关于自动化X光预测中跨域泛化的限制},
author={Cohen, Joseph Paul and Hashir, Mohammad and Brooks, Rupert and Bertrand, Hadrien},
booktitle={Medical Imaging with Deep Learning},
year={2020},
url={https://arxiv.org/abs/2002.02497}
}