-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
57 lines (45 loc) · 1.7 KB
/
main.py
File metadata and controls
57 lines (45 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from __future__ import print_function
import argparse
import numpy as np
import torch
import os
## Module
from dataLoader import get_datapath, DataSegmentationLoader
from utils import *
from models import UNet
from train import train
parser = argparse.ArgumentParser(description='Pytorch Brain Tumor Segmentation UNet')
parser.add_argument('--in_channel', default=3, type=int,
help='perturbation magnitude')
parser.add_argument('--out_channel', default=1, type=int,
help='perturbation magnitude')
parser.add_argument('--epochs', default=1, type=int,
help='perturbation magnitude')
parser.add_argument('--nfold', default=5, type=int,
help='perturbation magnitude')
parser.set_defaults(argument=True)
def seed_everything(seed: int = 42):
np.random.seed(seed)
os.environ["PYTHONHASHSEED"] = str(seed)
torch.manual_seed(seed)
def main():
# Import Data
global args
args = parser.parse_args()
#Use GPU
device = 'cuda' if torch.cuda.is_available() else 'cpu'
if torch.cuda.is_available():
print(f'CUDA is available. Your device is {device}.')
else:
print(f'CUDA is not available. Your device is {device}. It can take long time training in CPU.')
#Fix Seed
random_state = 42
seed_everything(random_state)
#Dataload
image, mask = get_datapath('./data/', random_state)
dataloader = DataSegmentationLoader(image, mask)
model = UNet(in_channels=args.in_channel, out_channels=args.out_channel).to(device)
loss = DiceLoss()
train(dataloader, model, loss, device, args.epochs, args.nfold)
if __name__ == '__main__':
main()