тензор потока ValueError: входной тензор должен иметь ранг в CycleGAN - PullRequest
0 голосов
/ 15 марта 2020

входное изображение: ширина = 32px, высота = 48px, канал = 3

, и я предварительно обработал изображения этим кодом.

def random_crop(image):
  cropped_image = tf.image.random_crop(
      image, size=[IMG_HEIGHT, IMG_WIDTH, 3])
  return cropped_image

def normalize(image):
  image = tf.cast(image, tf.float32)
  image = (image / 127.5) - 1
  return image

def random_jitter(image):
  # resizing to 286 x 286 x 3
  #image = tf.image.resize(image, [286, 286], method=tf.image.ResizeMethod.NEAREST_NEIGHBOR)
  image = tf.image.resize(image, [48, 32], method=tf.image.ResizeMethod.NEAREST_NEIGHBOR)

  # randomly cropping to 256 x 256 x 3
  image = random_crop(image)

  # random mirroring
  image = tf.image.random_flip_left_right(image)

  return image

def preprocess_image_train(image):
  image = random_jitter(image)
  image = normalize(image)
  return image

и другие train & Нейронная сеть код совпадает с https://www.tensorflow.org/tutorials/generative/cyclegan

Но когда я начал тренироваться .... произошла ошибка ....

WARNING:tensorflow:Model was constructed with shape Tensor("input_19:0", shape=(None, None, None, 3), dtype=float32) for input (None, None, None, 3), but it was re-called on a Tensor with incompatible shape (48, 32, 3).
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/tensor_shape.py in merge_with(self, other)
    922       try:
--> 923         self.assert_same_rank(other)
    924         new_dims = []

15 frames
ValueError: Shapes (48, 32, 3) and (None, None, None, None) must have the same rank

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
ValueError: Shapes (48, 32, 3) and (None, None, None, None) are not compatible

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
ValueError: Shape (48, 32, 3) must have rank 4

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/ops/nn_ops.py in __init__(self, input_shape, filter_shape, padding, strides, dilation_rate, name, data_format)
   1066     except ValueError:
   1067       raise ValueError(
-> 1068           "input tensor must have rank %d" % (num_spatial_dims + 2))
   1069 
   1070     try:

ValueError: input tensor must have rank 

Как я могу решить эту проблему?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...