keras转tf.keras中VGG19 input_shape

使用tf.keras时出现报错。从keras改到tf中出现
结论:shape过大,不符合输入要求

更新:nice!之后试试这个

Traceback (most recent call last):
  File "srgan.py", line 406, in <module>
    gan = SRGAN()
  File "srgan.py", line 63, in __init__
    self.vgg = self.build_vgg()
  File "srgan.py", line 150, in build_vgg
    img_features = vgg(img)
  File "C:\python3_7\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 922, in __call__
    outputs = call_fn(cast_inputs, *args, **kwargs)
  File "C:\python3_7\lib\site-packages\tensorflow\python\keras\engine\network.py", line 719, in call
    convert_kwargs_to_constants=base_layer_utils.call_context().saving)
  File "C:\python3_7\lib\site-packages\tensorflow\python\keras\engine\network.py", line 888, in _run_internal_graph
    output_tensors = layer(computed_tensors, **kwargs)
  File "C:\python3_7\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 886, in __call__
    self.name)
  File "C:\python3_7\lib\site-packages\tensorflow\python\keras\engine\input_spec.py", line 216, in assert_input_compatibility
    ' but received input with shape ' + str(shape))
ValueError: Input 0 of layer fc1 is incompatible with the layer: expected axis -1 of input shape to have value 25088 but received input with shape [None, 32768]

检查了img的shape(相关blog),两种引用shape一致。

检查两种应用api是否有区别:

tensorflow内input_shape[224.224.3]
224.224.3
keras内input_shape:299*299
在这里插入图片描述
代码测试img的shape为 256,256,3
在这里插入图片描述
warning也显示

WARNING:tensorflow:Model was constructed with shape (None, 224, 224, 3) for input Tensor("input_1:0", shape=(None, 224, 224, 3), dtype=float32), but it was called on an input with incompatible shape (None, 256, 256, 3).

改小shape

  • 新错误,改低了tensorflow版本为1后未出现
X_test.shape:(None, 224, 224, 3)
X_test[num].shape:(224, 224, 3)
Traceback (most recent call last):
  File "srgan.py", line 404, in <module>
    gan = SRGAN()
  File "srgan.py", line 63, in __init__
    self.vgg = self.build_vgg()
  File "srgan.py", line 148, in build_vgg
    img_features = vgg(img)
  File "C:\python3_7\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 922, in __call__
    outputs = call_fn(cast_inputs, *args, **kwargs)
  File "C:\python3_7\lib\site-packages\tensorflow\python\keras\engine\network.py", line 719, in call
    convert_kwargs_to_constants=base_layer_utils.call_context().saving)
  File "C:\python3_7\lib\site-packages\tensorflow\python\keras\engine\network.py", line 900, in _run_internal_graph
    tensor = tensor_dict[str(id(x))].pop()
IndexError: pop from empty list

版权声明:本文为qq_42957563原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。