Ошибка размера при изменении input_shape в u _net tensorflow - PullRequest
0 голосов
/ 08 мая 2020

Когда я изменил input_shape модели u _net в учебных пособиях по тензорному потоку (с (128,128,3) на (150,150,3). Это показывает, что слой concat имеет несовместимые размеры, тогда как input_shape не должен влиять на промежуточные Казалось, все работает нормально, когда я изменил форму обратно на (128,128,3)

  base_model = tf.keras.applications.MobileNetV2(input_shape=[150,150,3], include_top=False)

# Use the activations of these layers
layer_names = [
    'block_1_expand_relu',   # 64x64
    'block_3_expand_relu',   # 32x32
    'block_6_expand_relu',   # 16x16
    'block_13_expand_relu',  # 8x8
    'block_16_project',      # 4x4
]
layers = [base_model.get_layer(name).output for name in layer_names]

# Create the feature extraction model
down_stack = tf.keras.Model(inputs=base_model.input, outputs=layers)

down_stack.trainable = False


up_stack = [
    pix2pix.upsample(512, 3),  # 4x4 -> 8x8
    pix2pix.upsample(256, 3),  # 8x8 -> 16x16
    pix2pix.upsample(128, 3),  # 16x16 -> 32x32
    pix2pix.upsample(64, 3),   # 32x32 -> 64x64
]

def unet_model(output_channels):
  inputs = tf.keras.layers.Input(shape=[150,150,3])
  x = inputs

  # Downsampling through the model
  skips = down_stack(x)
  x = skips[-1]
  skips = reversed(skips[:-1])

  # Upsampling and establishing the skip connections
  for up, skip in zip(up_stack, skips):
    x = up(x)
    concat = tf.keras.layers.Concatenate()
    x = concat([x, skip])

  # This is the last layer of the model
  last = tf.keras.layers.Conv2DTranspose(
      output_channels, 3, strides=2,
      padding='same')  #64x64 -> 128x128

  x = last(x)

  return tf.keras.Model(inputs=inputs, outputs=x)

OUTPUT -

ValueError Traceback (последний вызов последний)

in () ----> 1 модель = u_net_model (3)

4 кадра

/ usr / local / lib / python3 .6 / dist-packages / tensorflow / python / keras / Layers / merge.py в build (self, input_shape) 517 shape [axis] для shape в shape_set, если shape [axis] не None) 518 if len (unique_dims)> 1: -> 519 поднять ValueError (err_msg) 520 521 def _merge_function (self, inputs):

ValueError: Для слоя Concatenate требуются входные данные с совпадающими формами, за исключением оси concat. Получены входные формы: [(Нет, 20, 20, 256), (Нет, 19, 19, 192)]

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