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
class ScaledWSConv2d(nn.Conv2d): | |
"""2D Conv layer with Scaled Weight Standardization.""" | |
def __init__(self, in_channels, out_channels, kernel_size,stride=1, padding=0,dilation=1, groups=1, bias=True, gain=True,eps=1e-4): | |
nn.Conv2d.__init__(self, in_channels, out_channels,kernel_size, stride,padding, dilation,groups, bias) | |
if gain: | |
self.gain = nn.Parameter(torch.ones(self.out_channels, 1, 1, 1)) | |
else: | |
self.gain = None | |
# Epsilon, a small constant to avoid dividing by zero. | |
self.eps = eps |
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
# Keras layer implementation of "Fix your classifier: the marginal value of training the last weight layer" | |
# by Andres Torrubia, licensed under GPL 3: https://www.gnu.org/licenses/gpl-3.0.en.html | |
# https://arxiv.org/abs/1801.04540 | |
from keras import backend as K | |
from keras.engine.topology import Layer | |
from keras import activations | |
from keras.initializers import Constant, RandomUniform | |
import numpy as np | |
from scipy.linalg import hadamard |
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 os | |
import sys | |
import numpy as np | |
from skimage import io, exposure | |
import pydicom | |
import re | |
import time | |
from multiprocessing import Pool | |
from multiprocessing import cpu_count | |
from tqdm import tqdm |
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
# if you have iterm2 for osx (www.iterm2.com) this is a like print(...) for images in the console | |
import base64 | |
import cStringIO | |
import numpngw | |
import numpy as np | |
def show_image(a): | |
if a.dtype != np.uint8: | |
a = a.astype(np.uint8) |