Trying to resize storage that is not resizable #7654
Applewine33
started this conversation in
General
Replies: 1 comment
-
Hi @Applewine33, please share more information such as the whole error message and a small piece of code that can directly reproduce the issue. |
Beta Was this translation helpful? Give feedback.
0 replies
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.
-
I recond the model then I want to use test data to see whether the model work will it error with the message like title.
How can I get the right result?
Code :
import os
import json
import torch
import matplotlib.pyplot as plt
from monai.networks.nets import UNet
from monai.data import CacheDataset, DataLoader
from monai.inferers import sliding_window_inference
from monai.transforms import (
EnsureChannelFirstd,
Compose,
LoadImaged,
ScaleIntensityRanged,
Spacingd,
)
with open('data_split.json') as f:
data = json.load(f)
testing_set = data["testing"]
testing_transform = Compose([
LoadImaged(keys=["image", "label"]),
EnsureChannelFirstd(keys=["image", "label"]),
Spacingd(
keys=["image", "label"],
pixdim=[2.0, 2.0, 2.0]
),
ScaleIntensityRanged(
keys="image",
a_min=-125,
a_max=225,
b_min=0.0,
b_max=1.0
)
])
test_ds = CacheDataset(data=testing_set, transform=testing_transform, num_workers=4)
test_loader = DataLoader(test_ds, batch_size=1, shuffle=False, num_workers=4)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = UNet(
spatial_dims=3,
in_channels=1,
out_channels=3,
channels=(16, 32, 64, 128, 256),
strides=(2, 2, 2, 2),
num_res_units=2
).to(device)
model.load_state_dict(torch.load(os.path.join(".", "best_metric_model.pth")))
model.eval()
y_true = []
y_pred = []
with torch.no_grad():
for test_data in test_loader:
test_images, test_labels = (
test_data["image"].to(device),
test_data["label"].to(device),
)
pred = model(test_images).argmax(dim=1)
for i in range(len(pred)):
y_true.append(test_labels[i].item())
y_pred.append(pred[i].item())
print(classification_report(
y_true, y_pred, target_names=class_names, digits=4))
Beta Was this translation helpful? Give feedback.
All reactions