コード例 #1
0
    from utils.inference import inference_phase_rUNet
    from models import rUNet
# data_dir = sys.argv[1]
# saved_models = sys.argv[2]
data_dir = '/data/uob'
saved_models = '/data/uob/saved_models/trained_6positions_multi_loss'

training_dist = [2, 4, 10, 20, 25, 35]
unseen_dist = [1, 3, 15, 30]

dataset_folder = os.path.join(data_dir, 'dataset')
root_path = partial(os.path.join, saved_models)

regex = re.compile(r'\d+')

selected_testdata = select_dist(dist_list=training_dist,
                                root_folder=dataset_folder)
selected_unseen = select_dist(dist_list=unseen_dist,
                              root_folder=dataset_folder)

data_loaders_test, data_lengths_test = define_dataset(
    dataset_folder,
    batch_size=8,
    include_list=selected_testdata,
    alldata=False)

print(data_lengths_test)

data_loaders_unseen, data_lengths_unseen = define_dataset(
    dataset_folder, batch_size=8, include_list=selected_unseen, alldata=True)
print(data_lengths_unseen)
コード例 #2
0
except ModuleNotFoundError:
    from utils.data import define_dataset, select_dist
    from utils.training import retrain_rUNet_multi_loss
    from models import rUNet, dice_loss
    from utils.data.transformers import ChannelsFirst, Rescale, ToTensor, Crop, GaussianNoise, RandomCrop, Swap, \
        FlipUD, FlipLR
SEED = 42
torch.manual_seed(SEED)
np.random.seed(SEED)

DATA_DIR_DEEPTHOUGHT = "/storage/yw18581/data"

DATA_DIR = DATA_DIR_DEEPTHOUGHT
SRC_DIR = os.path.join("/", "storage", "yw18581", "src", "leaf_reco")
ROOT_DIR = os.path.join(DATA_DIR, "dataset")
EXCLUDED = select_dist(dist_list=[1, 3, 15, 30], root_folder=ROOT_DIR)
print(EXCLUDED)

base_transformers = [
    Crop(row_slice=slice(0, 1400), col_slice=slice(1000, None)),
    Rescale(scale=0.25),
    ChannelsFirst(),
    ToTensor()
]
#train_transformers = [RandomCrop(p=1), Swap(p=0.7), FlipLR(p=0.7), FlipUD(p=0.7),
#                      GaussianNoise(p=0.75, mean=30, sigma=2), Rescale(0.25), ChannelsFirst(),ToTensor()]
#print("Load dataset")

#data_loaders, data_length = define_dataset(root_folder=ROOT_DIR, base_transformers=base_transformers,
#                                           train_transformers=train_transformers,
#                                           batch_size=16, excluded_list=EXCLUDED,
コード例 #3
0
    from .models import UNet, dice_loss
except ModuleNotFoundError:
    from utils.data import define_dataset, select_dist
    from utils.training import training_UNet
    from models import UNet, dice_loss


SEED = 8
torch.manual_seed(SEED)
np.random.seed(SEED)

DATA_DIR_DEEPTHOUGHT = "/storage/yw18581/data"
data_dir = DATA_DIR_DEEPTHOUGHT
src_dir = os.path.join("/", "storage", "yw18581", "src", "leaf_reco")
root_dir = os.path.join(data_dir, "dataset")
selected_distances = select_dist(dist_list=[2, 4, 10, 25], root_folder=root_dir, keys_list=['first'])
excluded_distances = select_dist(root_folder=root_dir, keys_list=['second', 'third'])
print(selected_distances)

print("Load dataset")
data_loaders, data_lengths = define_dataset(root_folder=root_dir, batch_size=16, include_list=selected_distances,
                                            excluded_list=excluded_distances, multi_processing=4)

print(data_lengths)
print("Define model")
n_epochs = 100

torch.cuda.empty_cache()
print("Train model")
model = UNet()
optimizer = optim.Adam(model.parameters(), lr=1e-4)
コード例 #4
0
from utils.training import training_phase_rUNet_multi_loss
import numpy as np
from models import rUNet, dice_loss
import torch
import torch.optim as optim
import torch.nn as nn

SEED = 8
torch.manual_seed(SEED)
np.random.seed(SEED)

DATA_DIR_DEEPTHOUGHT = "/storage/yw18581/data"
data_dir = DATA_DIR_DEEPTHOUGHT
src_dir = os.path.join("/", "storage", "yw18581", "src", "leaf_reco")
root_dir = os.path.join(data_dir, "dataset")
selected_distances = select_dist(dist_list=[2, 4, 10, 20, 25, 35],
                                 root_folder=root_dir)
print(selected_distances)

print("Load dataset")
data_loaders, data_lengths = define_dataset(root_folder=root_dir,
                                            batch_size=32,
                                            include_list=selected_distances,
                                            multi_processing=4)

print(data_lengths)
print("Define model")
#coeffs = [0.70, 0.75, 0.60]
coeffs = [0.25, 0.30, 0.40]
n_epochs = 100

for coef in coeffs:
コード例 #5
0
    from models import rUNet
import torch

#data_dir = sys.argv[1]
#saved_models = sys.argv[2]
data_dir = '/storage/yw18581/data'
saved_models = '/storage/yw18581/src/leaf_reco/saved_models/trained_6positions'

distances_unseen = [2, 4, 10, 20, 25, 35]
distances_testdata = [1, 3, 15, 30]

dataset_folder = os.path.join(data_dir, 'dataset')

regex = re.compile(r'\d+')

excluded_testdata = select_dist(dist_list=distances_testdata,
                                root_folder=dataset_folder)
excluded_unseen = select_dist(dist_list=distances_unseen,
                              root_folder=dataset_folder)

data_loaders_test, data_lengths_test = define_dataset(
    dataset_folder,
    batch_size=8,
    excluded_list=excluded_testdata,
    alldata=False)

print(data_lengths_test)

data_loaders_unseen, data_lengths_unseen = define_dataset(
    dataset_folder, batch_size=8, excluded_list=excluded_unseen, alldata=True)
print(data_lengths_unseen)
コード例 #6
0
from utils.training import training_phase_rUNet
import numpy as np
from models import rUNet, dice_loss
import torch
import torch.optim as optim
import torch.nn as nn

SEED = 42
torch.manual_seed(SEED)
np.random.seed(SEED)

DATA_DIR_DEEPTHOUGHT = "/storage/yw18581/data"
data_dir = DATA_DIR_DEEPTHOUGHT
src_dir = os.path.join("/", "storage", "yw18581", "src", "leaf_reco")
root_dir = os.path.join(data_dir, "dataset")
excluded = select_dist(dist_list=[1, 3, 15, 30], root_folder=root_dir)
print(excluded)

print("Load dataset")
data_loaders, data_lengths = define_dataset(root_folder=root_dir, batch_size=16, excluded_list=excluded,
                                            multi_processing=4)

print(data_lengths)
print("Define model")
coeffs = [0.75, 0.70, 0.60, 0.50]
coeffs_2 = [0.25, 0.30, 0.40]
n_epochs = 100

for coef in coeffs_2:
    print("combined loss: {}*dice_loss + {} mse".format(coef, 1.0 - coef))
    torch.cuda.empty_cache()