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
# (CC-NC-SA) Nasim Rahaman | |
import theano as th | |
import theano.tensor as T | |
import numpy as np | |
import time | |
# Weights | |
W = th.shared(value=np.random.uniform(size=(3, 3))) | |
# Input |
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
__author__ = "nasim.rahaman at iwr.uni-heidelberg.de" | |
__doc__ = """A few bells and whistles for the theano function callable. | |
Examples: | |
import theano.tensor as T | |
x = T.scalar() | |
y = T.scalar() | |
f1 = function(inputs={'x': x, 'y': y}, outputs={'z1': x + y, 'z2': x + 2*y}) | |
f1(x=2, y=3) |
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
import yaml | |
import numpy as np | |
import os | |
from theano import config | |
class relay(object): | |
def __init__(self, switches, ymlfile, callevery=1): |
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
import numpy as np | |
from scipy.ndimage.interpolation import map_coordinates | |
from scipy.ndimage.filters import gaussian_filter | |
# Elastic transform | |
def elastic_transformations(alpha, sigma, rng=np.random.RandomState(42), | |
interpolation_order=1): | |
"""Returns a function to elastically transform multiple images.""" | |
# Good values for: | |
# alpha: 2000 |
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
import torch | |
import torch.nn as nn | |
def log_sum_exp(x): | |
# See implementation detail in | |
# http://timvieira.github.io/blog/post/2014/02/11/exp-normalize-trick/ | |
# b is a shift factor. see link. | |
# x.size() = [N, C]: | |
b, _ = torch.max(x, 1) |
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
import torch | |
import torch.nn as nn | |
class ContinoulliWithLogitsLoss(nn.BCEWithLogitsLoss): | |
""" | |
Numerically stable implementation of the objective function defined in [1]. | |
[1] https://arxiv.org/abs/1907.06845 | |
""" |