Skip to content
Snippets Groups Projects
Commit d460e791 authored by Gudmundur's avatar Gudmundur
Browse files

Project update by Peter, minor path changes by Gudmundur

parent 1cecdb36
Branches main
No related tags found
No related merge requests found
Showing
with 1310 additions and 1296 deletions
File added
......@@ -4,6 +4,6 @@ same_size: False
mean: [0.0,0.0,0.0]
std: [1.0,1.0,1.0]
full_rot: 180
scale: (0.8, 1.2)
scale: [0.8, 1.2]
shear: 10
cutout: 16
\ No newline at end of file
ADAM:
lr: 0.001
betas: (0.9, 0.999)
betas: [0.9, 0.999]
eps: 1e-08
weight_decay: 0
......
......@@ -6,10 +6,11 @@ TRAIN:
CHECKPOINT_PERIOD: 2
AUTO_RESUME: True
DATA:
PATH_TO_DATA: r"C:\Users\ptrkm\PycharmProjects\BachelorDeeplearning\Embeddings\New_Embeddings"
PATH_TO_LABEL: r"C:\Users\ptrkm\PycharmProjects\BachelorDeeplearning\Embeddings\New_Embeddings"
PATH_TO_DIFFICULTIES: r"C:\Users\ptrkm\PycharmProjects\BachelorDeeplearning\Embeddings\New_Embeddings"
PATH_TO_SPLIT: r"C:\Users\ptrkm\PycharmProjects\BachelorDeeplearning\Embeddings\New_Embeddings"
PATH_TO_DATA: [data/processed/additional-dermoscopic-images,
data/processed/main-dermoscopic-images]
PATH_TO_LABEL: data/processed/labels.csv
PATH_TO_DIFFICULTIES: data/processed/difficulties.pkl
PATH_TO_SPLIT: data/processed/splits.pkl
NETWORK:
PATH_TO_SAVED: None
BACKBONE:
......@@ -24,11 +25,11 @@ NETWORK:
TRAINING:
BACKBONE:
MAX_EPOCH: 100
LOSS: contrastive
LOSS: Contrastive
EARLY_STOP_PATIENCE: 3
HEAD:
MAX_EPOCH: 20
LOSS: least_squares
LOSS: LeastSquares
EARLY_STOP_PATIENCE: 2
COMBINED:
MAX_EPOCH: 10
......@@ -39,17 +40,21 @@ SOLVER:
MOMENTUM: 0.9
WEIGHT_DECAY: 1e-4
WARMUP_START_LR: 0.01
OPTIMIZING_METHOD: ADAM
OPTIMIZER: ADAM
ALPHA: 0.5
AUGMENTATION:
NAME: ngessert
CONFIG: standard_augmenter.yaml
CONFIG: config_augmentations/standard_augmenter.yaml
TEST:
ENABLE: True
BATCH_SIZE: 64
DATA_LOADER:
NUM_WORKERS: 8
NUM_WORKERS: 0
PIN_MEMORY: True
EVAL_METRICS:
BACKBONE: knn
HEAD: MSE
NUM_GPUS: 1 # Not set up to handle more currently
NUM_SHARDS: 1
RNG_SEED: 0
OUTPUT_DIR: r"C:\Users\ptrkm\PycharmProjects\BachelorDeeplearning\Embeddings\New_Embeddings"
\ No newline at end of file
OUTPUT_DIR: r"data/output"
\ No newline at end of file
File added
......@@ -6,7 +6,7 @@ from torchvision import transforms, utils
import math
from PIL import Image
from numba import jit
import color_constancy as cc
# import color_constancy as cc
import pickle
from argparse import Namespace
......@@ -42,10 +42,9 @@ class DataAugmentISIC_AISC:
elif self.random_resize:
all_transforms.append(transforms.RandomResizedCrop(self.input_size[0], scale=(0.08, 1.0)))
all_transforms.append(cc.general_color_constancy(gaussian_differentiation=0, minkowski_norm=6, sigma=0))
# all_transforms.append(cc.general_color_constancy(gaussian_differentiation=0, minkowski_norm=6, sigma=0))
all_transforms.append(transforms.RandomHorizontalFlip())
all_transforms.append(transforms.RandomVerticalFlip())
all_transforms.append(transforms.RandomChoice([transforms.RandomAffine(model_params.get('full_rot',180),
scale=model_params.get('scale', (0.8,1.2)),
shear=model_params.get('shear', 10),
......@@ -69,7 +68,7 @@ class DataAugmentISIC_AISC:
self.composed_train = transforms.Compose(all_transforms)
self.composed_eval = transforms.Compose([
cc.general_color_constancy(gaussian_differentiation=0, minkowski_norm=6, sigma = 0),
# cc.general_color_constancy(gaussian_differentiation=0, minkowski_norm=6, sigma = 0),
transforms.Resize(self.input_size),
transforms.ToTensor(),
transforms.Normalize(np.float32(model_params.get('mean', np.array([0.0, 0.0, 0.0]))),
......@@ -148,7 +147,7 @@ class Cutout_v0(object):
DATA_AUGMENTERS = {'ngessert': DataAugmentISIC_AISC}
def get_data_augmenter(augment_params):
return DATA_AUGMENTERS[augment_params.NAME](augment_params.vals)
return DATA_AUGMENTERS[augment_params.name](augment_params.vals)
if __name__ == "__main__":
......
......@@ -4,13 +4,14 @@ from PIL import Image
import os
import pickle
import pandas as pd
from Embeddings.New_Embeddings.data_augmentations import augmentations as aug
from data_augmentations import augmentations as aug
class AISC(Dataset):
def __init__(self, dataset_params):
self.path_to_data = dataset_params.PATH_TO_DATA
self.path_to_labels = dataset_params.PATH_TO_LABELS
self.path_to_labels = dataset_params.PATH_TO_LABEL
self.path_to_difficulties = dataset_params.PATH_TO_DIFFICULTIES
self.path_to_split = dataset_params.PATH_TO_SPLIT
self.difficulties = None
......@@ -76,8 +77,8 @@ class AISC(Dataset):
labels = pd.read_csv(self.path_to_labels)
label_names = list(labels['names'])
labels = labels.drop('names', axis=1).values()
labels = labels.drop('names', axis=1)
labels = labels.values
return label_names, labels
def read_difficulties(self):
......@@ -86,6 +87,7 @@ class AISC(Dataset):
:return: (dict) with image names as keys (not full path) and difficulty as value
"""
if not os.path.isfile(self.path_to_difficulties):
breakpoint()
raise ValueError("Chosen path to difficulties is not a file on this device")
difficulties = pickle.load(open(self.path_to_difficulties, 'rb'))
......@@ -100,12 +102,15 @@ class AISC(Dataset):
temp = dict()
loading_order = dict()
for mode, names in split.items():
for split, val in split.items():
for mode, names in val.items():
temp[mode] = {
name: self.name_to_file_label_difficulty[name]
for name in names
}
loading_order[mode] = names
return temp, loading_order
def __getitem__(self, item):
......@@ -115,16 +120,18 @@ class AISC(Dataset):
:param item: (int) conforming to the index of names
:return: (tuple) of (torch.Tensor, torch.Tensor, torch.Tensor) of image, label and difficulty
"""
file, label, difficulty, has_diff = self.name_to_file_label_difficulty[
file, label, difficulty, has_diff = (self.name_to_file_label_difficulty[self.mode][
self.loading_order[self.mode][item]
]
]).values()
image = Image.open(file)
image = self.data_augmenter(image, self.mode)
label = torch.tensor(label)
label = torch.tensor(label).reshape(-1)
difficulty = torch.tensor(difficulty)
if self.mode == 'train':
return image, label, difficulty, has_diff
return image, label, difficulty
else:
return image, label, difficulty, file, has_diff
File added
File added
File added
File added
......@@ -3,12 +3,12 @@
def create_loss(losses, args):
alpha = args.ALPHA
alpha = args.SOLVER.ALPHA
loss_backbone = losses[0]
loss_head = losses[1]
def loss(embeddings, est_difficulties,labels, difficulties, score_keeper):
labels = labels.reshape(-1)
if score_keeper.is_training == 'backbone':
return loss_backbone(embeddings, labels)
if score_keeper.is_training == 'head':
......
......@@ -15,7 +15,8 @@ with the same name e.g. contrastive.yaml this should correspond to the string pu
when added it should also be added to the dictionary in the bottom named all_losses
"""
def get_contrastive(args):
return losses.ContrastiveLoss(args.pos_margin, args.neg_margin, **args.kwargs)
return losses.ContrastiveLoss(args.pos_margin, args.neg_margin)
def get_triplet_margin(args):
return losses.TripletMarginLoss(margin=args.margin,
......@@ -27,9 +28,9 @@ def get_triplet_margin(args):
all_losses = {
'contrastive': get_contrastive,
'triplet_marging': get_triplet_margin
'Contrastive': get_contrastive,
'TripletMarging': get_triplet_margin
}
def get_loss(loss, loss_args):
return all_losses[loss](loss_args)
return all_losses[loss](loss_args.__dict__[loss])
......@@ -5,7 +5,8 @@ from pytorch_metric_learning import losses
import torch.nn as nn
def get_least_squares(args):
return nn.MSELoss(reduction=args.reductions)
return nn.MSELoss(reduction=args.reduction)
def get_l1(args):
return nn.L1Loss(reduction=args.reductions)
......@@ -21,9 +22,10 @@ class KendallsTau(nn.modules.loss._Loss):
tau = 2/(len(difficulty) * (len(difficulty)-1)) * torch.sum(torch)
all_losses = {
'least_squares': get_least_squares,
'LeastSquares': get_least_squares,
'L1': get_l1,
}
def get_loss(loss, loss_args):
return all_losses[loss](loss_args)
\ No newline at end of file
return all_losses[loss](loss_args.__dict__[loss])
\ No newline at end of file
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment