Exemplo n.º 1
0
def predict_cost(operator, params):
    # apply lstm architecture to compute operator tree embedding
    _, r_out = predict_representation(operator, params)

    # estimation network to get costs
    hidden_layer = leaky_relu(r_out, params['w_est_h1'])
    return leaky_relu(hidden_layer, params['w_est_final'])
Exemplo n.º 2
0
        def create_deconv(input,
                          in_channels,
                          out_channels,
                          input_image_size,
                          weight_set=[],
                          no_bias=False):
            # # reverse max-pooling using densely connected layer:
            # dense = tf.reshape(input, [-1, in_channels * image_size**2])
            # new_image_size = image_size*2
            # w1 = weight_var([in_channels * image_size**2, in_channels * new_image_size**2])
            # img = tf.reshape(tf.matmul(dense, w1), [-1, new_image_size, new_image_size, in_channels])
            #
            input = batch_norm(input)
            w = weight_var([patch_size, patch_size, out_channels, in_channels])
            weight_set.append(w)
            b = weight_var([out_channels], init_zero=no_bias)

            if not no_bias:
                weight_set.append(b)

            batch_size = tf.shape(input)[0]
            output_shape = tf.pack([
                batch_size, input_image_size * 2, input_image_size * 2,
                out_channels
            ])

            deconv = tf.nn.conv2d_transpose(input,
                                            w,
                                            output_shape,
                                            strides=[1, 2, 2, 1],
                                            padding='SAME')
            return leaky_relu(deconv + b)
Exemplo n.º 3
0
def create_fc(input, out_size, weight_set=[]):
    # input_dropped = tf.nn.dropout(input, dropout_keep_prob)
    in_size = input.get_shape()[-1]
    w = weight_var([in_size, out_size], stddev=0.1)
    weight_set.append(w)
    b = weight_var([out_size], stddev=0)
    weight_set.append(b)
    x = tf.matmul(input, w)
    return leaky_relu(x + b)
Exemplo n.º 4
0
        def create_conv(input, in_channels, out_channels, weight_set=[]):
            input = batch_norm(input, variables_collections=[weight_set])
            w = weight_var([patch_size, patch_size, in_channels, out_channels])
            b = weight_var([out_channels])
            weight_set.append(w)
            weight_set.append(b)

            conv = tf.nn.conv2d(input, w, strides=[1, 2, 2, 1], padding='SAME')
            activation = leaky_relu(conv + b)
            return activation
Exemplo n.º 5
0
def predict_embedding(node, params):
    embedding_op = leaky_relu(node.operator_feature, params['w_emd_op'])
    embedding_table = leaky_relu(node.table_feature, params['w_emd_t'])
    embedding_sample = leaky_relu(node.sample_bitmap, params['w_emd_s'])

    embedding_predicate = np.zeros((1, node.dim_predicate_embedding))
    for predicate_vector in node.predicates_list:
        current_embedding = leaky_relu(predicate_vector, params['w_emd_p'])
        embedding_predicate = np.maximum(embedding_predicate,
                                         current_embedding)

    for predicate_vector in node.join_predicates_list:
        current_embedding = leaky_relu(predicate_vector, params['w_emd_jp'])
        embedding_predicate = np.maximum(embedding_predicate,
                                         current_embedding)

    embedding = np.concatenate(
        (embedding_op, embedding_table, embedding_sample, embedding_predicate),
        axis=1)

    return embedding
Exemplo n.º 6
0
def create_conv(input, out_channels, patch_size=2, stride=2, weight_set=[]):
    in_channels = input.get_shape()[-1]
    w = weight_var([patch_size, patch_size, in_channels, out_channels],
                   stddev=0.1)
    b = weight_var([out_channels], stddev=0)
    conv = tf.nn.conv2d(input,
                        w,
                        strides=[1, stride, stride, 1],
                        padding='SAME')
    activation = leaky_relu(conv + b)  # tf.nn.relu(conv + b)
    weight_set.append(w)
    weight_set.append(b)
    return activation
Exemplo n.º 7
0
 def create_conv_with_pooling(input,
                              in_channels,
                              out_channels,
                              weight_set=[]):
     w = weight_var([patch_size, patch_size, in_channels, out_channels])
     b = weight_var([out_channels], init_zero=True)
     conv = tf.nn.conv2d(input, w, strides=[1, 1, 1, 1], padding='SAME')
     activation = leaky_relu(conv + b)
     weight_set.append(w)
     weight_set.append(b)
     pooled = tf.nn.max_pool(activation,
                             ksize=[1, 2, 2, 1],
                             strides=[1, 2, 2, 1],
                             padding='SAME')
     return pooled
Exemplo n.º 8
0
 def create_dense(input,
                  in_size,
                  out_size,
                  weight_set=[],
                  relu=True,
                  no_bias=False):
     input = batch_norm(input)
     input_dropped = tf.nn.dropout(input, disc_dropout_keep_prob)
     w = weight_var([in_size, out_size])
     weight_set.append(w)
     b = weight_var([out_size], init_zero=no_bias)
     if not no_bias:
         weight_set.append(b)
     x = tf.matmul(input_dropped, w)
     return leaky_relu(x + b) if relu else x + b
Exemplo n.º 9
0
def create_deconv(input, out_channels, patch_size=2, stride=2, weight_set=[]):
    # stride should be multiple of patch_size for best results
    in_channels = input.get_shape()[-1]
    input_image_width, input_image_height = input_image_size.get_shape()[2:4]

    w = weight_var([patch_size, patch_size, out_channels, in_channels])
    weight_set.append(w)
    b = weight_var([out_channels], init_zero=no_bias)
    weight_set.append(b)

    batch_size = tf.shape(input)[0]
    output_shape = tf.pack([
        batch_size, input_image_width * stride, input_image_height * stride,
        out_channels
    ])

    deconv = tf.nn.conv2d_transpose(input,
                                    w,
                                    output_shape,
                                    strides=[1, stride, stride, 1],
                                    padding='SAME')
    return leaky_relu(deconv + b)
Exemplo n.º 10
0
def generator_caffenet_fc6(input_feat, reuse=False, trainable=False):
    with tf.variable_scope('generator', reuse=reuse) as vs:
        assert input_feat.get_shape().as_list()[-1] == 4096
        # input_feat = tf.placeholder(tf.float32, shape=(None, 4096), name='feat')

        relu_defc7 = leaky_relu(
            fc(input_feat, 4096, name='defc7', trainable=trainable))
        relu_defc6 = leaky_relu(
            fc(relu_defc7, 4096, name='defc6', trainable=trainable))
        relu_defc5 = leaky_relu(
            fc(relu_defc6, 4096, name='defc5', trainable=trainable))
        reshaped_defc5 = tf.reshape(relu_defc5, [-1, 256, 4, 4])
        relu_deconv5 = leaky_relu(
            upconv(tf.transpose(reshaped_defc5, perm=[0, 2, 3, 1]),
                   256,
                   4,
                   2,
                   'deconv5',
                   biased=True,
                   trainable=trainable))
        relu_conv5_1 = leaky_relu(
            upconv(relu_deconv5,
                   512,
                   3,
                   1,
                   'conv5_1',
                   biased=True,
                   trainable=trainable))
        relu_deconv4 = leaky_relu(
            upconv(relu_conv5_1,
                   256,
                   4,
                   2,
                   'deconv4',
                   biased=True,
                   trainable=trainable))
        relu_conv4_1 = leaky_relu(
            upconv(relu_deconv4,
                   256,
                   3,
                   1,
                   'conv4_1',
                   biased=True,
                   trainable=trainable))
        relu_deconv3 = leaky_relu(
            upconv(relu_conv4_1,
                   128,
                   4,
                   2,
                   'deconv3',
                   biased=True,
                   trainable=trainable))
        relu_conv3_1 = leaky_relu(
            upconv(relu_deconv3,
                   128,
                   3,
                   1,
                   'conv3_1',
                   biased=True,
                   trainable=trainable))
        deconv2 = leaky_relu(
            upconv(relu_conv3_1,
                   64,
                   4,
                   2,
                   'deconv2',
                   biased=True,
                   trainable=trainable))
        deconv1 = leaky_relu(
            upconv(deconv2,
                   32,
                   4,
                   2,
                   'deconv1',
                   biased=True,
                   trainable=trainable))
        deconv0 = upconv(deconv1,
                         3,
                         4,
                         2,
                         'deconv0',
                         biased=True,
                         trainable=trainable)

    variables = tf.contrib.framework.get_variables(vs)

    return deconv0, variables, [
        relu_defc7, relu_defc6, relu_defc5, reshaped_defc5, relu_deconv5,
        relu_conv5_1, relu_deconv4, relu_conv4_1, relu_deconv3, relu_conv3_1,
        deconv2, deconv1, deconv0
    ]