Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
assert (len(self.input_layer.get_output_shape()) == 4), \
'Input must have 4 dimensions.'
assert (self.input_layer.data_order == layers.data_order.type1), \
'Input data order does not match this layer\'s data order.'
def get_output_shape(self):
input_shape = self.input_layer.get_output_shape()
return (input_shape[1], input_shape[2], input_shape[3], input_shape[0])
def output(self, *args, **kwargs):
input = self.input_layer.output(*args, **kwargs)
return input.dimshuffle(1, 2, 3, 0)
class Deconv2DNoBiasLayerGuidedBackProp(Deconv2DNoBiasLayer):
def output(self, input=None, dropout_active=True, *args, **kwargs):
if input is None:
input = self.input_layer.output(dropout_active=dropout_active,
*args, **kwargs)
if dropout_active and (self.dropout > 0.):
retain_prob = 1 - self.dropout
mask = layers.srng.binomial(input.shape, p=retain_prob,
dtype='int32').astype('float32')
# apply the input mask and rescale the input accordingly.
# By doing this it's no longer necessary to rescale the weights
# at test time.
input = input / retain_prob * mask
contiguous_input = gpu_contiguous(input)
contiguous_filters = gpu_contiguous(self.W)
filter_size=5,
weights_std=winit2,
nonlinearity=nonlinearity,
pad=2)
pool2 = cc_layers.Pooling2DLayer(conv2, 2, stride=2)
conv3 = cc_layers.Conv2DNoBiasLayer(
pool2,
n_filters=256,
filter_size=5,
weights_std=winit3,
nonlinearity=nonlinearity,
pad=2)
deconv3 = cc_layers.Deconv2DNoBiasLayer(
conv3, conv3, nonlinearity=layers.identity)
unpool4 = cc_layers.Unpooling2DLayer(deconv3, pool2)
deconv4 = cc_layers.Deconv2DNoBiasLayer(
unpool4, conv2, nonlinearity=layers.identity)
unpool5 = cc_layers.Unpooling2DLayer(deconv4, pool1)
output = cc_layers.Deconv2DNoBiasLayer(
unpool5, conv1, nonlinearity=layers.identity)
class SupervisedModel(anna.models.SupervisedModel):
batch = 128
input = cc_layers.Input2DLayer(batch, 3, 96, 96)
k = float(numpy.random.rand()*1+0.2)
print '## k = %.3f' % k
winit1 = k/numpy.sqrt(5*5*3)
winit2 = k/numpy.sqrt(5*5*64)
winit3 = k/numpy.sqrt(5*5*128)
binit = 0.0
def trec(x):
return x*(x > 0.0)
nonlinearity = trec
conv1 = cc_layers.Conv2DNoBiasLayer(
input,
n_filters=96,
filter_size=5,
weights_std=winit1,
nonlinearity=nonlinearity,
pad=2)
pool1 = cc_layers.Pooling2DLayer(conv1, 2, stride=2)
unpool2 = cc_layers.Unpooling2DLayer(pool1, pool1)
output = cc_layers.Deconv2DNoBiasLayer(
unpool2, conv1, nonlinearity=layers.identity)
class CAELayer2Model(anna.models.UnsupervisedModel):
batch = 128
input = cc_layers.Input2DLayer(batch, 3, 32, 32)
k = float(numpy.random.rand()*1+0.2)
print '## k = %.3f' % k
winit1 = k/numpy.sqrt(5*5*3)
winit2 = k/numpy.sqrt(5*5*96)
binit = 0.0
def trec(x):
return x*(x > 0.0)
n_filters=64,
filter_size=5,
weights_std=winit1,
nonlinearity=nonlinearity,
pad=2)
pool1 = cc_layers.Pooling2DLayer(conv1, 2, stride=2)
conv2 = cc_layers.Conv2DNoBiasLayer(
pool1,
n_filters=128,
filter_size=5,
weights_std=winit2,
nonlinearity=nonlinearity,
pad=2)
pool2 = cc_layers.Pooling2DLayer(conv2, 2, stride=2)
unpool3 = cc_layers.Unpooling2DLayer(pool2, pool2)
deconv3 = cc_layers.Deconv2DNoBiasLayer(
unpool3, conv2, nonlinearity=layers.identity)
unpool4 = cc_layers.Unpooling2DLayer(deconv3, pool1)
output = cc_layers.Deconv2DNoBiasLayer(
unpool4, conv1, nonlinearity=layers.identity)
class CAELayer3Model(anna.models.UnsupervisedModel):
batch = 128
input = cc_layers.Input2DLayer(batch, 3, 96, 96)
k = float(numpy.random.rand()*1+0.2)
print '## k = %.3f' % k
winit1 = k/numpy.sqrt(5*5*3)
winit2 = k/numpy.sqrt(5*5*64)
winit3 = k/numpy.sqrt(5*5*128)
binit = 0.0
filter_size=5,
weights_std=winit2,
nonlinearity=nonlinearity,
pad=2)
pool2 = cc_layers.Pooling2DLayer(conv2, 2, stride=2)
conv3 = cc_layers.Conv2DNoBiasLayer(
pool2,
n_filters=256,
filter_size=5,
weights_std=winit3,
nonlinearity=nonlinearity,
pad=2)
deconv4 = cc_layers.Deconv2DNoBiasLayer(
conv3, conv3, nonlinearity=layers.identity)
unpool5 = cc_layers.Unpooling2DLayer(deconv4, pool2)
deconv5 = cc_layers.Deconv2DNoBiasLayer(
unpool5, conv2, nonlinearity=layers.identity)
unpool6 = cc_layers.Unpooling2DLayer(deconv5, pool1)
output = cc_layers.Deconv2DNoBiasLayer(
unpool6, conv1, nonlinearity=layers.identity)
class CNNModel(anna.models.SupervisedModel):
batch = 128
input = cc_layers.Input2DLayer(batch, 3, 96, 96)
k = float(numpy.random.rand()*1+0.2)
print '## k = %.3f' % k
winit1 = k/numpy.sqrt(5*5*3)
winit2 = k/numpy.sqrt(5*5*64)
winit3 = k/numpy.sqrt(5*5*128)
binit = 0.0
def trec(x):
return x*(x > 0.0)
nonlinearity = trec
conv1 = cc_layers.Conv2DNoBiasLayer(
input,
n_filters=64,
filter_size=5,
weights_std=winit1,
nonlinearity=nonlinearity,
pad=2)
pool1 = cc_layers.Pooling2DLayer(conv1, 2, stride=2)
unpool2 = cc_layers.Unpooling2DLayer(pool1, pool1)
output = cc_layers.Deconv2DNoBiasLayer(
unpool2, conv1, nonlinearity=layers.identity)
class CAELayer2Model(anna.models.UnsupervisedModel):
batch = 128
input = cc_layers.Input2DLayer(batch, 3, 96, 96)
k = float(numpy.random.rand()*1+0.2)
print '## k = %.3f' % k
winit1 = k/numpy.sqrt(5*5*3)
winit2 = k/numpy.sqrt(5*5*64)
binit = 0.0
def trec(x):
return x*(x > 0.0)
pad=2)
pool2 = cc_layers.Pooling2DLayer(conv2, 2, stride=2)
conv3 = cc_layers.Conv2DNoBiasLayer(
pool2,
n_filters=256,
filter_size=5,
weights_std=winit3,
nonlinearity=nonlinearity,
pad=2)
deconv3 = cc_layers.Deconv2DNoBiasLayer(
conv3, conv3, nonlinearity=layers.identity)
unpool4 = cc_layers.Unpooling2DLayer(deconv3, pool2)
deconv4 = cc_layers.Deconv2DNoBiasLayer(
unpool4, conv2, nonlinearity=layers.identity)
unpool5 = cc_layers.Unpooling2DLayer(deconv4, pool1)
output = cc_layers.Deconv2DNoBiasLayer(
unpool5, conv1, nonlinearity=layers.identity)
class SupervisedModel(anna.models.SupervisedModel):
batch = 128
input = cc_layers.Input2DLayer(batch, 3, 96, 96)
k = float(numpy.random.rand()*1+0.2)
print '## k = %.3f' % k
winit1 = k/numpy.sqrt(5*5*3)
winit2 = k/numpy.sqrt(5*5*64)
winit3 = k/numpy.sqrt(5*5*128)
binit = 0.0
def trec(x):
return x*(x > 0.0)
n_filters=96,
filter_size=5,
weights_std=winit1,
nonlinearity=nonlinearity,
pad=2)
pool1 = cc_layers.Pooling2DLayer(conv1, 2, stride=2)
conv2 = cc_layers.Conv2DNoBiasLayer(
pool1,
n_filters=144,
filter_size=5,
weights_std=winit2,
nonlinearity=nonlinearity,
pad=2)
pool2 = cc_layers.Pooling2DLayer(conv2, 2, stride=2)
unpool3 = cc_layers.Unpooling2DLayer(pool2, pool2)
deconv3 = cc_layers.Deconv2DNoBiasLayer(
unpool3, conv2, nonlinearity=layers.identity)
unpool4 = cc_layers.Unpooling2DLayer(deconv3, pool1)
output = cc_layers.Deconv2DNoBiasLayer(
unpool4, conv1, nonlinearity=layers.identity)
class CAELayer3Model(anna.models.UnsupervisedModel):
batch = 128
input = cc_layers.Input2DLayer(batch, 3, 32, 32)
k = float(numpy.random.rand()*1+0.2)
print '## k = %.3f' % k
winit1 = k/numpy.sqrt(5*5*3)
winit2 = k/numpy.sqrt(5*5*96)
winit3 = k/numpy.sqrt(5*5*144)
binit = 0.0
nonlinearity=nonlinearity,
pad=2)
pool1 = cc_layers.Pooling2DLayer(conv1, 2, stride=2)
conv2 = cc_layers.Conv2DNoBiasLayer(
pool1,
n_filters=144,
filter_size=5,
weights_std=winit2,
nonlinearity=nonlinearity,
pad=2)
pool2 = cc_layers.Pooling2DLayer(conv2, 2, stride=2)
unpool3 = cc_layers.Unpooling2DLayer(pool2, pool2)
deconv3 = cc_layers.Deconv2DNoBiasLayer(
unpool3, conv2, nonlinearity=layers.identity)
unpool4 = cc_layers.Unpooling2DLayer(deconv3, pool1)
output = cc_layers.Deconv2DNoBiasLayer(
unpool4, conv1, nonlinearity=layers.identity)
class CAELayer3Model(anna.models.UnsupervisedModel):
batch = 128
input = cc_layers.Input2DLayer(batch, 3, 32, 32)
k = float(numpy.random.rand()*1+0.2)
print '## k = %.3f' % k
winit1 = k/numpy.sqrt(5*5*3)
winit2 = k/numpy.sqrt(5*5*96)
winit3 = k/numpy.sqrt(5*5*144)
binit = 0.0
def trec(x):
return x*(x > 0.0)
conv2 = cc_layers.Conv2DNoBiasLayer(
pool1,
n_filters=128,
filter_size=5,
weights_std=winit2,
nonlinearity=nonlinearity,
pad=2)
pool2 = cc_layers.Pooling2DLayer(conv2, 2, stride=2)
conv3 = cc_layers.Conv2DNoBiasLayer(
pool2,
n_filters=256,
filter_size=5,
weights_std=winit3,
nonlinearity=nonlinearity,
pad=2)
deconv4 = cc_layers.Deconv2DNoBiasLayer(
conv3, conv3, nonlinearity=layers.identity)
unpool5 = cc_layers.Unpooling2DLayer(deconv4, pool2)
deconv5 = cc_layers.Deconv2DNoBiasLayer(
unpool5, conv2, nonlinearity=layers.identity)
unpool6 = cc_layers.Unpooling2DLayer(deconv5, pool1)
output = cc_layers.Deconv2DNoBiasLayer(
unpool6, conv1, nonlinearity=layers.identity)
class CNNModel(anna.models.SupervisedModel):
batch = 128
input = cc_layers.Input2DLayer(batch, 3, 96, 96)
k = float(numpy.random.rand()*1+0.2)
print '## k = %.3f' % k
winit1 = k/numpy.sqrt(5*5*3)