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 as th | |
from torch.autograd import Variable | |
from torch.autograd.function import Function | |
class Symeig(Function): | |
def __init__(self, eigenvectors=True, upper=True): | |
self.eigenvectors = eigenvectors | |
self.upper = upper |
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
class MultiSampler(Sampler): | |
"""Samples elements more than once in a single pass through the data. | |
This allows the number of samples per epoch to be larger than the number | |
of samples itself, which can be useful for data augmentation. | |
""" | |
def __init__(self, nb_samples, desired_samples, shuffle=False): | |
self.data_samples = nb_samples | |
self.desired_samples = desired_samples | |
self.shuffle |
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
def pearsonr(x, y): | |
""" | |
Mimics `scipy.stats.pearsonr` | |
Arguments | |
--------- | |
x : 1D torch.Tensor | |
y : 1D torch.Tensor | |
Returns |
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
""" | |
Custom datasets from both in-memory and out-of-memory data | |
""" | |
import torch.utils.data as data | |
from PIL import Image | |
import os | |
import os.path |
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
""" | |
Affine transforms implemented on torch tensors, and | |
only requiring one interpolation | |
Included: | |
- Affine() | |
- AffineCompose() | |
- Rotation() | |
- Translation() | |
- Shear() |
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
def transform_matrix_offset_center(matrix, x, y): | |
o_x = float(x) / 2 + 0.5 | |
o_y = float(y) / 2 + 0.5 | |
offset_matrix = np.array([[1, 0, o_x], [0, 1, o_y], [0, 0, 1]]) | |
reset_matrix = np.array([[1, 0, -o_x], [0, 1, -o_y], [0, 0, 1]]) | |
transform_matrix = np.dot(np.dot(offset_matrix, matrix), reset_matrix) | |
return transform_matrix | |
def apply_transform(x, transform_matrix, channel_axis=2, fill_mode='nearest', fill_value=0.): | |
x = np.rollaxis(x, channel_axis, 0) |