shaoyuca / FrictGAN-Image-to-Friction-Generation

FrictGAN-Sorce code and dataset for CAG journal
6 stars 0 forks source link

ValueError: input tensor must have rank 4 #1

Closed neverstoplearn closed 2 years ago

neverstoplearn commented 2 years ago

when I run the code,I got this error: Epoch: 0 WARNING:tensorflow:Model was constructed with shape Tensor("input_2:0", shape=(None, 1024, 1024, 1), dtype=float32) for input (None, 1024, 1024, 1), but it was re-called on a Tensor with incompatible shape (8, 1024, 1024). .Traceback (most recent call last): File "/home/zhengxin/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow_core/python/framework/tensor_shape.py", line 923, in merge_with self.assert_same_rank(other) File "/home/zhengxin/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow_core/python/framework/tensor_shape.py", line 978, in assert_same_rank (self, other)) ValueError: Shapes (8, 1024, 1024) and (None, None, None, None) must have the same rank

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/zhengxin/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow_core/python/framework/tensor_shape.py", line 1008, in with_rank return self.merge_with(unknown_shape(rank=rank)) File "/home/zhengxin/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow_core/python/framework/tensor_shape.py", line 929, in merge_with raise ValueError("Shapes %s and %s are not compatible" % (self, other)) ValueError: Shapes (8, 1024, 1024) and (None, None, None, None) are not compatible

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/zhengxin/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow_core/python/ops/nn_ops.py", line 1065, in init input_shape.with_rank(num_spatial_dims + 2) File "/home/zhengxin/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow_core/python/framework/tensor_shape.py", line 1010, in with_rank raise ValueError("Shape %s must have rank %d" % (self, rank)) ValueError: Shape (8, 1024, 1024) must have rank 4

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "FrictganNet.py", line 538, in main() File "FrictganNet.py", line 520, in main fit(train_dataset, args.epoch, test_dataset) File "FrictganNet.py", line 496, in fit D = train_step_dis(input_image, target, epoch) File "FrictganNet.py", line 460, in train_step_dis gen_output, latent_code = generator([input_image, noise], training=True) File "/home/zhengxin/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/base_layer.py", line 822, in call outputs = self.call(cast_inputs, args, kwargs) File "/home/zhengxin/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/network.py", line 717, in call convert_kwargs_to_constants=base_layer_utils.call_context().saving) File "/home/zhengxin/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/network.py", line 891, in _run_internal_graph output_tensors = layer(computed_tensors, kwargs) File "/home/zhengxin/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/base_layer.py", line 822, in call outputs = self.call(cast_inputs, args, **kwargs) File "/home/zhengxin/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow_core/python/keras/layers/convolutional.py", line 203, in call data_format=self._conv_op_data_format) File "/home/zhengxin/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow_core/python/ops/nn_ops.py", line 1068, in init "input tensor must have rank %d" % (num_spatial_dims + 2)) ValueError: input tensor must have rank 4 how can i fix it? thanks.

shaoyuca commented 2 years ago

I guess it was because the dimension of tensors is not aligned. The input tensor should be [batch_size, 1024, 1024, 1] as the input, but seems the bug was due to the input tensor shape being [batch_size, 1024, 1024]. Did you use your created new dataset? In my dataset, I initially set the data representation of the input grey-scale image as [1024, 1024], so extra processing is to convert it as [1024, 1024, 1] in the data-processing stage. Such the implementation should be in the script of the data processing.

neverstoplearn commented 2 years ago

thanks.i solve it by update the tensorflow version