privacy icon indicating copy to clipboard operation
privacy copied to clipboard

tensorflow.python.framework.errors_impl.InvalidArgumentError

Open Viserion-nlper opened this issue 5 years ago • 4 comments

Traceback (most recent call last): File "D:\Anaconda2\envs\tf1\lib\site-packages\tensorflow_core\python\framework\ops.py", line 1607, in _create_c_op c_op = c_api.TF_FinishOperation(op_desc) tensorflow.python.framework.errors_impl.InvalidArgumentError: Dimension size must be evenly divisible by 250 but is 1 for 'training/Reshape' (op: 'Reshape') with input shapes: [], [2] and with input tensors computed as partial s

how can i sovle it ,thanks

Yes that issue is known to the recent version of TensorFlow-privacy. When I checked in way in Feb, it was running fine, we need to raise this issue with TensorFlow-privacy.. https://hackernoon.com/differential-privacy-with-tensorflow-20-multi-class-text-classification-privacy-yk7a37uh.

here, the code snippets and results are attached..

I doubt it was the version problem? thanks

Viserion-nlper avatar Jul 01 '20 00:07 Viserion-nlper

Here is the GitHub checkins https://github.com/sharmi1206/differential-privacy-tensorflow/, where all the code related to DP was working in FEB , when it was checkedin. With tensorflow -1.1.15

What changes have gone in Tensorflow-privacy to result in this and how can we correct it. Please help us with the fix.

File "D:\Anaconda2\envs\tf1\lib\site-packages\tensorflow_core\python\framework\ops.py", line 1607, in _create_c_op c_op = c_api.TF_FinishOperation(op_desc) tensorflow.python.framework.errors_impl.InvalidArgumentError: Dimension size must be evenly divisible by 250 but is 1 for 'training/Reshape' (op: 'Reshape') with input shapes: [], [2] and with input tensors computed as partial s

Here's the code snippet. All detailed code is available at (https://github.com/sharmi1206/differential-privacy-tensorflow)

validation_sequences = tokenizer.texts_to_sequences(validation_articles) validation_padded = pad_sequences(validation_sequences, maxlen=max_length) training_label_seq = np.array(label_tokenizer.texts_to_sequences(train_labels)) validation_label_seq = np.array(label_tokenizer.texts_to_sequences(validation_labels))

reverse_word_index = dict([(value, key) for (key, value) in word_index.items()])
model = tf.keras.Sequential([
    # Add an Embedding layer expecting input vocab of size 5000, and output embedding dimension of size 64 we set at the top
    tf.keras.layers.Embedding(vocab_size, embedding_dim),
    tf.keras.layers.Bidirectional(tf.keras.layers.LSTM(embedding_dim)),
#    tf.keras.layers.Bidirectional(tf.keras.layers.LSTM(32)),
    # use ReLU in place of tanh function since they are very good alternatives of each other.
    tf.keras.layers.Dense(embedding_dim, activation='relu'),
    # Add a Dense layer with 6 units and softmax activation.
    # When we have multiple outputs, softmax convert outputs layers into a probability distribution.
    tf.keras.layers.Dense(6, activation='softmax')
])
model.summary()
if FLAGS.dpsgd:
    optimizer = DPAdamGaussianOptimizer(
        l2_norm_clip=FLAGS.l2_norm_clip,
        noise_multiplier=FLAGS.noise_multiplier,
        num_microbatches=FLAGS.microbatches,
        learning_rate=FLAGS.learning_rate)
      # reduction=tf.compat.v1.losses.Reduction.NONE
else:
    optimizer = AdamOptimizer()


model.compile(loss='sparse_categorical_crossentropy', optimizer=optimizer, metrics=['accuracy'])

num_epochs = 10
history = model.fit(train_padded, training_label_seq, epochs=num_epochs, validation_data=(validation_padded, validation_label_seq), verbose=2)

sharmi1206 avatar Jul 01 '20 03:07 sharmi1206

Would you please tell me what the progress of work

Viserion-nlper avatar Jul 04 '20 06:07 Viserion-nlper

I followed up with tensorflow issue link. They have not responded yet.

sharmi1206 avatar Jul 06 '20 18:07 sharmi1206

Everything works fine with Multi-class text classification with SparseCategorical Cross-Entropy and Adam Optimizer. Just changing the optimizer to DPGradientDescent/DPGaussianOptimizer ( optimizer = DPGradientDescentGaussianOptimizer( l2_norm_clip=l2_norm_clip, noise_multiplier=noise_multiplier, num_microbatches=int(microbatches_perc * batch_size), learning_rate=learning_rate)

OR

optimizer = DPAdamGaussianOptimizer(
    l2_norm_clip=l2_norm_clip,
    noise_multiplier=noise_multiplier,
    num_microbatches=int(microbatches_perc * batch_size),
    learning_rate=learning_rate)

gives

tensorflow.python.framework.errors_impl.InvalidArgumentError: Input to reshape is a tensor with 2 values, but the requested shape requires a multiple of 16 [[{{node training/Reshape}}]]

sharmi1206 avatar Sep 16 '20 14:09 sharmi1206