-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
841 additions
and
1,020 deletions.
There are no files selected for viewing
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import argparse | ||
import matplotlib.pyplot as plt | ||
from dataloader import MRIDataset | ||
from residual3dunet.model import ResidualUNet3D, UNet3D | ||
from torch.utils.data import Dataset, DataLoader | ||
from torch.nn import DataParallel | ||
import numpy as np | ||
import torch | ||
import torchvision.transforms as T | ||
from utils.segmentation_statistics import SegmentationStatistics | ||
from utils.evaluate import evaluate | ||
from utils.utils import compute_average, load_checkpoint | ||
import os | ||
|
||
|
||
def get_args(): | ||
# Test settings | ||
parser = argparse.ArgumentParser(description='Evaluate using test loader') | ||
parser.add_argument('--network', '-u', default='Unet3D', help='Specify the network (Unet3D / ResidualUnet3D)') | ||
parser.add_argument('--model', '-m', default='model.pt', metavar='FILE', help='Specify the file in which the model is stored') | ||
parser.add_argument('--batch-size', type=int, default=1, metavar='N',help='input batch size for testing (default: 64)') | ||
parser.add_argument('--no-cuda', action='store_true', default=False, help='disables CUDA testing') | ||
parser.add_argument('--mask-threshold', '-t', type=float, default=0.5, help='Minimum probability value to consider a mask pixel white') | ||
|
||
return parser.parse_args() | ||
|
||
|
||
def main(): | ||
|
||
args = get_args() | ||
|
||
use_cuda = not args.no_cuda and torch.cuda.is_available() | ||
device = torch.device("cuda" if use_cuda else "cpu") | ||
|
||
model = ResidualUNet3D(in_channels=1, out_channels=1, testing=True).to(device) | ||
|
||
# If using multiple gpu | ||
# Specify network | ||
if args.network.casefold() == "unet3d": | ||
model = UNet3D(in_channels=1, out_channels=1, testing=True).to(device) | ||
|
||
else: | ||
model = ResidualUNet3D(in_channels=1, out_channels=1, testing=True).to(device) | ||
|
||
# If using multiple gpu | ||
if torch.cuda.device_count() > 1 and use_cuda: | ||
model = DataParallel(model) | ||
|
||
load_checkpoint(args.model, model ,device=device) | ||
|
||
test_kwargs = {'batch_size': args.batch_size} | ||
|
||
if use_cuda: | ||
cuda_kwargs = {'num_workers': 1, | ||
'pin_memory': True, | ||
'shuffle': True} | ||
test_kwargs.update(cuda_kwargs) | ||
|
||
testdataset = MRIDataset(train=False, transform=T.ToTensor()) | ||
test_loader = DataLoader(dataset=testdataset, **test_kwargs) | ||
|
||
evaluate(model, test_loader, device, args.mask_threshold, show_stat=True) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.