This file contains hidden or 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 | |
import itertools | |
def Amat(kernel, size): | |
assert kernel.shape[0] == kernel.shape[1] | |
ksize = kernel.shape[0] | |
assert ksize % 2 | |
osize = (size + 1 - ksize) | |
A = np.zeros((osize ** 2, size ** 2)) | |
pos = lambda _1, _2, s: _1 * s + _2 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 itertools | |
import torch | |
def svd(x): | |
# https://discuss.pytorch.org/t/multidimensional-svd/4366/2 | |
batches = x.shape[:-2] | |
if batches: | |
n, m = x.shape[-2:] | |
k = min(n, m) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 | |
def map_nested(fn, structure, cond=lambda obj: isinstance(obj, torch.Tensor)): | |
r""" | |
Applies fn to an object in a possibly nested data structure and returns same | |
structure with every element changed if condition satisfied. | |
""" | |
def inner_map(obj): | |
if cond(obj): | |
return fn(obj) |
This file contains hidden or 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.nn | |
import collections | |
class Builder(object): | |
def __init__(self, *namespaces): | |
self._namespace = collections.ChainMap(*namespaces) | |
def __call__(self, name, *args, **kwargs): | |
try: | |
return self._namespace[name](*args, **kwargs) |
This file contains hidden or 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 sacred.observers | |
import tensorboardX | |
import os | |
class TensorboardObserver(sacred.observers.FileStorageObserver, tensorboardX.SummaryWriter): | |
VERSION = "TensorboardObserver-0.0.1" | |
def __init__(self, basedir, resource_dir=None, source_dir=None, | |
template=None, priority=sacred.observers.file_storage.DEFAULT_FILE_STORAGE_PRIORITY, |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.