def set_rec_net(num_filters,filtsize,superres = 1,nonlin = lnl.LeakyRectify(0.2), AR = False, n_rnn_units = 128, n_features = 13): input_l = ll.InputLayer((None, None)) rec_nn = ll.DimshuffleLayer(input_l, (0, 'x', 1)) hevar = np.sqrt(np.sqrt(2/(1+0.2**2))) if nonlin == lnl.tanh: init = lasagne.init.GlorotUniform() else: init = lasagne.init.HeNormal(hevar) for num,size in zip(num_filters,filtsize): rec_nn = (ll.Conv1DLayer(rec_nn, num_filters = num, filter_size = size, stride =1, pad = 'same', nonlinearity = nonlin, name='conv1', W = init)) if not AR: prob_nn = (ll.Conv1DLayer(rec_nn, num_filters = superres,filter_size = 11,stride =1, pad = 'same', nonlinearity=lnl.sigmoid,name='conv2', b = lasagne.init.Constant(-3.))) prob_nn = ll.DimshuffleLayer(prob_nn,(0,2,1)) prob_nn = ll.FlattenLayer(prob_nn) else: prob_nn = (ll.Conv1DLayer(rec_nn, num_filters = n_features,filter_size = 11,stride =1, pad = 'same', nonlinearity=nonlin,name='conv2')) prob_nn = ll.DimshuffleLayer(prob_nn,(0,2,1)) return {'network':prob_nn,'input':input_l, 'superres':superres, 'n_features':n_features, 'rnn_units':n_rnn_units}
dropout=0.0, partial_sum=1, untie_biases=True) l3b = cc_layers.CudaConvnetConv2DLayer(l3a, n_filters=128, filter_size=3, pad=0, weights_std=0.1, init_bias_value=0.1, dropout=0.0, partial_sum=1, untie_biases=True) l3 = cc_layers.CudaConvnetPooling2DLayer(l3b, pool_size=2) l3s = cc_layers.ShuffleC01BToBC01Layer(l3) l3f = layers.FlattenLayer(l3s) l4a = layers.DenseLayer(l3f, n_outputs=1024, weights_std=0.01, init_bias_value=0.1, dropout=0.5, nonlinearity=layers.identity) l4 = layers.FeatureMaxPoolingLayer(l4a, pool_size=2, feature_dim=1, implementation='reshape') j4 = layers.MultiRotMergeLayer(l4, num_views=4) # 2) # merge convolutional parts
def set_rec_net(num_filters, filtsize, nonlin=lnl.LeakyRectify(0.2), AR=False, FB=False, n_rnn_units=64, n_features=13, n_genparams=0, p_sigma=None): """ :param num_filters: Number of filters in each layer for the convolutional network, also sets number of layers :param filtsize: Size of the filters in each layer :param nonlin: Nonlinearity used These parameters are only relevant if a RNN is used to obtain a correlated posterior estimation :param AR: Whether this network is used as the first stage of an auto-regressive network :param FB: Whether the auto-regressive network uses a backwards running RNN :param n_rnn_units: Number of units in the RNN :param n_features: Number of features passed form the CNN to the RNN :param n_genparams: Number of generative model parameters inferred by the recognition network :param p_sigma: standard deviation of the prior on the inffered generative model parameter. """ input_l = ll.InputLayer((None, None)) rec_nn = ll.DimshuffleLayer(input_l, (0, 'x', 1)) hevar = np.sqrt(np.sqrt(2 / (1 + 0.2**2))) convout_nonlin = nonlin if n_features == 1: convout_nonlin = lnl.linear if nonlin == lnl.tanh: init = lasagne.init.GlorotUniform() else: init = lasagne.init.HeNormal(hevar) for num, size in zip(num_filters, filtsize): rec_nn = (ll.Conv1DLayer(rec_nn, num_filters=num, filter_size=size, stride=1, pad='same', nonlinearity=nonlin, name='conv_filter', W=init)) if not AR: prob_nn = (ll.Conv1DLayer(rec_nn, num_filters=1, filter_size=11, stride=1, pad='same', nonlinearity=lnl.sigmoid, name='conv_out', b=lasagne.init.Constant(-3.))) prob_nn = ll.DimshuffleLayer(prob_nn, (0, 2, 1)) prob_nn = ll.FlattenLayer(prob_nn) else: prob_nn = (ll.Conv1DLayer(rec_nn, num_filters=n_features, filter_size=11, stride=1, pad='same', nonlinearity=convout_nonlin, name='conv_out')) prob_nn = ll.DimshuffleLayer(prob_nn, (0, 2, 1)) if n_features == 1: prob_nn = ll.FlattenLayer(prob_nn) return { 'network': prob_nn, 'input': input_l, 'n_features': n_features, 'rnn_units': n_rnn_units, 'n_genparams': n_genparams, 'p_sigma': p_sigma, 'forw_backw': FB }