From 54b11b081021f7da15f6b0bc79b5598a6f963407 Mon Sep 17 00:00:00 2001 From: Nic Ma Date: Fri, 25 Sep 2020 00:46:38 +0800 Subject: [PATCH 1/2] [DLMED] add FHIR datalist Signed-off-by: Nic Ma --- .../torch/densenet_evaluation_array.py | 23 +- .../torch/densenet_evaluation_dict.py | 24 +- .../torch/densenet_training_array.py | 33 +- .../torch/densenet_training_dict.py | 34 +- 3d_classification/torch/ixi_datalist.json | 460 ++++++++++++++++++ 5 files changed, 494 insertions(+), 80 deletions(-) create mode 100644 3d_classification/torch/ixi_datalist.json diff --git a/3d_classification/torch/densenet_evaluation_array.py b/3d_classification/torch/densenet_evaluation_array.py index 43428ba4d5..5828d9aec5 100644 --- a/3d_classification/torch/densenet_evaluation_array.py +++ b/3d_classification/torch/densenet_evaluation_array.py @@ -12,7 +12,7 @@ import logging import os import sys - +import json import numpy as np import torch from torch.utils.data import DataLoader @@ -27,21 +27,14 @@ def main(): logging.basicConfig(stream=sys.stdout, level=logging.INFO) # IXI dataset as a demo, downloadable from https://brain-development.org/ixi-dataset/ - images = [ - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI607-Guys-1097-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI175-HH-1570-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI385-HH-2078-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI344-Guys-0905-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI409-Guys-0960-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI584-Guys-1129-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI253-HH-1694-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI092-HH-1436-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI574-IOP-1156-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI585-Guys-1130-T1.nii.gz"]), - ] - + # here we load part of the datalist from FHIR format config file + with open("ixi_datalist.json") as ixi_datalist: + datalist = json.load(ixi_datalist) + dirpath = os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1"]) + images = [os.path.join(dirpath, datalist["entry"][i]["resource"]["content"]["url"]) for i in range(21, 30)] # 2 binary labels for gender classification: man and woman - labels = np.array([0, 0, 1, 0, 1, 0, 1, 0, 1, 0], dtype=np.int64) + labels = [0 if datalist["entry"][i]["resource"]["note"]["text"] == "man" else 1 for i in range(21, 30)] + labels = np.array(labels, dtype=np.int64) # Define transforms for image val_transforms = Compose([ScaleIntensity(), AddChannel(), Resize((96, 96, 96)), ToTensor()]) diff --git a/3d_classification/torch/densenet_evaluation_dict.py b/3d_classification/torch/densenet_evaluation_dict.py index 0d6b2420fb..4c889b2610 100644 --- a/3d_classification/torch/densenet_evaluation_dict.py +++ b/3d_classification/torch/densenet_evaluation_dict.py @@ -12,7 +12,7 @@ import logging import os import sys - +import json import numpy as np import torch from torch.utils.data import DataLoader @@ -27,21 +27,15 @@ def main(): logging.basicConfig(stream=sys.stdout, level=logging.INFO) # IXI dataset as a demo, downloadable from https://brain-development.org/ixi-dataset/ - images = [ - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI607-Guys-1097-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI175-HH-1570-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI385-HH-2078-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI344-Guys-0905-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI409-Guys-0960-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI584-Guys-1129-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI253-HH-1694-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI092-HH-1436-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI574-IOP-1156-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI585-Guys-1130-T1.nii.gz"]), - ] - + # here we load part of the datalist from FHIR format config file + with open("ixi_datalist.json") as ixi_datalist: + datalist = json.load(ixi_datalist) + dirpath = os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1"]) + images = [os.path.join(dirpath, datalist["entry"][i]["resource"]["content"]["url"]) for i in range(21, 30)] # 2 binary labels for gender classification: man and woman - labels = np.array([0, 0, 1, 0, 1, 0, 1, 0, 1, 0], dtype=np.int64) + labels = [0 if datalist["entry"][i]["resource"]["note"]["text"] == "man" else 1 for i in range(21, 30)] + labels = np.array(labels, dtype=np.int64) + val_files = [{"img": img, "label": label} for img, label in zip(images, labels)] # Define transforms for image diff --git a/3d_classification/torch/densenet_training_array.py b/3d_classification/torch/densenet_training_array.py index a0712a4a57..dc91f0a846 100644 --- a/3d_classification/torch/densenet_training_array.py +++ b/3d_classification/torch/densenet_training_array.py @@ -12,7 +12,7 @@ import logging import os import sys - +import json import numpy as np import torch from torch.utils.data import DataLoader @@ -28,31 +28,14 @@ def main(): logging.basicConfig(stream=sys.stdout, level=logging.INFO) # IXI dataset as a demo, downloadable from https://brain-development.org/ixi-dataset/ - images = [ - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI314-IOP-0889-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI249-Guys-1072-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI609-HH-2600-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI173-HH-1590-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI020-Guys-0700-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI342-Guys-0909-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI134-Guys-0780-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI577-HH-2661-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI066-Guys-0731-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI130-HH-1528-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI607-Guys-1097-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI175-HH-1570-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI385-HH-2078-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI344-Guys-0905-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI409-Guys-0960-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI584-Guys-1129-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI253-HH-1694-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI092-HH-1436-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI574-IOP-1156-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI585-Guys-1130-T1.nii.gz"]), - ] - + # here we load part of the datalist from FHIR format config file + with open("ixi_datalist.json") as ixi_datalist: + datalist = json.load(ixi_datalist) + dirpath = os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1"]) + images = [os.path.join(dirpath, datalist["entry"][i]["resource"]["content"]["url"]) for i in range(0, 20)] # 2 binary labels for gender classification: man and woman - labels = np.array([0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0], dtype=np.int64) + labels = [0 if datalist["entry"][i]["resource"]["note"]["text"] == "man" else 1 for i in range(0, 20)] + labels = np.array(labels, dtype=np.int64) # Define transforms train_transforms = Compose([ScaleIntensity(), AddChannel(), Resize((96, 96, 96)), RandRotate90(), ToTensor()]) diff --git a/3d_classification/torch/densenet_training_dict.py b/3d_classification/torch/densenet_training_dict.py index 6d4a590e87..078c4ba84c 100644 --- a/3d_classification/torch/densenet_training_dict.py +++ b/3d_classification/torch/densenet_training_dict.py @@ -12,7 +12,7 @@ import logging import os import sys - +import json import numpy as np import torch from torch.utils.data import DataLoader @@ -28,31 +28,15 @@ def main(): logging.basicConfig(stream=sys.stdout, level=logging.INFO) # IXI dataset as a demo, downloadable from https://brain-development.org/ixi-dataset/ - images = [ - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI314-IOP-0889-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI249-Guys-1072-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI609-HH-2600-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI173-HH-1590-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI020-Guys-0700-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI342-Guys-0909-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI134-Guys-0780-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI577-HH-2661-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI066-Guys-0731-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI130-HH-1528-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI607-Guys-1097-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI175-HH-1570-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI385-HH-2078-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI344-Guys-0905-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI409-Guys-0960-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI584-Guys-1129-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI253-HH-1694-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI092-HH-1436-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI574-IOP-1156-T1.nii.gz"]), - os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1", "IXI585-Guys-1130-T1.nii.gz"]), - ] - + # here we load part of the datalist from FHIR format config file + with open("ixi_datalist.json") as ixi_datalist: + datalist = json.load(ixi_datalist) + dirpath = os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1"]) + images = [os.path.join(dirpath, datalist["entry"][i]["resource"]["content"]["url"]) for i in range(0, 20)] # 2 binary labels for gender classification: man and woman - labels = np.array([0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0], dtype=np.int64) + labels = [0 if datalist["entry"][i]["resource"]["note"]["text"] == "man" else 1 for i in range(0, 20)] + labels = np.array(labels, dtype=np.int64) + train_files = [{"img": img, "label": label} for img, label in zip(images[:10], labels[:10])] val_files = [{"img": img, "label": label} for img, label in zip(images[-10:], labels[-10:])] diff --git a/3d_classification/torch/ixi_datalist.json b/3d_classification/torch/ixi_datalist.json new file mode 100644 index 0000000000..c8d8501f43 --- /dev/null +++ b/3d_classification/torch/ixi_datalist.json @@ -0,0 +1,460 @@ +{ + "resourceType": "Bundle", + "id": "ixi-datalist", + "meta": { + "lastUpdated": "2020-09-25T01:00:00Z" + }, + "type": "batch", + "entry": [ + { + "resource": { + "resourceType": "Media", + "id": "1", + "status": "unknown", + "type": "image", + "content": { + "contentType": "image/nifti", + "url": "IXI314-IOP-0889-T1.nii.gz" + }, + "note": { + "text": "man" + } + } + }, + { + "resource": { + "resourceType": "Media", + "id": "2", + "status": "unknown", + "type": "image", + "content": { + "contentType": "image/nifti", + "url": "IXI249-Guys-1072-T1.nii.gz" + }, + "note": { + "text": "man" + } + } + }, + { + "resource": { + "resourceType": "Media", + "id": "3", + "status": "unknown", + "type": "image", + "content": { + "contentType": "image/nifti", + "url": "IXI609-HH-2600-T1.nii.gz" + }, + "note": { + "text": "man" + } + } + }, + { + "resource": { + "resourceType": "Media", + "id": "4", + "status": "unknown", + "type": "image", + "content": { + "contentType": "image/nifti", + "url": "IXI173-HH-1590-T1.nii.gz" + }, + "note": { + "text": "woman" + } + } + }, + { + "resource": { + "resourceType": "Media", + "id": "5", + "status": "unknown", + "type": "image", + "content": { + "contentType": "image/nifti", + "url": "IXI020-Guys-0700-T1.nii.gz" + }, + "note": { + "text": "man" + } + } + }, + { + "resource": { + "resourceType": "Media", + "id": "6", + "status": "unknown", + "type": "image", + "content": { + "contentType": "image/nifti", + "url": "IXI342-Guys-0909-T1.nii.gz" + }, + "note": { + "text": "man" + } + } + }, + { + "resource": { + "resourceType": "Media", + "id": "7", + "status": "unknown", + "type": "image", + "content": { + "contentType": "image/nifti", + "url": "IXI134-Guys-0780-T1.nii.gz" + }, + "note": { + "text": "man" + } + } + }, + { + "resource": { + "resourceType": "Media", + "id": "8", + "status": "unknown", + "type": "image", + "content": { + "contentType": "image/nifti", + "url": "IXI577-HH-2661-T1.nii.gz" + }, + "note": { + "text": "woman" + } + } + }, + { + "resource": { + "resourceType": "Media", + "id": "9", + "status": "unknown", + "type": "image", + "content": { + "contentType": "image/nifti", + "url": "IXI066-Guys-0731-T1.nii.gz" + }, + "note": { + "text": "woman" + } + } + }, + { + "resource": { + "resourceType": "Media", + "id": "10", + "status": "unknown", + "type": "image", + "content": { + "contentType": "image/nifti", + "url": "IXI130-HH-1528-T1.nii.gz" + }, + "note": { + "text": "man" + } + } + }, + { + "resource": { + "resourceType": "Media", + "id": "11", + "status": "unknown", + "type": "image", + "content": { + "contentType": "image/nifti", + "url": "IXI607-Guys-1097-T1.nii.gz" + }, + "note": { + "text": "man" + } + } + }, + { + "resource": { + "resourceType": "Media", + "id": "12", + "status": "unknown", + "type": "image", + "content": { + "contentType": "image/nifti", + "url": "IXI175-HH-1570-T1.nii.gz" + }, + "note": { + "text": "man" + } + } + }, + { + "resource": { + "resourceType": "Media", + "id": "13", + "status": "unknown", + "type": "image", + "content": { + "contentType": "image/nifti", + "url": "IXI385-HH-2078-T1.nii.gz" + }, + "note": { + "text": "woman" + } + } + }, + { + "resource": { + "resourceType": "Media", + "id": "14", + "status": "unknown", + "type": "image", + "content": { + "contentType": "image/nifti", + "url": "IXI344-Guys-0905-T1.nii.gz" + }, + "note": { + "text": "man" + } + } + }, + { + "resource": { + "resourceType": "Media", + "id": "15", + "status": "unknown", + "type": "image", + "content": { + "contentType": "image/nifti", + "url": "IXI409-Guys-0960-T1.nii.gz" + }, + "note": { + "text": "woman" + } + } + }, + { + "resource": { + "resourceType": "Media", + "id": "16", + "status": "unknown", + "type": "image", + "content": { + "contentType": "image/nifti", + "url": "IXI584-Guys-1129-T1.nii.gz" + }, + "note": { + "text": "man" + } + } + }, + { + "resource": { + "resourceType": "Media", + "id": "17", + "status": "unknown", + "type": "image", + "content": { + "contentType": "image/nifti", + "url": "IXI253-HH-1694-T1.nii.gz" + }, + "note": { + "text": "woman" + } + } + }, + { + "resource": { + "resourceType": "Media", + "id": "18", + "status": "unknown", + "type": "image", + "content": { + "contentType": "image/nifti", + "url": "IXI092-HH-1436-T1.nii.gz" + }, + "note": { + "text": "man" + } + } + }, + { + "resource": { + "resourceType": "Media", + "id": "19", + "status": "unknown", + "type": "image", + "content": { + "contentType": "image/nifti", + "url": "IXI574-IOP-1156-T1.nii.gz" + }, + "note": { + "text": "woman" + } + } + }, + { + "resource": { + "resourceType": "Media", + "id": "20", + "status": "unknown", + "type": "image", + "content": { + "contentType": "image/nifti", + "url": "IXI585-Guys-1130-T1.nii.gz" + }, + "note": { + "text": "man" + } + } + }, + { + "resource": { + "resourceType": "Media", + "id": "21", + "status": "unknown", + "type": "image", + "content": { + "contentType": "image/nifti", + "url": "IXI607-Guys-1097-T1.nii.gz" + }, + "note": { + "text": "man" + } + } + }, + { + "resource": { + "resourceType": "Media", + "id": "22", + "status": "unknown", + "type": "image", + "content": { + "contentType": "image/nifti", + "url": "IXI175-HH-1570-T1.nii.gz" + }, + "note": { + "text": "man" + } + } + }, + { + "resource": { + "resourceType": "Media", + "id": "23", + "status": "unknown", + "type": "image", + "content": { + "contentType": "image/nifti", + "url": "IXI385-HH-2078-T1.nii.gz" + }, + "note": { + "text": "woman" + } + } + }, + { + "resource": { + "resourceType": "Media", + "id": "24", + "status": "unknown", + "type": "image", + "content": { + "contentType": "image/nifti", + "url": "IXI344-Guys-0905-T1.nii.gz" + }, + "note": { + "text": "man" + } + } + }, + { + "resource": { + "resourceType": "Media", + "id": "25", + "status": "unknown", + "type": "image", + "content": { + "contentType": "image/nifti", + "url": "IXI409-Guys-0960-T1.nii.gz" + }, + "note": { + "text": "woman" + } + } + }, + { + "resource": { + "resourceType": "Media", + "id": "26", + "status": "unknown", + "type": "image", + "content": { + "contentType": "image/nifti", + "url": "IXI584-Guys-1129-T1.nii.gz" + }, + "note": { + "text": "man" + } + } + }, + { + "resource": { + "resourceType": "Media", + "id": "27", + "status": "unknown", + "type": "image", + "content": { + "contentType": "image/nifti", + "url": "IXI253-HH-1694-T1.nii.gz" + }, + "note": { + "text": "woman" + } + } + }, + { + "resource": { + "resourceType": "Media", + "id": "28", + "status": "unknown", + "type": "image", + "content": { + "contentType": "image/nifti", + "url": "IXI092-HH-1436-T1.nii.gz" + }, + "note": { + "text": "man" + } + } + }, + { + "resource": { + "resourceType": "Media", + "id": "29", + "status": "unknown", + "type": "image", + "content": { + "contentType": "image/nifti", + "url": "IXI574-IOP-1156-T1.nii.gz" + }, + "note": { + "text": "woman" + } + } + }, + { + "resource": { + "resourceType": "Media", + "id": "30", + "status": "unknown", + "type": "image", + "content": { + "contentType": "image/nifti", + "url": "IXI585-Guys-1130-T1.nii.gz" + }, + "note": { + "text": "man" + } + } + } + ] +} From 47726ad738c3615a2362020fcbdb802a20c1e8f1 Mon Sep 17 00:00:00 2001 From: Nic Ma Date: Fri, 16 Oct 2020 19:23:57 +0800 Subject: [PATCH 2/2] [DLMED] update according to comments --- .../torch/densenet_evaluation_array.py | 5 +- .../torch/densenet_evaluation_dict.py | 5 +- .../torch/densenet_training_array.py | 5 +- .../torch/densenet_training_dict.py | 5 +- 3d_classification/torch/ixi_datalist.json | 122 +++++++++--------- 5 files changed, 77 insertions(+), 65 deletions(-) diff --git a/3d_classification/torch/densenet_evaluation_array.py b/3d_classification/torch/densenet_evaluation_array.py index 5828d9aec5..07f4650120 100644 --- a/3d_classification/torch/densenet_evaluation_array.py +++ b/3d_classification/torch/densenet_evaluation_array.py @@ -31,7 +31,10 @@ def main(): with open("ixi_datalist.json") as ixi_datalist: datalist = json.load(ixi_datalist) dirpath = os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1"]) - images = [os.path.join(dirpath, datalist["entry"][i]["resource"]["content"]["url"]) for i in range(21, 30)] + images = list() + for i in range(21, 30): + filename = datalist["entry"][i]["resource"]["content"]["url"].split("//")[-1] + images.append(os.path.join(dirpath, filename)) # 2 binary labels for gender classification: man and woman labels = [0 if datalist["entry"][i]["resource"]["note"]["text"] == "man" else 1 for i in range(21, 30)] labels = np.array(labels, dtype=np.int64) diff --git a/3d_classification/torch/densenet_evaluation_dict.py b/3d_classification/torch/densenet_evaluation_dict.py index 4c889b2610..e00b85305a 100644 --- a/3d_classification/torch/densenet_evaluation_dict.py +++ b/3d_classification/torch/densenet_evaluation_dict.py @@ -31,7 +31,10 @@ def main(): with open("ixi_datalist.json") as ixi_datalist: datalist = json.load(ixi_datalist) dirpath = os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1"]) - images = [os.path.join(dirpath, datalist["entry"][i]["resource"]["content"]["url"]) for i in range(21, 30)] + images = list() + for i in range(21, 30): + filename = datalist["entry"][i]["resource"]["content"]["url"].split("//")[-1] + images.append(os.path.join(dirpath, filename)) # 2 binary labels for gender classification: man and woman labels = [0 if datalist["entry"][i]["resource"]["note"]["text"] == "man" else 1 for i in range(21, 30)] labels = np.array(labels, dtype=np.int64) diff --git a/3d_classification/torch/densenet_training_array.py b/3d_classification/torch/densenet_training_array.py index dc91f0a846..46e6483ff6 100644 --- a/3d_classification/torch/densenet_training_array.py +++ b/3d_classification/torch/densenet_training_array.py @@ -32,7 +32,10 @@ def main(): with open("ixi_datalist.json") as ixi_datalist: datalist = json.load(ixi_datalist) dirpath = os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1"]) - images = [os.path.join(dirpath, datalist["entry"][i]["resource"]["content"]["url"]) for i in range(0, 20)] + images = list() + for i in range(0, 20): + filename = datalist["entry"][i]["resource"]["content"]["url"].split("//")[-1] + images.append(os.path.join(dirpath, filename)) # 2 binary labels for gender classification: man and woman labels = [0 if datalist["entry"][i]["resource"]["note"]["text"] == "man" else 1 for i in range(0, 20)] labels = np.array(labels, dtype=np.int64) diff --git a/3d_classification/torch/densenet_training_dict.py b/3d_classification/torch/densenet_training_dict.py index 078c4ba84c..8cabfff777 100644 --- a/3d_classification/torch/densenet_training_dict.py +++ b/3d_classification/torch/densenet_training_dict.py @@ -32,7 +32,10 @@ def main(): with open("ixi_datalist.json") as ixi_datalist: datalist = json.load(ixi_datalist) dirpath = os.sep.join(["workspace", "data", "medical", "ixi", "IXI-T1"]) - images = [os.path.join(dirpath, datalist["entry"][i]["resource"]["content"]["url"]) for i in range(0, 20)] + images = list() + for i in range(0, 20): + filename = datalist["entry"][i]["resource"]["content"]["url"].split("//")[-1] + images.append(os.path.join(dirpath, filename)) # 2 binary labels for gender classification: man and woman labels = [0 if datalist["entry"][i]["resource"]["note"]["text"] == "man" else 1 for i in range(0, 20)] labels = np.array(labels, dtype=np.int64) diff --git a/3d_classification/torch/ixi_datalist.json b/3d_classification/torch/ixi_datalist.json index c8d8501f43..3cadfe54fa 100644 --- a/3d_classification/torch/ixi_datalist.json +++ b/3d_classification/torch/ixi_datalist.json @@ -4,7 +4,7 @@ "meta": { "lastUpdated": "2020-09-25T01:00:00Z" }, - "type": "batch", + "type": "collection", "entry": [ { "resource": { @@ -13,8 +13,8 @@ "status": "unknown", "type": "image", "content": { - "contentType": "image/nifti", - "url": "IXI314-IOP-0889-T1.nii.gz" + "contentType": "application/x-gzip", + "url": "file://IXI314-IOP-0889-T1.nii.gz" }, "note": { "text": "man" @@ -28,8 +28,8 @@ "status": "unknown", "type": "image", "content": { - "contentType": "image/nifti", - "url": "IXI249-Guys-1072-T1.nii.gz" + "contentType": "application/x-gzip", + "url": "file://IXI249-Guys-1072-T1.nii.gz" }, "note": { "text": "man" @@ -43,8 +43,8 @@ "status": "unknown", "type": "image", "content": { - "contentType": "image/nifti", - "url": "IXI609-HH-2600-T1.nii.gz" + "contentType": "application/x-gzip", + "url": "file://IXI609-HH-2600-T1.nii.gz" }, "note": { "text": "man" @@ -58,8 +58,8 @@ "status": "unknown", "type": "image", "content": { - "contentType": "image/nifti", - "url": "IXI173-HH-1590-T1.nii.gz" + "contentType": "application/x-gzip", + "url": "file://IXI173-HH-1590-T1.nii.gz" }, "note": { "text": "woman" @@ -73,8 +73,8 @@ "status": "unknown", "type": "image", "content": { - "contentType": "image/nifti", - "url": "IXI020-Guys-0700-T1.nii.gz" + "contentType": "application/x-gzip", + "url": "file://IXI020-Guys-0700-T1.nii.gz" }, "note": { "text": "man" @@ -88,8 +88,8 @@ "status": "unknown", "type": "image", "content": { - "contentType": "image/nifti", - "url": "IXI342-Guys-0909-T1.nii.gz" + "contentType": "application/x-gzip", + "url": "file://IXI342-Guys-0909-T1.nii.gz" }, "note": { "text": "man" @@ -103,8 +103,8 @@ "status": "unknown", "type": "image", "content": { - "contentType": "image/nifti", - "url": "IXI134-Guys-0780-T1.nii.gz" + "contentType": "application/x-gzip", + "url": "file://IXI134-Guys-0780-T1.nii.gz" }, "note": { "text": "man" @@ -118,8 +118,8 @@ "status": "unknown", "type": "image", "content": { - "contentType": "image/nifti", - "url": "IXI577-HH-2661-T1.nii.gz" + "contentType": "application/x-gzip", + "url": "file://IXI577-HH-2661-T1.nii.gz" }, "note": { "text": "woman" @@ -133,8 +133,8 @@ "status": "unknown", "type": "image", "content": { - "contentType": "image/nifti", - "url": "IXI066-Guys-0731-T1.nii.gz" + "contentType": "application/x-gzip", + "url": "file://IXI066-Guys-0731-T1.nii.gz" }, "note": { "text": "woman" @@ -148,8 +148,8 @@ "status": "unknown", "type": "image", "content": { - "contentType": "image/nifti", - "url": "IXI130-HH-1528-T1.nii.gz" + "contentType": "application/x-gzip", + "url": "file://IXI130-HH-1528-T1.nii.gz" }, "note": { "text": "man" @@ -163,8 +163,8 @@ "status": "unknown", "type": "image", "content": { - "contentType": "image/nifti", - "url": "IXI607-Guys-1097-T1.nii.gz" + "contentType": "application/x-gzip", + "url": "file://IXI607-Guys-1097-T1.nii.gz" }, "note": { "text": "man" @@ -178,8 +178,8 @@ "status": "unknown", "type": "image", "content": { - "contentType": "image/nifti", - "url": "IXI175-HH-1570-T1.nii.gz" + "contentType": "application/x-gzip", + "url": "file://IXI175-HH-1570-T1.nii.gz" }, "note": { "text": "man" @@ -193,8 +193,8 @@ "status": "unknown", "type": "image", "content": { - "contentType": "image/nifti", - "url": "IXI385-HH-2078-T1.nii.gz" + "contentType": "application/x-gzip", + "url": "file://IXI385-HH-2078-T1.nii.gz" }, "note": { "text": "woman" @@ -208,8 +208,8 @@ "status": "unknown", "type": "image", "content": { - "contentType": "image/nifti", - "url": "IXI344-Guys-0905-T1.nii.gz" + "contentType": "application/x-gzip", + "url": "file://IXI344-Guys-0905-T1.nii.gz" }, "note": { "text": "man" @@ -223,8 +223,8 @@ "status": "unknown", "type": "image", "content": { - "contentType": "image/nifti", - "url": "IXI409-Guys-0960-T1.nii.gz" + "contentType": "application/x-gzip", + "url": "file://IXI409-Guys-0960-T1.nii.gz" }, "note": { "text": "woman" @@ -238,8 +238,8 @@ "status": "unknown", "type": "image", "content": { - "contentType": "image/nifti", - "url": "IXI584-Guys-1129-T1.nii.gz" + "contentType": "application/x-gzip", + "url": "file://IXI584-Guys-1129-T1.nii.gz" }, "note": { "text": "man" @@ -253,8 +253,8 @@ "status": "unknown", "type": "image", "content": { - "contentType": "image/nifti", - "url": "IXI253-HH-1694-T1.nii.gz" + "contentType": "application/x-gzip", + "url": "file://IXI253-HH-1694-T1.nii.gz" }, "note": { "text": "woman" @@ -268,8 +268,8 @@ "status": "unknown", "type": "image", "content": { - "contentType": "image/nifti", - "url": "IXI092-HH-1436-T1.nii.gz" + "contentType": "application/x-gzip", + "url": "file://IXI092-HH-1436-T1.nii.gz" }, "note": { "text": "man" @@ -283,8 +283,8 @@ "status": "unknown", "type": "image", "content": { - "contentType": "image/nifti", - "url": "IXI574-IOP-1156-T1.nii.gz" + "contentType": "application/x-gzip", + "url": "file://IXI574-IOP-1156-T1.nii.gz" }, "note": { "text": "woman" @@ -298,8 +298,8 @@ "status": "unknown", "type": "image", "content": { - "contentType": "image/nifti", - "url": "IXI585-Guys-1130-T1.nii.gz" + "contentType": "application/x-gzip", + "url": "file://IXI585-Guys-1130-T1.nii.gz" }, "note": { "text": "man" @@ -313,8 +313,8 @@ "status": "unknown", "type": "image", "content": { - "contentType": "image/nifti", - "url": "IXI607-Guys-1097-T1.nii.gz" + "contentType": "application/x-gzip", + "url": "file://IXI607-Guys-1097-T1.nii.gz" }, "note": { "text": "man" @@ -328,8 +328,8 @@ "status": "unknown", "type": "image", "content": { - "contentType": "image/nifti", - "url": "IXI175-HH-1570-T1.nii.gz" + "contentType": "application/x-gzip", + "url": "file://IXI175-HH-1570-T1.nii.gz" }, "note": { "text": "man" @@ -343,8 +343,8 @@ "status": "unknown", "type": "image", "content": { - "contentType": "image/nifti", - "url": "IXI385-HH-2078-T1.nii.gz" + "contentType": "application/x-gzip", + "url": "file://IXI385-HH-2078-T1.nii.gz" }, "note": { "text": "woman" @@ -358,8 +358,8 @@ "status": "unknown", "type": "image", "content": { - "contentType": "image/nifti", - "url": "IXI344-Guys-0905-T1.nii.gz" + "contentType": "application/x-gzip", + "url": "file://IXI344-Guys-0905-T1.nii.gz" }, "note": { "text": "man" @@ -373,8 +373,8 @@ "status": "unknown", "type": "image", "content": { - "contentType": "image/nifti", - "url": "IXI409-Guys-0960-T1.nii.gz" + "contentType": "application/x-gzip", + "url": "file://IXI409-Guys-0960-T1.nii.gz" }, "note": { "text": "woman" @@ -388,8 +388,8 @@ "status": "unknown", "type": "image", "content": { - "contentType": "image/nifti", - "url": "IXI584-Guys-1129-T1.nii.gz" + "contentType": "application/x-gzip", + "url": "file://IXI584-Guys-1129-T1.nii.gz" }, "note": { "text": "man" @@ -403,8 +403,8 @@ "status": "unknown", "type": "image", "content": { - "contentType": "image/nifti", - "url": "IXI253-HH-1694-T1.nii.gz" + "contentType": "application/x-gzip", + "url": "file://IXI253-HH-1694-T1.nii.gz" }, "note": { "text": "woman" @@ -418,8 +418,8 @@ "status": "unknown", "type": "image", "content": { - "contentType": "image/nifti", - "url": "IXI092-HH-1436-T1.nii.gz" + "contentType": "application/x-gzip", + "url": "file://IXI092-HH-1436-T1.nii.gz" }, "note": { "text": "man" @@ -433,8 +433,8 @@ "status": "unknown", "type": "image", "content": { - "contentType": "image/nifti", - "url": "IXI574-IOP-1156-T1.nii.gz" + "contentType": "application/x-gzip", + "url": "file://IXI574-IOP-1156-T1.nii.gz" }, "note": { "text": "woman" @@ -448,8 +448,8 @@ "status": "unknown", "type": "image", "content": { - "contentType": "image/nifti", - "url": "IXI585-Guys-1130-T1.nii.gz" + "contentType": "application/x-gzip", + "url": "file://IXI585-Guys-1130-T1.nii.gz" }, "note": { "text": "man"