Using custom dataset labels don't show up #1599
Unanswered
CharlieFengCN
asked this question in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi I'm using Unetr to run another public binary classification dataset - ATLAS R2.0 I made sure my json file is fine but why aren't my labels showing up when I do the data visualization This is my process for data extraction and image
`train_transforms = Compose(
[
LoadImaged(keys=["image", "label"]),
EnsureChannelFirstd(keys=["image", "label"]),
Orientationd(keys=["image", "label"], axcodes="RAS"),
ScaleIntensityRanged(
keys=["image"],
a_min=-50,
a_max=100,
b_min=0.0,
b_max=1.0,
clip=True,
),
# Spacingd(keys=["image", "label"], pixdim=(2.0, 2.0, 0.1), mode=("bilinear", "nearest")),
# CropForegroundd(keys=["image", "label"], source_key="image"),
# CenterSpatialCropd(keys=['image', 'label'], roi_size=(512,512,12)),
# Resize(spatial_size=(400, 400, 12)),
ResizeWithPadOrCropd(keys=["image", "label"], spatial_size=(197,233,189)),
RandCropByPosNegLabeld(
keys=["image", "label"],
label_key="label",
spatial_size=(96, 96, 96),
pos=1,
neg=1,
num_samples=8,
image_key="image",
image_threshold=0,
),
# RandAffined(
# keys=["image", "label"],
# mode=("bilinear", "nearest"),
# prob=1.0,
# spatial_size=(512, 512, 16),
# translate_range=(40, 40, 2),
# rotate_range=(np.pi / 36, np.pi / 36, np.pi / 4),
# scale_range=(0.15, 0.15, 0.15),
# padding_mode="border",
# ),
# RandGaussianNoised(keys=["image"], prob=0.10, std=0.1),
RandFlipd(
keys=["image", "label"],
spatial_axis=[0],
prob=0.10,
),
RandFlipd(
keys=["image", "label"],
spatial_axis=[1],
prob=0.10,
),
RandFlipd(
keys=["image", "label"],
spatial_axis=[2],
prob=0.10,
),
RandRotate90d(
keys=["image", "label"],
prob=0.10,
max_k=3,
),
RandShiftIntensityd(
keys=["image"],
offsets=0.10,
prob=0.50,
),
# CenterSpatialCropd(keys=['image', 'label'], roi_size=(352,352,16))
]
)
val_transforms = Compose(
[
LoadImaged(keys=["image", "label"]),
EnsureChannelFirstd(keys=["image", "label"]),
Orientationd(keys=["image", "label"], axcodes="RAS"),
# Spacingd(keys=["image", "label"], pixdim=(1.0, 1.0, 0.1), mode=("bilinear", "nearest")),
ScaleIntensityRanged(
keys=["image"],
a_min=-50,
a_max=100,
b_min=0.0,
b_max=1.0,
clip=True,
),
# CropForegroundd(keys=["image", "label"], source_key="image"),
# Resize(spatial_size=(400, 400, 12)),
ResizeWithPadOrCropd(keys=["image", "label"], spatial_size=(197,233,189)),
)
data_dir = r"/home/FCN/code/data"
split_json = "/dataset.json"
datasets = data_dir + split_json
datalist = load_decathlon_datalist(datasets, True, "training")
val_files = load_decathlon_datalist(datasets, True, "validation")
train_ds = CacheDataset(
data=datalist,
transform=train_transforms,
cache_num=24,
cache_rate=1.0,
num_workers=8,
)
device_ids = [i for i in range(torch.cuda.device_count())]
train_loader = DataLoader(train_ds, batch_size=1, shuffle=True, num_workers=0, pin_memory=True)
val_ds = CacheDataset(data=val_files, transform=val_transforms, cache_num=6, cache_rate=1.0, num_workers=4)
val_loader = DataLoader(val_ds, batch_size=1, shuffle=False, num_workers=0, pin_memory=True)
print(len(train_loader))
print(len(val_loader))`
`check_ds = Dataset(data=val_files, transform=val_transforms)
check_loader = DataLoader(check_ds, batch_size=1)
check_data = first(check_loader)
image, label = (check_data["image"][0][0], check_data["label"][0][0])
print(f"image shape: {image.shape}, label shape: {label.shape}")
plot the slice [:, :, 80]
plt.figure("check", (12, 6))
plt.subplot(1, 2, 1)
plt.title("image")
plt.imshow(image[:, :, 80], cmap="gray")
plt.subplot(1, 2, 2)
plt.title("label")
plt.imshow(label[:, :,80])
plt.show()`
Please tell me what's wrong . Thanks very much
Beta Was this translation helpful? Give feedback.
All reactions