kartik-joshi / Adversarial-Attack-on-Recurrent-Neural-Network

Implement adversarial arrack on Recurrent Neural network built to perform sentiment analysis with LSTM using TensorFlow
BSD 2-Clause "Simplified" License
21 stars 5 forks source link

I am getting ValueError: Cannot reshape a tensor with 32768000 elements to shape [1000,256] (256000 elements) for 'sequential/reshape/Reshape' (op: 'Reshape') with input shapes: [1000,16,16,128], [2] and with input tensors computed as partial shapes: input[1] = [1000,256]. #2

Open khorshidisamira opened 4 years ago

khorshidisamira commented 4 years ago

Hello, I tried to run test_attack.py code but this is what I am getting:

Loading data... 25000 train sequences 25000 test sequences train labals 25000 train Shape issssss (25000,) after process 25000 Test labals 25000 after process 25000 Pad sequences (samples x time) x_train shape: (25000, 256) x_test shape: (25000, 256) Max value 19999 Build model... WARNING:tensorflow:From /home/sakhors/Competition2/2DConv/comp/lib/python3.7/site-packages/tensorflow_core/python/keras/initializers.py:119: calling RandomUniform.init (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version. Instructions for updating: Call initializer instance with the dtype argument instead of passing it to the constructor WARNING:tensorflow:From /home/sakhors/Competition2/2DConv/comp/lib/python3.7/site-packages/tensorflow_core/python/ops/resource_variable_ops.py:1630: calling BaseResourceVariable.init (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version. Instructions for updating: If using Keras pass *_constraint arguments to layers. WARNING:tensorflow:From /home/sakhors/Research_direction/Neural_point_process/Adversarial_attacks/Adversarial-Attack-on-Recurrent-Neural-Network-master/l2_attack.py:79: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.

++++++++++++++++++++++++++++++++++++++++++++++++++++ Traceback (most recent call last): File "/home/sakhors/Competition2/2DConv/comp/lib/python3.7/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: Cannot reshape a tensor with 32768000 elements to shape [1000,256] (256000 elements) for 'sequential/reshape/Reshape' (op: 'Reshape') with input shapes: [1000,16,16,128], [2] and with input tensors computed as partial shapes: input[1] = [1000,256].

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "test_attack.py", line 82, in attack = CarliniL2(sess, model, batch_size=1000, max_iterations=1000, confidence=0, targeted=True) File "/home/sakhors/Research_direction/Neural_point_process/Adversarial_attacks/Adversarial-Attack-on-Recurrent-Neural-Network-master/l2_attack.py", line 96, in init self.output = model.predict(self.pass_to_model) File "/home/sakhors/Research_direction/Neural_point_process/Adversarial_attacks/Adversarial-Attack-on-Recurrent-Neural-Network-master/setup_rnn_keras_imdb.py", line 137, in predict return self.model(data) File "/home/sakhors/Competition2/2DConv/comp/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/base_layer.py", line 854, in call outputs = call_fn(cast_inputs, args, kwargs) File "/home/sakhors/Competition2/2DConv/comp/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/sequential.py", line 255, in call return super(Sequential, self).call(inputs, training=training, mask=mask) File "/home/sakhors/Competition2/2DConv/comp/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/network.py", line 695, in call return self._run_internal_graph(inputs, training=training, mask=mask) File "/home/sakhors/Competition2/2DConv/comp/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/network.py", line 844, in _run_internal_graph output_tensors = layer(computed_tensors, kwargs) File "/home/sakhors/Competition2/2DConv/comp/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/base_layer.py", line 854, in call outputs = call_fn(cast_inputs, args, *kwargs) File "/home/sakhors/Competition2/2DConv/comp/lib/python3.7/site-packages/tensorflow_core/python/keras/layers/core.py", line 471, in call (array_ops.shape(inputs)[0],) + self.target_shape) File "/home/sakhors/Competition2/2DConv/comp/lib/python3.7/site-packages/tensorflow_core/python/ops/array_ops.py", line 131, in reshape result = gen_array_ops.reshape(tensor, shape, name) File "/home/sakhors/Competition2/2DConv/comp/lib/python3.7/site-packages/tensorflow_core/python/ops/gen_array_ops.py", line 8115, in reshape "Reshape", tensor=tensor, shape=shape, name=name) File "/home/sakhors/Competition2/2DConv/comp/lib/python3.7/site-packages/tensorflow_core/python/framework/op_def_library.py", line 794, in _apply_op_helper op_def=op_def) File "/home/sakhors/Competition2/2DConv/comp/lib/python3.7/site-packages/tensorflow_core/python/util/deprecation.py", line 507, in new_func return func(args, **kwargs) File "/home/sakhors/Competition2/2DConv/comp/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 3357, in create_op attrs, op_def, compute_device) File "/home/sakhors/Competition2/2DConv/comp/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 3426, in _create_op_internal op_def=op_def) File "/home/sakhors/Competition2/2DConv/comp/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 1770, in init control_input_ops) File "/home/sakhors/Competition2/2DConv/comp/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 1610, in _create_c_op raise ValueError(str(e)) ValueError: Cannot reshape a tensor with 32768000 elements to shape [1000,256] (256000 elements) for 'sequential/reshape/Reshape' (op: 'Reshape') with input shapes: [1000,16,16,128], [2] and with input tensors computed as partial shapes: input[1] = [1000,256].

Any idea? My os is Ubuntu 18 and I am using keras 2.3.1 and tensorlow 1.15.

drrain92 commented 4 years ago

I have the same issue with you.

paullintilhac commented 1 year ago

same here. still no solution? any forks that solve this?