def _build_net(self): w2 = helpers.weight_variable([ENCODED_FEATURES, HIDDEN_UNITS_2]) b2 = helpers.bias_variable([HIDDEN_UNITS_2]) l2 = tf.nn.relu6(tf.matmul(self.x_placeholder, w2) + b2) l2_drop = tf.nn.dropout(l2, self.keep_prob) # Output layer w5 = helpers.weight_variable([HIDDEN_UNITS_2, OUTPUT_CLASSES]) b5 = helpers.bias_variable([OUTPUT_CLASSES]) l5 = tf.nn.relu6(tf.matmul(l2_drop, w5) + b5) return tf.nn.softmax(l5)
def _build(self): # First hidden layer w2 = helpers.weight_variable([INPUT_UNITS, HIDDEN_UNITS_1]) b2 = helpers.bias_variable([HIDDEN_UNITS_1]) l2 = tf.nn.relu(tf.matmul(self.x_placeholder, w2) + b2) l2_drop = tf.nn.dropout(l2, self.keep_prob) # Second hidden layer w3 = helpers.weight_variable([HIDDEN_UNITS_1, HIDDEN_UNITS_2]) b3 = helpers.bias_variable([HIDDEN_UNITS_2]) l3 = tf.nn.relu(tf.matmul(l2_drop, w3) + b3) l3_drop = tf.nn.dropout(l3, self.keep_prob) # Output layer w5 = helpers.weight_variable([HIDDEN_UNITS_2, OUTPUT_CLASSES]) b5 = helpers.bias_variable([OUTPUT_CLASSES]) return tf.nn.softmax(tf.matmul(l3_drop, w5) + b5)
def _build_decoder(self, encoder): weights = helpers.weight_variable([ENCODED_FEATURES, INPUT_UNITS]) biases = helpers.bias_variable([INPUT_UNITS]) l3 = tf.nn.relu(tf.matmul(encoder, weights) + biases) return tf.nn.softmax(l3)
def _build_encoder(self): weights = helpers.weight_variable([INPUT_UNITS, ENCODED_FEATURES]) biases = helpers.bias_variable([ENCODED_FEATURES]) return tf.nn.relu(tf.matmul(self.x_placeholder, weights) + biases)
def inference(): x = tf.placeholder(tf.float32, shape=[None, 784], name='input') image = tf.reshape(x, [-1, 28, 28, 1]) with tf.name_scope('conv_layer_1'): W_conv1 = helpers.weight_variable([5, 5, 1, 32], 'W_conv1') b_conv1 = helpers.bias_variable([32], 'bias_conv1') alphas_conv1 = helpers.bias_variable([32], 'alpha_conv1') layer_conv_1 = helpers.prelu( helpers.conv2d(image, W_conv1) + b_conv1, alphas_conv1) W_conv1_b = helpers.weight_variable([5, 5, 32, 32], 'W_conv1_b') b_conv1_b = helpers.bias_variable([32], 'bias_conv1_b') alphas_conv1_b = helpers.bias_variable([32], 'alpha_conv1_b') layer_conv_1_b = helpers.prelu( helpers.conv2d(layer_conv_1, W_conv1_b) + b_conv1_b, alphas_conv1_b) stage_1_pool = helpers.max_pool_2x2(layer_conv_1_b) with tf.name_scope('conv_layer_2'): W_conv2 = helpers.weight_variable([5, 5, 32, 64], "W_conv2") b_conv2 = helpers.bias_variable([64], 'bias_conv2') alphas_conv2 = helpers.bias_variable([64], 'alpha_conv2') layer_conv_2 = helpers.prelu( helpers.conv2d(stage_1_pool, W_conv2) + b_conv2, alphas_conv2) W_conv2_b = helpers.weight_variable([5, 5, 64, 64], "W_conv2_b") b_conv2_b = helpers.bias_variable([64], 'bias_conv2_b') alphas_conv2_b = helpers.bias_variable([64], 'alpha_conv2_b') layer_conv_2_b = helpers.prelu( helpers.conv2d(layer_conv_2, W_conv2_b) + b_conv2_b, alphas_conv2_b) stage_2_pool = helpers.max_pool_2x2(layer_conv_2_b) # stage_2_pool_flat = tf.reshape(stage_2_pool, [-1, 7 * 7 * 64]) with tf.name_scope('conv_layer_3'): W_conv3 = helpers.weight_variable([5, 5, 64, 128], "W_conv3") b_conv3 = helpers.bias_variable([128], 'bias_conv3') alphas_conv3 = helpers.bias_variable([128], 'alpha_conv3') layer_conv_3 = helpers.prelu( helpers.conv2d(stage_2_pool, W_conv3) + b_conv3, alphas_conv3) # stage_3_pool = helpers.max_pool_2x2(layer_conv_3) # stage_3_pool_flat = tf.reshape(stage_3_pool, [-1, 4 * 4 * 256]) W_conv3_b = helpers.weight_variable([5, 5, 128, 128], "W_conv3_b") b_conv3_b = helpers.bias_variable([128], 'bias_conv3_b') alphas_conv3_b = helpers.bias_variable([128], 'alpha_conv3_b') layer_conv_3_b = helpers.prelu( helpers.conv2d(layer_conv_3, W_conv3_b) + b_conv3_b, alphas_conv3_b) stage_3_pool = helpers.max_pool_2x2(layer_conv_3_b) stage_3_pool_flat = tf.reshape(stage_3_pool, [-1, 4 * 4 * 128]) with tf.name_scope('fc_layer_1'): W_fc1 = helpers.weight_variable([4 * 4 * 128, 2], "W_fc1") # W_fc1 = helpers.weight_variable([7 * 7 * 64, 2], "W_fc1") b_fc1 = helpers.bias_variable([2], 'bias_fc1') alphas_fc1 = helpers.bias_variable([2], 'alpha_conv3') output = helpers.prelu( tf.matmul(stage_3_pool_flat, W_fc1) + b_fc1, alphas_fc1) # with tf.name_scope('fc_output'): # W_output = helpers.weight_variable([500, 10], "W_putput") # b_output = helpers.bias_variable([10], 'bias_output') # output = tf.nn.relu(tf.matmul(h_fc1, W_output) + b_output) # with tf.name_scope('output'): # W_output = helpers.weight_variable([2, 10], "W_output") # b_output = helpers.bias_variable([10]) # output = tf.nn.relu(tf.matmul(h_fc2, W_output) + b_output) return x, output