def cnn_text(net_input, sequence_length, vocab_size, embedding_size, stride_h, filter_sizes, num_filters, num_classes, keep_prob, l2_lambda, is_bn, bn_training): embedding_layer = embedding(net_input, vocab_size, embedding_size, "embedding") pools = list() for i, filter_size in enumerate(filter_sizes): convi = conv(embedding_layer, filter_size, embedding_size, 1, num_filters, stride_h, 1, "conv" + str(i)) if is_bn: bni = batch_norm(convi, bn_training, "bn" + str(i)) convi = bni pooli = max_pool(convi, (sequence_length - filter_size) // stride_h + 1, 1, 1, 1, "pool" + str(i)) pools.append(pooli) num_filters_total = num_filters * len(filter_sizes) h_pool = concat(pools, 3, "concat") h_pool_flat = tf.reshape(h_pool, [-1, num_filters_total]) h_drop = dropout(h_pool_flat, keep_prob) h_fc = fc(h_drop, num_filters_total, num_classes, l2_lambda, "fc") return h_fc
def __init__(self, target_num, dropout_rate, name): super(VGG16, self).__init__() #self.input_data_shape = input_data_shape self.DNN_name = name self.target_num = target_num self.dropout_rate = dropout_rate #self.load_weights = load_weights # Construct the initial data of VGG16 network. self.conv1_1 = network.conv2d(64, [3, 3], [1, 1, 1, 1]) self.conv1_2 = network.conv2d(64, [3, 3], [1, 1, 1, 1]) self.conv2_1 = network.conv2d(128, [3, 3], [1, 1, 1, 1]) self.conv2_2 = network.conv2d(128, [3, 3], [1, 1, 1, 1]) self.conv3_1 = network.conv2d(256, [3, 3], [1, 1, 1, 1]) self.conv3_2 = network.conv2d(256, [3, 3], [1, 1, 1, 1]) self.conv3_3 = network.conv2d(256, [3, 3], [1, 1, 1, 1]) self.conv4_1 = network.conv2d(512, [3, 3], [1, 1, 1, 1]) self.conv4_2 = network.conv2d(512, [3, 3], [1, 1, 1, 1]) self.conv4_3 = network.conv2d(128, [3, 3], [1, 1, 1, 1]) self.conv5_1 = network.conv2d(128, [3, 3], [1, 1, 1, 1]) self.conv5_2 = network.conv2d(128, [3, 3], [1, 1, 1, 1]) self.conv5_3 = network.conv2d(128, [3, 3], [1, 1, 1, 1]) self.full1 = network.fully_connected(4096) self.full2 = network.fully_connected(4096) self.full3 = network.fully_connected(self.target_num) # For batch normalization self.bn1 = network.batch_norm() self.bn2 = network.batch_norm() self.bn3 = network.batch_norm() self.bn4 = network.batch_norm() self.bn5 = network.batch_norm() self.bn6 = network.batch_norm() self.bn7 = network.batch_norm() self.bn8 = network.batch_norm() self.bn9 = network.batch_norm() self.bn10 = network.batch_norm() self.bn11 = network.batch_norm() self.bn12 = network.batch_norm() self.bn13 = network.batch_norm() self.bn14 = network.batch_norm() self.bn15 = network.batch_norm()