Esempio n. 1
0
from torch.optim.lr_scheduler import (
    CosineAnnealingLR,
    CosineAnnealingWarmRestarts,
    CyclicLR,
    ReduceLROnPlateau,
    StepLR,
)

from src.utils.mapper import configmapper

configmapper.map("schedulers", "step")(StepLR)
configmapper.map("schedulers", "cosineanneal")(CosineAnnealingLR)
configmapper.map("schedulers", "reduceplateau")(ReduceLROnPlateau)
configmapper.map("schedulers", "cyclic")(CyclicLR)
configmapper.map("schedulers",
                 "cosineannealrestart")(CosineAnnealingWarmRestarts)
"""Metrics."""
from sklearn.metrics import (
    mean_squared_error,
    f1_score,
    precision_score,
    recall_score,
    roc_auc_score,
    accuracy_score,
)
from src.utils.mapper import configmapper

configmapper.map("metrics", "sklearn_f1")(f1_score)
configmapper.map("metrics", "sklearn_p")(precision_score)
configmapper.map("metrics", "sklearn_r")(recall_score)
configmapper.map("metrics", "sklearn_roc")(roc_auc_score)
configmapper.map("metrics", "sklearn_acc")(accuracy_score)
configmapper.map("metrics", "sklearn_mse")(mean_squared_error)
Esempio n. 3
0
from transformers import AutoModelForTokenClassification, AutoModelForQuestionAnswering
from src.utils.mapper import configmapper

configmapper.map("models", "autotoken")(AutoModelForTokenClassification)
configmapper.map("models", "autospans")(AutoModelForQuestionAnswering)
Esempio n. 4
0
import torch.nn as nn
from src.utils.mapper import configmapper

configmapper.map("activations", "relu")(nn.ReLU)
configmapper.map("activations", "logsoftmax")(nn.LogSoftmax)
configmapper.map("activations", "softmax")(nn.Softmax)
Esempio n. 5
0
import matplotlib.pyplot as plt
import numpy as np
import torch
import torch_geometric.transforms as torch_geometric_transforms
import torchvision.transforms as transforms
from skimage.segmentation import slic
from torch_geometric.data import Data
from torch_scatter import scatter_mean

from src.utils.mapper import configmapper

configmapper.map("transforms", "Resize")(transforms.Resize)
configmapper.map("transforms", "Normalize")(transforms.Normalize)
configmapper.map("transforms", "ToTensor")(transforms.ToTensor)
configmapper.map("transforms", "ToPILImage")(transforms.ToPILImage)
configmapper.map("transforms", "Grayscale")(transforms.Grayscale)
configmapper.map("transforms",
                 "ToSLIC")(torch_geometric_transforms.to_superpixels.ToSLIC)
configmapper.map("transforms", "KNNGraph")(torch_geometric_transforms.KNNGraph)
configmapper.map("transforms",
                 "PolarTransformation")(torch_geometric_transforms.Polar)
configmapper.map("transforms",
                 "RadiusGraph")(torch_geometric_transforms.RadiusGraph)


# https://github.com/phcavelar/mnist-superpixel
@configmapper.map("transforms", "RAGGraph")
class RAGGraph(object):
    def __init__(self, add_seg=False, add_img=False, **kwargs):
        self.add_seg = add_seg
        self.add_img = add_img
"All criterion functions."
from torch.nn import MSELoss, CrossEntropyLoss
from src.utils.mapper import configmapper

configmapper.map("losses", "mse")(MSELoss)
configmapper.map("losses", "CrossEntropyLoss")(CrossEntropyLoss)
Esempio n. 7
0
" Method containing activation functions"
from torch.optim import SGD, Adam, AdamW

from src.utils.mapper import configmapper


configmapper.map("optimizers", "adam")(Adam)
configmapper.map("optimizers", "adam_w")(AdamW)
configmapper.map("optimizers", "sgd")(SGD)