为了使用VGG16网络回归任务,我以下列方式将其扩展:延长异常keras VGG16型号:self.assert_input_compatibility(X)抛出
keras.applications.vgg16.VGG16(input_tensor=input_tensor, include_top=False)
x = model.output
x = Flatten()(x)
x = Dense(1024, activation='relu')(x)
x = Dropout(0.5)(x)
x = Dense(512,activation='relu')(x)
x = Dropout(0.5)(x)
x = Dense(256,activation='relu')(x)
x = Dropout(0.5)(x)
x = Dense(1)(x)
model = Model(model.input, x)
这立即引发以下异常:
File "C:\Users\Ralph\Documents\GitHub\CarND-Behavioral-Cloning-P3\model.py", line 116, in <module>
tf.app.run()
File "C:\Users\Ralph\Miniconda3\envs\carnd-term1\lib\site-packages\tensorflow\python\platform\app.py", line 43, in run
sys.exit(main(sys.argv[:1] + flags_passthrough))
File "C:\Users\Ralph\Documents\GitHub\CarND-Behavioral-Cloning-P3\model.py", line 101, in main
model = create_model()
File "C:\Users\Ralph\Documents\GitHub\CarND-Behavioral-Cloning-P3\model.py", line 60, in create_model
x = Dense(1024)(x)
File "C:\Users\Ralph\Miniconda3\envs\carnd-term1\lib\site-packages\keras\engine\topology.py", line 529, in __call__
self.assert_input_compatibility(x)
File "C:\Users\Ralph\Miniconda3\envs\carnd-term1\lib\site-packages\keras\engine\topology.py", line 457, in assert_input_compatibility
if K.ndim(x) < ndim:
File "C:\Users\Ralph\Miniconda3\envs\carnd-term1\lib\site-packages\keras\backend\tensorflow_backend.py", line 396, in ndim
dims = x.get_shape()._dims
AttributeError: 'function' object has no attribute 'get_shape'
Press any key to continue . . .
我是否必须更改体系结构,或者是否存在输入维推理问题?
输入张量的形状是什么? –
原始形状为160,320,3,但在预处理过程中张量调整为224,224,3。你认为它的输入?网络建设发生异常,就在我上面发布的代码片段中。 – user1934212