Wasserstein GAN based on neuralgym gives color-channel ValueError: Dimension 0 in both shapes must be equal, but are 1 and 3. Shapes are [1] and [3]

Viewed 41

I keep getting Errors when trying out a forked Git from konstantg.

The aim is, equally to the original project, to inpaint images with a given or randomly created mask with help of a neural network (a modified Wasserstein Generative adversarial network in this case). The given network can be trained on own data sets in the format of images. The GitHub Repository can crop images of different sizes to modifiable (see inpaint.yml) sizes of shape like [256,256,1] or [512,512,3].

The main difference between the fork and the original is the number of color channels ([x,x,3] or [x,x,1]) that are used in the images, which also seems to be connected to my problem.

On Github, LP429 has the same issue like me, but did not document whether a solution was found, nor is konstantg's comment helpful. He is right regarding that there is a problem with the library neuralgym, but I copied his fork of JiahuiYu's neuralgym over and over into my folder and it did not help.

The images I put in have 1 color channel, but I think the neuralgym library somewhere still expects 3 color channels. I just can't find it.

Click on the link under the error sample in order to replicate the error locally. I have added all necessary libraries, folders and files to the fork from konstantg and changes to specific files were made according to the 'Issues' region of this project;

You only need to open run.ipynb and run all cells to get this Error:

My Error:

[2022-08-11 20:03:21 @__init__.py:79] Set root logger. Unset logger with neuralgym.unset_logger().
[2022-08-11 20:03:21 @__init__.py:80] Saving logging to file: neuralgym_logs/20220811200320970248.
[2022-08-11 20:03:21 @config.py:92] ---------------------------------- APP CONFIG ----------------------------------
[2022-08-11 20:03:21 @config.py:119] DATASET: land
[2022-08-11 20:03:21 @config.py:119] RANDOM_CROP: False
[2022-08-11 20:03:21 @config.py:119] VAL: False
[2022-08-11 20:03:21 @config.py:119] LOG_DIR: land
[2022-08-11 20:03:21 @config.py:119] MODEL_RESTORE: 
[2022-08-11 20:03:21 @config.py:119] GAN: wgan_gp
[2022-08-11 20:03:21 @config.py:119] PRETRAIN_COARSE_NETWORK: False
[2022-08-11 20:03:21 @config.py:119] GAN_LOSS_ALPHA: 0.001
[2022-08-11 20:03:21 @config.py:119] WGAN_GP_LAMBDA: 10
[2022-08-11 20:03:21 @config.py:119] COARSE_L1_ALPHA: 1.2
[2022-08-11 20:03:21 @config.py:119] L1_LOSS_ALPHA: 1.2
[2022-08-11 20:03:21 @config.py:119] AE_LOSS_ALPHA: 1.2
[2022-08-11 20:03:21 @config.py:119] GAN_WITH_MASK: False
[2022-08-11 20:03:21 @config.py:119] DISCOUNTED_MASK: True
[2022-08-11 20:03:21 @config.py:119] RANDOM_SEED: False
[2022-08-11 20:03:21 @config.py:119] PADDING: SAME
[2022-08-11 20:03:21 @config.py:119] NUM_GPUS: 1
[2022-08-11 20:03:21 @config.py:119] GPU_ID: -1
[2022-08-11 20:03:21 @config.py:119] TRAIN_SPE: 10000
[2022-08-11 20:03:21 @config.py:119] MAX_ITERS: 1000000
[2022-08-11 20:03:21 @config.py:119] VIZ_MAX_OUT: 10
[2022-08-11 20:03:21 @config.py:119] GRADS_SUMMARY: False
[2022-08-11 20:03:21 @config.py:119] GRADIENT_CLIP: False
[2022-08-11 20:03:21 @config.py:119] GRADIENT_CLIP_VALUE: 0.1
[2022-08-11 20:03:21 @config.py:119] VAL_PSTEPS: 10000000
[2022-08-11 20:03:21 @config.py:111] DATA_FLIST: 
[2022-08-11 20:03:21 @config.py:119]   land: ['data_flist/train_shuffled.flist', 'data_flist/validation_static_view.flist']
[2022-08-11 20:03:21 @config.py:119] STATIC_VIEW_SIZE: 30
[2022-08-11 20:03:21 @config.py:119] IMG_SHAPES: [256, 256, 1]
[2022-08-11 20:03:21 @config.py:119] HEIGHT: 256
[2022-08-11 20:03:21 @config.py:119] WIDTH: 256
[2022-08-11 20:03:21 @config.py:119] MAX_DELTA_HEIGHT: 64
[2022-08-11 20:03:21 @config.py:119] MAX_DELTA_WIDTH: 64
[2022-08-11 20:03:21 @config.py:119] BATCH_SIZE: 32
[2022-08-11 20:03:21 @config.py:119] VERTICAL_MARGIN: 0
[2022-08-11 20:03:21 @config.py:119] HORIZONTAL_MARGIN: 0
[2022-08-11 20:03:21 @config.py:119] AE_LOSS: True
[2022-08-11 20:03:21 @config.py:119] L1_LOSS: True
[2022-08-11 20:03:21 @config.py:119] GLOBAL_DCGAN_LOSS_ALPHA: 1.0
[2022-08-11 20:03:21 @config.py:119] GLOBAL_WGAN_LOSS_ALPHA: 1.0
[2022-08-11 20:03:21 @config.py:119] LOAD_VGG_MODEL: False
[2022-08-11 20:03:21 @config.py:119] VGG_MODEL_FILE: data/model_zoo/vgg16.npz
[2022-08-11 20:03:21 @config.py:119] FEATURE_LOSS: False
[2022-08-11 20:03:21 @config.py:119] GRAMS_LOSS: False
[2022-08-11 20:03:21 @config.py:119] TV_LOSS: False
[2022-08-11 20:03:21 @config.py:119] TV_LOSS_ALPHA: 0.0
[2022-08-11 20:03:21 @config.py:119] FEATURE_LOSS_ALPHA: 0.01
[2022-08-11 20:03:21 @config.py:119] GRAMS_LOSS_ALPHA: 50
[2022-08-11 20:03:21 @config.py:119] SPATIAL_DISCOUNTING_GAMMA: 0.9
[2022-08-11 20:03:21 @config.py:94] --------------------------------------------------------------------------------
[2022-08-11 20:03:21 @dataset.py:26] --------------------------------- Dataset Info ---------------------------------
[2022-08-11 20:03:21 @dataset.py:36] file_length: 7
[2022-08-11 20:03:21 @dataset.py:36] random: False
[2022-08-11 20:03:21 @dataset.py:36] random_crop: False
[2022-08-11 20:03:21 @dataset.py:36] filetype: image
[2022-08-11 20:03:21 @dataset.py:36] shapes: [[256, 256, 1]]
[2022-08-11 20:03:21 @dataset.py:36] dtypes: [tf.float32]
[2022-08-11 20:03:21 @dataset.py:36] return_fnames: False
[2022-08-11 20:03:21 @dataset.py:36] batch_phs: [<tf.Tensor 'Placeholder:0' shape=(?, 256, 256, 1) dtype=float32>]
[2022-08-11 20:03:21 @dataset.py:36] enqueue_size: 32
[2022-08-11 20:03:21 @dataset.py:36] queue_size: 256
[2022-08-11 20:03:21 @dataset.py:36] nthreads: 16
[2022-08-11 20:03:21 @dataset.py:36] fn_preprocess: None
[2022-08-11 20:03:21 @dataset.py:36] index: 0
[2022-08-11 20:03:21 @dataset.py:37] --------------------------------------------------------------------------------
[2022-08-11 20:03:24 @inpaint_model.py:169] Set batch_predicted to x2.
[2022-08-11 20:03:24 @inpaint_ops.py:201] Use spatial discounting l1 loss.
[2022-08-11 20:03:24 @inpaint_ops.py:201] Use spatial discounting l1 loss.
[2022-08-11 20:03:25 @inpaint_model.py:251] Set L1_LOSS_ALPHA to 1.200000
[2022-08-11 20:03:25 @inpaint_model.py:252] Set GAN_LOSS_ALPHA to 0.001000
[2022-08-11 20:03:25 @inpaint_model.py:255] Set AE_LOSS_ALPHA to 1.200000
[2022-08-11 20:03:27 @inpaint_model.py:169] Set batch_predicted to x2.
[2022-08-11 20:03:27 @inpaint_ops.py:201] Use spatial discounting l1 loss.
[2022-08-11 20:03:27 @inpaint_ops.py:201] Use spatial discounting l1 loss.
[2022-08-11 20:03:28 @inpaint_model.py:251] Set L1_LOSS_ALPHA to 1.200000
[2022-08-11 20:03:28 @inpaint_model.py:252] Set GAN_LOSS_ALPHA to 0.001000
[2022-08-11 20:03:28 @inpaint_model.py:255] Set AE_LOSS_ALPHA to 1.200000
[2022-08-11 20:03:28 @trainer.py:61] ------------------------- Context Of Secondary Trainer -------------------------
[2022-08-11 20:03:28 @trainer.py:63] optimizer: <tensorflow.python.training.adam.AdamOptimizer object at 0x7f72e5958c50>
[2022-08-11 20:03:28 @trainer.py:63] var_list: [<tf.Variable 'discriminator/discriminator_local/conv1/kernel:0' shape=(5, 5, 1, 32) dtype=float32_ref>, <tf.Variable 'discriminator/discriminator_local/conv1/bias:0' shape=(32,) dtype=float32_ref>, <tf.Variable 'discriminator/discriminator_local/conv2/kernel:0' shape=(5, 5, 32, 64) dtype=float32_ref>, <tf.Variable 'discriminator/discriminator_local/conv2/bias:0' shape=(64,) dtype=float32_ref>, <tf.Variable 'discriminator/discriminator_local/conv3/kernel:0' shape=(5, 5, 64, 128) dtype=float32_ref>, <tf.Variable 'discriminator/discriminator_local/conv3/bias:0' shape=(128,) dtype=float32_ref>, <tf.Variable 'discriminator/discriminator_local/conv4/kernel:0' shape=(5, 5, 128, 256) dtype=float32_ref>, <tf.Variable 'discriminator/discriminator_local/conv4/bias:0' shape=(256,) dtype=float32_ref>, <tf.Variable 'discriminator/discriminator_global/conv1/kernel:0' shape=(5, 5, 1, 32) dtype=float32_ref>, <tf.Variable 'discriminator/discriminator_global/conv1/bias:0' shape=(32,) dtype=float32_ref>, <tf.Variable 'discriminator/discriminator_global/conv2/kernel:0' shape=(5, 5, 32, 64) dtype=float32_ref>, <tf.Variable 'discriminator/discriminator_global/conv2/bias:0' shape=(64,) dtype=float32_ref>, <tf.Variable 'discriminator/discriminator_global/conv3/kernel:0' shape=(5, 5, 64, 128) dtype=float32_ref>, <tf.Variable 'discriminator/discriminator_global/conv3/bias:0' shape=(128,) dtype=float32_ref>, <tf.Variable 'discriminator/discriminator_global/conv4/kernel:0' shape=(5, 5, 128, 128) dtype=float32_ref>, <tf.Variable 'discriminator/discriminator_global/conv4/bias:0' shape=(128,) dtype=float32_ref>, <tf.Variable 'discriminator/dout_local_fc/kernel:0' shape=(65536, 1) dtype=float32_ref>, <tf.Variable 'discriminator/dout_local_fc/bias:0' shape=(1,) dtype=float32_ref>, <tf.Variable 'discriminator/dout_global_fc/kernel:0' shape=(32768, 1) dtype=float32_ref>, <tf.Variable 'discriminator/dout_global_fc/bias:0' shape=(1,) dtype=float32_ref>]
[2022-08-11 20:03:28 @trainer.py:63] graph_def: <function multigpu_graph_def at 0x7f73586ec1e0>
[2022-08-11 20:03:28 @trainer.py:63] graph_def_kwargs: {'model': <inpaint_model.InpaintCAModel object at 0x7f72ecdbe748>, 'data': <neuralgym.data.data_from_fnames.DataFromFNames object at 0x7f72ecdf7320>, 'config': {}, 'loss_type': 'd'}
[2022-08-11 20:03:28 @trainer.py:63] feed_dict: {}
[2022-08-11 20:03:28 @trainer.py:63] max_iters: 5
[2022-08-11 20:03:28 @trainer.py:63] log_dir: /tmp/neuralgym
[2022-08-11 20:03:28 @trainer.py:63] spe: 1
[2022-08-11 20:03:28 @trainer.py:63] grads_summary: True
[2022-08-11 20:03:28 @trainer.py:63] log_progress: False
[2022-08-11 20:03:28 @trainer.py:64] --------------------------------------------------------------------------------
[2022-08-11 20:03:31 @inpaint_model.py:169] Set batch_predicted to x2.
[2022-08-11 20:03:31 @inpaint_ops.py:201] Use spatial discounting l1 loss.
[2022-08-11 20:03:31 @inpaint_ops.py:201] Use spatial discounting l1 loss.
Traceback (most recent call last):
  File "/home/USERNAME/anaconda3/envs/py37/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: Dimension 0 in both shapes must be equal, but are 1 and 3. Shapes are [1] and [3]. for 'concat_7' (op: 'ConcatV2') with input shapes: [32,256,256,1], [32,256,256,1], [32,256,256,1], [32,256,256,3], [] and with computed input tensors: input[4] = <2>.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "train.py", line 100, in <module>
    log_dir=log_prefix,
  File "/home/USERNAME/Desktop/MyRepo/neuralgym/train/trainer.py", line 41, in __init__
    self._train_op, self._loss = self.train_ops_and_losses()
  File "/home/USERNAME/Desktop/MyRepo/neuralgym/train/trainer.py", line 250, in train_ops_and_losses
    loss = self.context['graph_def'](**graph_def_kwargs)
  File "train.py", line 20, in multigpu_graph_def
    images, config, summary=True, reuse=True)
  File "/home/USERNAME/Desktop/MyRepo/inpaint_model.py", line 197, in build_graph_with_losses
    tf.concat(viz_img, axis=2),
  File "/home/USERNAME/anaconda3/envs/py37/lib/python3.7/site-packages/tensorflow_core/python/util/dispatch.py", line 180, in wrapper
    return target(*args, **kwargs)
  File "/home/USERNAME/anaconda3/envs/py37/lib/python3.7/site-packages/tensorflow_core/python/ops/array_ops.py", line 1420, in concat
    return gen_array_ops.concat_v2(values=values, axis=axis, name=name)
  File "/home/USERNAME/anaconda3/envs/py37/lib/python3.7/site-packages/tensorflow_core/python/ops/gen_array_ops.py", line 1257, in concat_v2
    "ConcatV2", values=values, axis=axis, name=name)
  File "/home/USERNAME/anaconda3/envs/py37/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/USERNAME/anaconda3/envs/py37/lib/python3.7/site-packages/tensorflow_core/python/util/deprecation.py", line 507, in new_func
    return func(*args, **kwargs)
  File "/home/USERNAME/anaconda3/envs/py37/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 3357, in create_op
    attrs, op_def, compute_device)
  File "/home/USERNAME/anaconda3/envs/py37/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 3426, in _create_op_internal
    op_def=op_def)
  File "/home/USERNAME/anaconda3/envs/py37/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 1770, in __init__
    control_input_ops)
  File "/home/USERNAME/anaconda3/envs/py37/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 1610, in _create_c_op
    raise ValueError(str(e))
ValueError: Dimension 0 in both shapes must be equal, but are 1 and 3. Shapes are [1] and [3]. for 'concat_7' (op: 'ConcatV2') with input shapes: [32,256,256,1], [32,256,256,1], [32,256,256,1], [32,256,256,3], [] and with computed input tensors: input[4] = <2>.

The Repository to clone the error is here.

My System:

  • OS: Ubuntu 22.04
  • A single GPU: NVIDIA GeForce GTX 1050 Ti
  • IDE: PyCharm Professional Edition
  • Python: 3.7
  • Tensorflow: 1.15
0 Answers
Related