0

What dimensions are required in tf.nn.conv1d ? and how to perform max pooling afterwards?

a.kh
  • 25
  • 5

1 Answers1

0

A simple example snip:

               filter = tf.zeros([3, 16, 16])
                W = tf.Variable(tf.truncated_normal(filter, stddev=0.1), name="W")
                b = tf.Variable(tf.constant(0.1, shape=[num_filters]), name="b")
                conv = tf.nn.conv1d(
                    input_values,
                    W,
                    strides=2,
                    padding="VALID",
                    name="conv")
                # nonlinearity operation
                h = tf.nn.relu(tf.nn.bias_add(conv, b), name="relu")
                # Maxpooling over the outputs
                pooled = tf.nn.max_pool(
                    h,
                    ksize=[1, sequence_length - filter_size + 1, 1, 1],
                    strides=[1, 1, 1, 1],
                    padding='VALID',
                    name="pool")
                pooled_outputs.append(pooled)

Check this answer as well.

Gun2sh
  • 870
  • 12
  • 22
  • self.W = tf.Variable( tf.constant(0.0, shape=[vocab_size, embedding_size]), trainable=trainableEmbeddings,name="W") self.embedded_words1 = tf.nn.embedding_lookup(self.W, self.input_x1) self.embedded_words2 = tf.nn.embedding_lookup(self.W, self.input_x2) self.one_embedding=tf.concat([self.embedded_words1,self.embedded_words2], 1) This is my input, but im facing this error "ValueError: Dimensions must be equal, but are 100 and 1 for 'conv-maxpool-3/conv/Conv2D' (op: 'Conv2D') with input shapes: [?,1,30,100], [1,3,1,128]." – a.kh Jan 14 '18 at 16:18
  • Can you please give an example on input shape ? – a.kh Jan 14 '18 at 17:06
  • the input of conv1d can be: x = tf.placeholder(tf.float32, [batch_size, 10, 16]). check the link where it has the Guide to 1D con – Gun2sh Jan 14 '18 at 20:10