Skip to content

Dropout Appears to Lose Tensor Shape #344

Closed

Description

@JosephCatrambone

While training a model, I encountered a strange issue around dropout. I can't yet rule out user error and haven't yet produced the minimum viable product, but I wanted to get this on the board before I forgot.

# With dropout...
        wc1 = tf.Variable(tf.random_normal([1, sample_vec_len, 1, 64]))
        bc1 = tf.Variable(tf.random_normal([64,]))
        conv1 = tf.nn.conv2d(inputs, wc1, strides=[1, 1, 1, 1], padding='SAME') + bc1
        act1 = tf.nn.relu(conv1)
        drop1 = tf.nn.dropout(act1, keep_prob=dropout_toggle)
        # TensorShape([Dimension(None), Dimension(1), Dimension(4620), Dimension(64)])

        wc2 = tf.Variable(tf.random_normal([1, char_sample_size, 64, 32]))
        bc2 = tf.Variable(tf.random_normal([32,]))
        conv2 = tf.nn.conv2d(drop1, wc2, strides=[1, 1, 1, 1], padding='SAME') + bc2
        act2 = tf.nn.relu(conv2)
        norm2 = tf.nn.lrn(act2, bitreader.get_sentence_vector_length(1), bias=1.0, alpha=0.001, beta=0.75)
        # TensorShape([Dimension(None), Dimension(1), Dimension(4620), Dimension(32)])

        # Conv -> FC
        dims = act2.get_shape()
        shape = [dims[0].value, dims[1].value, dims[2].value, dims[3].value] # dims[0].value -> None
        c_fc = tf.reshape(act2, [-1, shape[1]*shape[2]*shape[3]])

(venv)jcatrambone-osx:nlp jcatrambone$ python ./nlp_tensorflow.py ../wikipedia_utf8_filtered_20pageviews.csv.gz 1
Building model.
Traceback (most recent call last):
File "./nlp_tensorflow.py", line 92, in
encoder, decoder, weights, biases = build_model("ConvNLP", x, keep_prob)
File "./nlp_tensorflow.py", line 56, in build_model
c_fc = tf.reshape(act2, [-1, shape[1]_shape[2]_shape[3]])
TypeError: unsupported operand type(s) for *: 'NoneType' and 'NoneType'

# Remove dropout...
        wc1 = tf.Variable(tf.random_normal([1, sample_vec_len, 1, 64]))
        bc1 = tf.Variable(tf.random_normal([64,]))
        conv1 = tf.nn.conv2d(inputs, wc1, strides=[1, 1, 1, 1], padding='SAME') + bc1
        act1 = tf.nn.relu(conv1)
        # TensorShape([Dimension(None), Dimension(1), Dimension(4620), Dimension(64)])

        wc2 = tf.Variable(tf.random_normal([1, char_sample_size, 64, 32]))
        bc2 = tf.Variable(tf.random_normal([32,]))
        conv2 = tf.nn.conv2d(act1, wc2, strides=[1, 1, 1, 1], padding='SAME') + bc2
        act2 = tf.nn.relu(conv2)
        norm2 = tf.nn.lrn(act2, bitreader.get_sentence_vector_length(1), bias=1.0, alpha=0.001, beta=0.75)
        # TensorShape([Dimension(None), Dimension(1), Dimension(4620), Dimension(32)])

        # Conv -> FC
        dims = act2.get_shape()
        shape = [dims[0].value, dims[1].value, dims[2].value, dims[3].value] # dims[0].value -> None
        c_fc = tf.reshape(act2, [-1, shape[1]*shape[2]*shape[3]])

(venv)jcatrambone-osx:nlp jcatrambone$ python ./nlp_tensorflow.py ../wikipedia_utf8_filtered_20pageviews.csv.gz 1
Building model.
Defining loss functions and optimizer.
Gathering variables.
Beginning training session.
can't determine number of CPU cores: assuming 4
I tensorflow/core/common_runtime/local_device.cc:25] Local device intra op parallelism threads: 4
can't determine number of CPU cores: assuming 4
I tensorflow/core/common_runtime/local_session.cc:45] Local session inter op parallelism threads: 4
Initializing variables.
Session, variables, and generator initialized. Training.

Runs fine...

Activity

  1. vrv commented on Nov 24, 2015

    @vrv

    Did you use the binary install? I think we fixed a bug in dropout shape inference, so it is fixed in the source.

    I'll de-dupe with #184, since it is likely related.

  2. JosephCatrambone commented on Nov 24, 2015

    @JosephCatrambone
    Author

    Yup. Binary install on all my machines. I'll do a pull and verify the fix. Thanks for the help and sorry for the noise -- I really did search for (open) issues before posting. :)

  3. halilakin commented on Dec 25, 2015

    @halilakin

    Oh, had the same issue. Thanks

  4. added 2 commits that reference this issue on Jan 23, 2020
  5. added a commit that references this issue on May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions