Python lasagne.init.Normal() Examples
The following are 20
code examples of lasagne.init.Normal().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
lasagne.init
, or try the search function
.
Example #1
Source File: models_uncond.py From EvolutionaryGAN with MIT License | 6 votes |
def build_discriminator_toy(image=None, nd=512, GP_norm=None): Input = InputLayer(shape=(None, 2), input_var=image) print ("Dis input:", Input.output_shape) dis0 = DenseLayer(Input, nd, W=Normal(0.02), nonlinearity=relu) print ("Dis fc0:", dis0.output_shape) if GP_norm is True: dis1 = DenseLayer(dis0, nd, W=Normal(0.02), nonlinearity=relu) else: dis1 = batch_norm(DenseLayer(dis0, nd, W=Normal(0.02), nonlinearity=relu)) print ("Dis fc1:", dis1.output_shape) if GP_norm is True: dis2 = batch_norm(DenseLayer(dis1, nd, W=Normal(0.02), nonlinearity=relu)) else: dis2 = DenseLayer(dis1, nd, W=Normal(0.02), nonlinearity=relu) print ("Dis fc2:", dis2.output_shape) disout = DenseLayer(dis2, 1, W=Normal(0.02), nonlinearity=sigmoid) print ("Dis output:", disout.output_shape) return disout
Example #2
Source File: models_uncond.py From EvolutionaryGAN with MIT License | 6 votes |
def build_generator_32(noise=None, ngf=128): # noise input InputNoise = InputLayer(shape=(None, 100), input_var=noise) #FC Layer gnet0 = DenseLayer(InputNoise, ngf*4*4*4, W=Normal(0.02), nonlinearity=relu) print ("Gen fc1:", gnet0.output_shape) #Reshape Layer gnet1 = ReshapeLayer(gnet0,([0],ngf*4,4,4)) print ("Gen rs1:", gnet1.output_shape) # DeConv Layer gnet2 = Deconv2DLayer(gnet1, ngf*2, (4,4), (2,2), crop=1, W=Normal(0.02),nonlinearity=relu) print ("Gen deconv1:", gnet2.output_shape) # DeConv Layer gnet3 = Deconv2DLayer(gnet2, ngf, (4,4), (2,2), crop=1, W=Normal(0.02),nonlinearity=relu) print ("Gen deconv2:", gnet3.output_shape) # DeConv Layer gnet4 = Deconv2DLayer(gnet3, 3, (4,4), (2,2), crop=1, W=Normal(0.02),nonlinearity=tanh) print ("Gen output:", gnet4.output_shape) return gnet4
Example #3
Source File: models_uncond.py From EvolutionaryGAN with MIT License | 6 votes |
def build_discriminator_32(image=None,ndf=128): lrelu = LeakyRectify(0.2) # input: images InputImg = InputLayer(shape=(None, 3, 32, 32), input_var=image) print ("Dis Img_input:", InputImg.output_shape) # Conv Layer dis1 = Conv2DLayer(InputImg, ndf, (4,4), (2,2), pad=1, W=Normal(0.02), nonlinearity=lrelu) print ("Dis conv1:", dis1.output_shape) # Conv Layer dis2 = batch_norm(Conv2DLayer(dis1, ndf*2, (4,4), (2,2), pad=1, W=Normal(0.02), nonlinearity=lrelu)) print ("Dis conv2:", dis2.output_shape) # Conv Layer dis3 = batch_norm(Conv2DLayer(dis2, ndf*4, (4,4), (2,2), pad=1, W=Normal(0.02), nonlinearity=lrelu)) print ("Dis conv3:", dis3.output_shape) # Conv Layer dis4 = DenseLayer(dis3, 1, W=Normal(0.02), nonlinearity=sigmoid) print ("Dis output:", dis4.output_shape) return dis4
Example #4
Source File: models_uncond.py From EvolutionaryGAN with MIT License | 6 votes |
def build_generator_64(noise=None, ngf=128): # noise input InputNoise = InputLayer(shape=(None, 100), input_var=noise) #FC Layer gnet0 = DenseLayer(InputNoise, ngf*8*4*4, W=Normal(0.02), nonlinearity=relu) print ("Gen fc1:", gnet0.output_shape) #Reshape Layer gnet1 = ReshapeLayer(gnet0,([0],ngf*8,4,4)) print ("Gen rs1:", gnet1.output_shape) # DeConv Layer gnet2 = Deconv2DLayer(gnet1, ngf*8, (4,4), (2,2), crop=1, W=Normal(0.02),nonlinearity=relu) print ("Gen deconv2:", gnet2.output_shape) # DeConv Layer gnet3 = Deconv2DLayer(gnet2, ngf*4, (4,4), (2,2), crop=1, W=Normal(0.02),nonlinearity=relu) print ("Gen deconv3:", gnet3.output_shape) # DeConv Layer gnet4 = Deconv2DLayer(gnet3, ngf*4, (4,4), (2,2), crop=1, W=Normal(0.02),nonlinearity=relu) print ("Gen deconv4:", gnet4.output_shape) # DeConv Layer gnet5 = Deconv2DLayer(gnet4, ngf*2, (4,4), (2,2), crop=1, W=Normal(0.02),nonlinearity=relu) print ("Gen deconv5:", gnet5.output_shape) # DeConv Layer gnet6 = Deconv2DLayer(gnet5, 3, (3,3), (1,1), crop='same', W=Normal(0.02),nonlinearity=tanh) print ("Gen output:", gnet6.output_shape) return gnet6
Example #5
Source File: layers_theano.py From visual_dynamics with MIT License | 6 votes |
def __init__(self, incomings, Q=init.Normal(std=0.001), R=init.Normal(std=0.001), S=init.Normal(std=0.001), b=init.Constant(0.), **kwargs): super(BilinearChannelwiseLayer, self).__init__(incomings, **kwargs) self.y_shape, self.u_shape = [input_shape[1:] for input_shape in self.input_shapes] self.c_dim = self.y_shape[0] self.y_dim = int(np.prod(self.y_shape[1:])) self.u_dim, = self.u_shape self.Q = self.add_param(Q, (self.c_dim, self.y_dim, self.y_dim, self.u_dim), name='Q') self.R = self.add_param(R, (self.c_dim, self.y_dim, self.u_dim), name='R') self.S = self.add_param(S, (self.c_dim, self.y_dim, self.y_dim), name='S') if b is None: self.b = None else: self.b = self.add_param(b, (self.c_dim, self.y_dim), name='b', regularizable=False)
Example #6
Source File: models_uncond.py From EvolutionaryGAN with MIT License | 6 votes |
def build_discriminator_128(image=None,ndf=128): lrelu = LeakyRectify(0.2) # input: images InputImg = InputLayer(shape=(None, 3, 128, 128), input_var=image) print ("Dis Img_input:", InputImg.output_shape) # Conv Layer dis1 = Conv2DLayer(InputImg, ndf, (4,4), (2,2), pad=1, W=Normal(0.02), nonlinearity=lrelu) print ("Dis conv1:", dis1.output_shape) # Conv Layer dis2 = batch_norm(Conv2DLayer(dis1, ndf*2, (4,4), (2,2), pad=1, W=Normal(0.02), nonlinearity=lrelu)) print ("Dis conv2:", dis2.output_shape) # Conv Layer dis3 = batch_norm(Conv2DLayer(dis2, ndf*4, (4,4), (2,2), pad=1, W=Normal(0.02), nonlinearity=lrelu)) print ("Dis conv3:", dis3.output_shape) # Conv Layer dis4 = batch_norm(Conv2DLayer(dis3, ndf*8, (4,4), (2,2), pad=1, W=Normal(0.02), nonlinearity=lrelu)) print ("Dis conv3:", dis4.output_shape) # Conv Layer dis5 = batch_norm(Conv2DLayer(dis4, ndf*16, (4,4), (2,2), pad=1, W=Normal(0.02), nonlinearity=lrelu)) print ("Dis conv4:", dis5.output_shape) # Conv Layer dis6 = DenseLayer(dis5, 1, W=Normal(0.02), nonlinearity=sigmoid) print ("Dis output:", dis6.output_shape) return dis6
Example #7
Source File: layers_theano.py From visual_dynamics with MIT License | 6 votes |
def __init__(self, incomings, axis=1, Q=init.Normal(std=0.001), R=init.Normal(std=0.001), S=init.Normal(std=0.001), b=init.Constant(0.), **kwargs): """ axis: The first axis of Y to be lumped into a single bilinear model. The bilinear model are computed independently for each element wrt the preceding axes. """ super(BilinearLayer, self).__init__(incomings, **kwargs) assert axis >= 1 self.axis = axis self.y_shape, self.u_shape = [input_shape[1:] for input_shape in self.input_shapes] self.y_dim = int(np.prvod(self.y_shape[self.axis-1:])) self.u_dim, = self.u_shape self.Q = self.add_param(Q, (self.y_dim, self.y_dim, self.u_dim), name='Q') self.R = self.add_param(R, (self.y_dim, self.u_dim), name='R') self.S = self.add_param(S, (self.y_dim, self.y_dim), name='S') if b is None: self.b = None else: self.b = self.add_param(b, (self.y_dim,), name='b', regularizable=False)
Example #8
Source File: layers.py From gogh-figure with GNU Affero General Public License v3.0 | 5 votes |
def style_conv_block(conv_in, num_styles, num_filters, filter_size, stride, nonlinearity=rectify, normalization=instance_norm): sc_network = ReflectLayer(conv_in, filter_size//2) sc_network = normalization(ConvLayer(sc_network, num_filters, filter_size, stride, nonlinearity=nonlinearity, W=Normal()), num_styles=num_styles) return sc_network
Example #9
Source File: layers.py From Neural-Photo-Editor with MIT License | 5 votes |
def pd(num_layers=2,num_filters=32,filter_size=(3,3),pad=1,stride = (1,1),nonlinearity=elu,style='convolutional',bnorm=1,**kwargs): input_args = locals() input_args.pop('num_layers') return {key:entry if type(entry) is list else [entry]*num_layers for key,entry in input_args.iteritems()} # Possible Conv2DDNN convenience function. Remember to delete the C2D import at the top if you use this # def C2D(incoming = None, num_filters = 32, filter_size= [3,3],pad = 'same',stride = [1,1], W = initmethod('relu'),nonlinearity = elu,name = None): # return lasagne.layers.dnn.Conv2DDNNLayer(incoming,num_filters,filter_size,stride,pad,False,W,None,nonlinearity,False) # Shape-Preserving Gaussian Sample layer for latent vectors with spatial dimensions. # This is a holdover from an "old" (i.e. I abandoned it last month) idea.
Example #10
Source File: layers.py From Neural-Photo-Editor with MIT License | 5 votes |
def InceptionUpscaleLayer(incoming,param_dict,block_name): branch = [0]*len(param_dict) # Loop across branches for i,dict in enumerate(param_dict): for j,style in enumerate(dict['style']): # Loop up branch branch[i] = TC2D( incoming = branch[i] if j else incoming, num_filters = dict['num_filters'][j], filter_size = dict['filter_size'][j], crop = dict['pad'][j] if 'pad' in dict else None, stride = dict['stride'][j], W = initmethod('relu'), nonlinearity = dict['nonlinearity'][j], name = block_name+'_'+str(i)+'_'+str(j)) if style=='convolutional'\ else NL( incoming = lasagne.layers.dnn.Pool2DDNNLayer( incoming = lasagne.layers.Upscale2DLayer( incoming=incoming if j == 0 else branch[i], scale_factor = dict['stride'][j]), pool_size = dict['filter_size'][j], stride = [1,1], mode = dict['mode'][j], pad = dict['pad'][j], name = block_name+'_'+str(i)+'_'+str(j)), nonlinearity = dict['nonlinearity'][j]) # Apply Batchnorm branch[i] = BN(branch[i],name = block_name+'_bnorm_'+str(i)+'_'+str(j)) if dict['bnorm'][j] else branch[i] # Concatenate Sublayers return CL(incomings=branch,name=block_name) # Convenience function to efficiently generate param dictionaries for use with InceptioNlayer
Example #11
Source File: layers.py From Neural-Photo-Editor with MIT License | 5 votes |
def __init__(self, incoming, num_filters, filter_size, stride=(1, 1), crop=0, untie_biases=False, W=initmethod(), b=lasagne.init.Constant(0.), nonlinearity=lasagne.nonlinearities.rectify, flip_filters=False, **kwargs): super(DeconvLayer, self).__init__( incoming, num_filters, filter_size, stride, crop, untie_biases, W, b, nonlinearity, flip_filters, n=2, **kwargs) # rename self.crop to self.pad self.crop = self.pad del self.pad
Example #12
Source File: base.py From gelato with MIT License | 5 votes |
def smart_init(shape): if len(shape) > 1: return init.GlorotUniform()(shape) else: return init.Normal()(shape)
Example #13
Source File: layers.py From opt-mmd with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, incoming, num_centers, locs=init.Normal(std=1), log_sigma=init.Constant(0.), **kwargs): super(RBFLayer, self).__init__(incoming, **kwargs) self.num_centers = num_centers assert len(self.input_shape) == 2 in_dim = self.input_shape[1] self.locs = self.add_param(locs, (num_centers, in_dim), name='locs', regularizable=False) self.log_sigma = self.add_param(log_sigma, (), name='log_sigma')
Example #14
Source File: models_uncond.py From EvolutionaryGAN with MIT License | 5 votes |
def build_generator_128(noise=None, ngf=128): lrelu = LeakyRectify(0.2) # noise input InputNoise = InputLayer(shape=(None, 100), input_var=noise) #FC Layer gnet0 = DenseLayer(InputNoise, ngf*16*4*4, W=Normal(0.02), nonlinearity=lrelu) print ("Gen fc1:", gnet0.output_shape) #Reshape Layer gnet1 = ReshapeLayer(gnet0,([0],ngf*16,4,4)) print ("Gen rs1:", gnet1.output_shape) # DeConv Layer gnet2 = Deconv2DLayer(gnet1, ngf*8, (4,4), (2,2), crop=1, W=Normal(0.02),nonlinearity=lrelu) print ("Gen deconv1:", gnet2.output_shape) # DeConv Layer gnet3 = Deconv2DLayer(gnet2, ngf*8, (4,4), (2,2), crop=1, W=Normal(0.02),nonlinearity=lrelu) print ("Gen deconv2:", gnet3.output_shape) # DeConv Layer gnet4 = Deconv2DLayer(gnet3, ngf*4, (4,4), (2,2), crop=1, W=Normal(0.02),nonlinearity=lrelu) print ("Gen deconv3:", gnet4.output_shape) # DeConv Layer gnet5 = Deconv2DLayer(gnet4, ngf*4, (4,4), (2,2), crop=1, W=Normal(0.02),nonlinearity=lrelu) print ("Gen deconv4:", gnet5.output_shape) # DeConv Layer gnet6 = Deconv2DLayer(gnet5, ngf*2, (4,4), (2,2), crop=1, W=Normal(0.02),nonlinearity=lrelu) print ("Gen deconv5:", gnet6.output_shape) # DeConv Layer gnet7 = Deconv2DLayer(gnet6, 3, (3,3), (1,1), crop='same', W=Normal(0.02),nonlinearity=tanh) print ("Gen output:", gnet7.output_shape) return gnet7
Example #15
Source File: models_uncond.py From EvolutionaryGAN with MIT License | 5 votes |
def build_generator_toy(noise=None, nd=512): InputNoise = InputLayer(shape=(None, 2), input_var=noise) print ("Gen input:", InputNoise.output_shape) gnet0 = DenseLayer(InputNoise, nd, W=Normal(0.02), nonlinearity=relu) print ("Gen fc0:", gnet0.output_shape) gnet1 = DenseLayer(gnet0, nd, W=Normal(0.02), nonlinearity=relu) print ("Gen fc1:", gnet1.output_shape) gnet2 = DenseLayer(gnet1, nd, W=Normal(0.02), nonlinearity=relu) print ("Gen fc2:", gnet2.output_shape) gnetout = DenseLayer(gnet2, 2, W=Normal(0.02), nonlinearity=None) print ("Gen output:", gnetout.output_shape) return gnetout
Example #16
Source File: layers.py From opt-mmd with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, incoming, num_freqs, freqs=init.Normal(std=1), log_sigma=init.Constant(0.), **kwargs): super(SmoothedCFLayer, self).__init__(incoming, **kwargs) self.num_freqs = num_freqs assert len(self.input_shape) == 2 in_dim = self.input_shape[1] self.freqs = self.add_param(freqs, (num_freqs, in_dim), name='freqs') self.log_sigma = self.add_param(log_sigma, (), name='log_sigma')
Example #17
Source File: net_theano.py From visual_dynamics with MIT License | 4 votes |
def build_small_action_cond_encoder_net(input_shapes): x_shape, u_shape = input_shapes x2_c_dim = x1_c_dim = x_shape[0] x1_shape = (x1_c_dim, x_shape[1]//2, x_shape[2]//2) x2_shape = (x2_c_dim, x1_shape[1]//2, x1_shape[2]//2) y2_dim = 64 X_var = T.tensor4('X') U_var = T.matrix('U') l_x = L.InputLayer(shape=(None,) + x_shape, input_var=X_var, name='x') l_u = L.InputLayer(shape=(None,) + u_shape, input_var=U_var, name='u') l_x1 = L.Conv2DLayer(l_x, x1_c_dim, filter_size=6, stride=2, pad=2, W=init.Normal(std=0.01), nonlinearity=nl.rectify) l_x2 = L.Conv2DLayer(l_x1, x2_c_dim, filter_size=6, stride=2, pad=2, W=init.Normal(std=0.01), nonlinearity=nl.rectify) l_y2 = L.DenseLayer(l_x2, y2_dim, nonlinearity=None, name='y') l_y2_diff_pred = LT.BilinearLayer([l_y2, l_u], name='y_diff_pred') l_y2_next_pred = L.ElemwiseMergeLayer([l_y2, l_y2_diff_pred], T.add) l_x2_next_pred_flat = L.DenseLayer(l_y2_next_pred, np.prod(x2_shape), nonlinearity=None) l_x2_next_pred = L.ReshapeLayer(l_x2_next_pred_flat, ([0],) + x2_shape) l_x1_next_pred = LT.Deconv2DLayer(l_x2_next_pred, x2_c_dim, filter_size=6, stride=2, pad=2, W=init.Normal(std=0.01), nonlinearity=nl.rectify) l_x_next_pred = LT.Deconv2DLayer(l_x1_next_pred, x1_c_dim, filter_size=6, stride=2, pad=2, W=init.Normal(std=0.01), nonlinearity=nl.tanh, name='x_next_pred') X_next_pred_var = lasagne.layers.get_output(l_x_next_pred) X_diff_var = T.tensor4('X_diff') X_next_var = X_var + X_diff_var loss = ((X_next_var - X_next_pred_var) ** 2).mean(axis=0).sum() / 2. net_name = 'SmallActionCondEncoderNet' input_vars = OrderedDict([(var.name, var) for var in [X_var, U_var, X_diff_var]]) pred_layers = OrderedDict([('y_diff_pred', l_y2_diff_pred), ('y', l_y2), ('x0_next_pred', l_x_next_pred)]) return net_name, input_vars, pred_layers, loss
Example #18
Source File: layers.py From Neural-Photo-Editor with MIT License | 4 votes |
def MDCL(incoming,num_filters,scales,name,dnn=True): if dnn: from lasagne.layers.dnn import Conv2DDNNLayer as C2D # W initialization method--this should also work as Orthogonal('relu'), but I have yet to validate that as thoroughly. winit = initmethod(0.02) # Initialization method for the coefficients sinit = lasagne.init.Constant(1.0/(1+len(scales))) # Number of incoming channels ni =lasagne.layers.get_output_shape(incoming)[1] # Weight parameter--the primary parameter for this block W = theano.shared(lasagne.utils.floatX(winit.sample((num_filters,lasagne.layers.get_output_shape(incoming)[1],3,3))),name=name+'W') # Primary Convolution Layer--No Dilation n = C2D(incoming = incoming, num_filters = num_filters, filter_size = [3,3], stride = [1,1], pad = (1,1), W = W*theano.shared(lasagne.utils.floatX(sinit.sample(num_filters)), name+'_coeff_base').dimshuffle(0,'x','x','x'), # Note the broadcasting dimshuffle for the num_filter scalars. b = None, nonlinearity = None, name = name+'base' ) # List of remaining layers. This should probably just all be concatenated into a single list rather than being a separate deal. nd = [] for i,scale in enumerate(scales): # I don't think 0 dilation is technically defined (or if it is it's just the regular filter) but I use it here as a convenient keyword to grab the 1x1 mean conv. if scale==0: nd.append(C2D(incoming = incoming, num_filters = num_filters, filter_size = [1,1], stride = [1,1], pad = (0,0), W = T.mean(W,axis=[2,3]).dimshuffle(0,1,'x','x')*theano.shared(lasagne.utils.floatX(sinit.sample(num_filters)), name+'_coeff_1x1').dimshuffle(0,'x','x','x'), b = None, nonlinearity = None, name = name+str(scale))) # Note the dimshuffles in this layer--these are critical as the current DilatedConv2D implementation uses a backward pass. else: nd.append(lasagne.layers.DilatedConv2DLayer(incoming = lasagne.layers.PadLayer(incoming = incoming, width=(scale,scale)), num_filters = num_filters, filter_size = [3,3], dilation=(scale,scale), W = W.dimshuffle(1,0,2,3)*theano.shared(lasagne.utils.floatX(sinit.sample(num_filters)), name+'_coeff_'+str(scale)).dimshuffle('x',0,'x','x'), b = None, nonlinearity = None, name = name+str(scale))) return ESL(nd+[n]) # MDC-based Upsample Layer. # This is a prototype I don't make use of extensively. It's operational but it doesn't seem to improve results yet.
Example #19
Source File: layers.py From Neural-Photo-Editor with MIT License | 4 votes |
def InceptionLayer(incoming,param_dict,block_name): branch = [0]*len(param_dict) # Loop across branches for i,dict in enumerate(param_dict): for j,style in enumerate(dict['style']): # Loop up branch branch[i] = C2D( incoming = branch[i] if j else incoming, num_filters = dict['num_filters'][j], filter_size = dict['filter_size'][j], pad = dict['pad'][j] if 'pad' in dict else None, stride = dict['stride'][j], W = initmethod('relu'), nonlinearity = dict['nonlinearity'][j], name = block_name+'_'+str(i)+'_'+str(j)) if style=='convolutional'\ else NL(lasagne.layers.dnn.Pool2DDNNLayer( incoming=incoming if j == 0 else branch[i], pool_size = dict['filter_size'][j], mode = dict['mode'][j], stride = dict['stride'][j], pad = dict['pad'][j], name = block_name+'_'+str(i)+'_'+str(j)), nonlinearity = dict['nonlinearity'][j]) if style=='pool'\ else lasagne.layers.DilatedConv2DLayer( incoming = lasagne.layers.PadLayer(incoming = incoming if j==0 else branch[i],width = dict['pad'][j]) if 'pad' in dict else incoming if j==0 else branch[i], num_filters = dict['num_filters'][j], filter_size = dict['filter_size'][j], dilation = dict['dilation'][j], # pad = dict['pad'][j] if 'pad' in dict else None, W = initmethod('relu'), nonlinearity = dict['nonlinearity'][j], name = block_name+'_'+str(i)+'_'+str(j)) if style== 'dilation'\ else DL( incoming = incoming if j==0 else branch[i], num_units = dict['num_filters'][j], W = initmethod('relu'), b = None, nonlinearity = dict['nonlinearity'][j], name = block_name+'_'+str(i)+'_'+str(j)) # Apply Batchnorm branch[i] = BN(branch[i],name = block_name+'_bnorm_'+str(i)+'_'+str(j)) if dict['bnorm'][j] else branch[i] # Concatenate Sublayers return CL(incomings=branch,name=block_name) # Convenience function to define an inception-style block with upscaling
Example #20
Source File: generate.py From opt-mmd with BSD 3-Clause "New" or "Revised" License | 4 votes |
def _sample_trained_minibatch_gan(params_file, n, batch_size, rs): import lasagne from lasagne.init import Normal import lasagne.layers as ll import theano as th from theano.sandbox.rng_mrg import MRG_RandomStreams import theano.tensor as T import nn theano_rng = MRG_RandomStreams(rs.randint(2 ** 15)) lasagne.random.set_rng(np.random.RandomState(rs.randint(2 ** 15))) noise_dim = (batch_size, 100) noise = theano_rng.uniform(size=noise_dim) ls = [ll.InputLayer(shape=noise_dim, input_var=noise)] ls.append(nn.batch_norm( ll.DenseLayer(ls[-1], num_units=4*4*512, W=Normal(0.05), nonlinearity=nn.relu), g=None)) ls.append(ll.ReshapeLayer(ls[-1], (batch_size,512,4,4))) ls.append(nn.batch_norm( nn.Deconv2DLayer(ls[-1], (batch_size,256,8,8), (5,5), W=Normal(0.05), nonlinearity=nn.relu), g=None)) # 4 -> 8 ls.append(nn.batch_norm( nn.Deconv2DLayer(ls[-1], (batch_size,128,16,16), (5,5), W=Normal(0.05), nonlinearity=nn.relu), g=None)) # 8 -> 16 ls.append(nn.weight_norm( nn.Deconv2DLayer(ls[-1], (batch_size,3,32,32), (5,5), W=Normal(0.05), nonlinearity=T.tanh), train_g=True, init_stdv=0.1)) # 16 -> 32 gen_dat = ll.get_output(ls[-1]) with np.load(params_file) as d: params = [d['arr_{}'.format(i)] for i in range(9)] ll.set_all_param_values(ls[-1], params, trainable=True) sample_batch = th.function(inputs=[], outputs=gen_dat) samps = [] while len(samps) < n: samps.extend(sample_batch()) samps = np.array(samps[:n]) return samps