def feature_extraction_block(input_): weights = [] biases = [] layer, weight, bias = utils.convolution(input_, shape=[3, 3, 1, 64], strides=[1, 1, 1, 1], padding='SAME', init_w=tf.initializers.he_normal(), init_b=tf.initializers.zeros(), name='fblock', index=0) layer = tf.nn.leaky_relu(layer, 0.05) weights.append(weight) biases.append(bias) layer, weight, bias = utils.convolution(layer, shape=[3, 3, 64, 64], strides=[1, 1, 1, 1], padding='SAME', init_w=tf.initializers.he_normal(), init_b=tf.initializers.zeros(), name='fblock', index=1) layer = tf.nn.leaky_relu(layer, 0.05) weights.append(weight) biases.append(bias) return layer, weights, biases
def inference(image): weights = [] biases = [] with tf.name_scope('vdsr_layer_0'): layer, weight, bias = utils.convolution( image, shape=[3, 3, 1, 64], strides=[1, 1, 1, 1], padding='SAME', init_w=tf.initializers.he_normal(), init_b=tf.initializers.zeros(), name='vdsr', index=0) layer = tf.nn.relu(layer) weights.append(weight) biases.append(bias) for i in range(1, 19): with tf.name_scope('vdsr_layer_%d' % i): layer, weight, bias = utils.convolution( layer, shape=[3, 3, 64, 64], strides=[1, 1, 1, 1], padding='SAME', init_w=tf.initializers.he_normal(), init_b=tf.initializers.zeros(), name='vdsr', index=i) layer = tf.nn.relu(layer) weights.append(weight) biases.append(bias) with tf.name_scope('vdsr_layer_19'): layer, weight, bias = utils.convolution( layer, shape=[3, 3, 64, 1], strides=[1, 1, 1, 1], padding='SAME', init_w=tf.initializers.he_normal(), init_b=tf.initializers.zeros(), name='vdsr', index=19) weights.append(weight) biases.append(bias) with tf.name_scope('vdsr_output'): output = image + layer output = tf.clip_by_value(output, 0., 1.) return output, layer, weights, biases
def move(prior, motion, motionKernel): validate_dist(prior) validate_dist(motionKernel) posterior = np.zeros_like(prior) if np.array_equal(motion, [0, 0]): posterior = prior elif np.array_equal(motion, [0, 1]): posterior = convolution(prior, np.fliplr(motionKernel)) elif np.array_equal(motion, [0, -1]): posterior = convolution(prior, motionKernel) elif np.array_equal(motion, [1, 0]): posterior = convolution(prior, np.rot90(motionKernel, k=3)) elif np.array_equal(motion, [-1, 0]): posterior = convolution(prior, np.rot90(motionKernel, k=1)) else: raise Exception("Invalid motion command {}".format(motion)) return posterior
def compression_unit(input_, block_index): weights = [] biases = [] layer, weight, bias = utils.convolution(input_, shape=[1, 1, 80, 64], strides=[1, 1, 1, 1], padding='SAME', init_w=tf.initializers.he_normal(), init_b=tf.initializers.zeros(), name='compression_unit_%d' % block_index, index=0) layer = tf.nn.leaky_relu(layer, 0.05) weights.append(weight) biases.append(bias) return layer, weights, biases
def enhancement_unit(input_, block_index): weights = [] biases = [] layer, weight, bias = utils.grouped_convolution( input_, shape=[3, 3, 64, 48], strides=[1, 1, 1, 1], padding='SAME', group=4, init_w=tf.initializers.he_normal(), init_b=tf.initializers.zeros(), name='enhancement_unit_%d' % block_index, index=0) layer = tf.nn.leaky_relu(layer, 0.05) weights += weight biases += bias layer, weight, bias = utils.convolution(layer, shape=[3, 3, 48, 32], strides=[1, 1, 1, 1], padding='SAME', init_w=tf.initializers.he_normal(), init_b=tf.initializers.zeros(), name='enhancement_unit_%d' % block_index, index=1) layer = tf.nn.leaky_relu(layer, 0.05) weights.append(weight) biases.append(bias) layer, weight, bias = utils.convolution(layer, shape=[3, 3, 32, 64], strides=[1, 1, 1, 1], padding='SAME', init_w=tf.initializers.he_normal(), init_b=tf.initializers.zeros(), name='enhancement_unit_%d' % block_index, index=2) layer = tf.nn.leaky_relu(layer, 0.05) weights.append(weight) biases.append(bias) segment_1, segment_2 = tf.split(layer, [16, 48], axis=3) concatenated = tf.concat([input_, segment_1], axis=3) layer, weight, bias = utils.grouped_convolution( segment_2, shape=[3, 3, 48, 64], strides=[1, 1, 1, 1], padding='SAME', group=4, init_w=tf.initializers.he_normal(), init_b=tf.initializers.zeros(), name='enhancement_unit_%d' % block_index, index=3) layer = tf.nn.leaky_relu(layer, 0.05) weights += weight biases += bias layer, weight, bias = utils.convolution(layer, shape=[3, 3, 64, 48], strides=[1, 1, 1, 1], padding='SAME', init_w=tf.initializers.he_normal(), init_b=tf.initializers.zeros(), name='enhancement_unit_%d' % block_index, index=4) layer = tf.nn.leaky_relu(layer, 0.05) weights.append(weight) biases.append(bias) layer, weight, bias = utils.convolution(layer, shape=[3, 3, 48, 80], strides=[1, 1, 1, 1], padding='SAME', init_w=tf.initializers.he_normal(), init_b=tf.initializers.zeros(), name='enhancement_unit_%d' % block_index, index=5) layer = tf.nn.leaky_relu(layer, 0.05) weights.append(weight) biases.append(bias) output = layer + concatenated return output, weights, biases
def __init__(self, vocab_size, input_dimension): super(AcousticModel, self).__init__() self.vocab_size = vocab_size self.input_dimension = input_dimension self.dropout = nn.Dropout(p=0.5) self.num_rnn_layers = 4 conv1 = nn.Sequential() conv1.add_module( 'conv1_conv1', convolution(in_channels=1, filter_size=32, bias=False)) conv1.add_module('conv1_norm1', normalization(num_features=32)) conv1.add_module('conv1_relu1', nn.ReLU()) conv1.add_module('conv1_dropout1', nn.Dropout(p=0.1)) conv1.add_module('conv1_conv2', convolution(in_channels=32, filter_size=32)) conv1.add_module('conv1_norm2', normalization(num_features=32)) conv1.add_module('conv1_relu2', nn.ReLU()) conv1.add_module('conv1_maxpool', maxpooling(2)) conv1.add_module('conv1_dropout2', nn.Dropout(p=0.1)) self.conv1 = conv1 conv2 = nn.Sequential() conv2.add_module('conv2_conv1', convolution(in_channels=32, filter_size=64)) conv2.add_module('conv2_norm1', normalization(num_features=64)) conv2.add_module('conv2_relu1', nn.ReLU()) conv2.add_module('conv2_dropout1', nn.Dropout(p=0.1)) conv2.add_module('conv2_conv2', convolution(in_channels=64, filter_size=64)) conv2.add_module('conv2_norm2', normalization(num_features=64)) conv2.add_module('conv2_relu2', nn.ReLU()) conv2.add_module('conv2_maxpool', maxpooling(2)) conv2.add_module('conv2_dropout2', nn.Dropout(p=0.1)) self.conv2 = conv2 conv3 = nn.Sequential() conv3.add_module('conv3_conv1', convolution(in_channels=64, filter_size=128)) conv3.add_module('conv3_relu1', nn.ReLU()) conv3.add_module('conv3_dropout1', nn.Dropout(p=0.2)) conv3.add_module('conv3_norm1', normalization(num_features=128)) conv3.add_module('conv3_conv2', convolution(in_channels=128, filter_size=128)) conv3.add_module('conv3_norm2', normalization(num_features=128)) conv3.add_module('conv3_relu2', nn.ReLU()) conv3.add_module('conv3_maxpool', maxpooling(2)) conv3.add_module('conv3_dropout2', nn.Dropout(p=0.2)) self.conv3 = conv3 conv4 = nn.Sequential() conv4.add_module('conv4_conv1', convolution(in_channels=128, filter_size=128)) conv4.add_module('conv4_norm1', normalization(num_features=128)) conv4.add_module('conv4_relu1', nn.ReLU()) conv4.add_module('conv4_dropout1', nn.Dropout(p=0.2)) conv4.add_module('conv4_conv2', convolution(in_channels=128, filter_size=128)) conv4.add_module('conv4_relu2', nn.ReLU()) conv4.add_module('conv4_conv3', convolution(in_channels=128, filter_size=128)) conv4.add_module('conv4_norm2', normalization(num_features=128)) conv4.add_module('conv4_relu3', nn.ReLU()) conv4.add_module('conv4_dropout2', nn.Dropout(p=0.2)) self.conv4 = conv4 # no maxpooling self.fc_features = int(input_dimension / 8 * 128) # due to three times of pooling 2**3 = 8 self.fc1 = fclayer(in_features=self.fc_features, out_features=512) self.fc2 = fclayer(in_features=512, out_features=vocab_size) self.transformer = TransformerEncoder(num_layers=4, model_size=512, inner_size=2048, key_size=64, value_size=64, num_head=8)