【发布时间】:2020-03-24 19:40:19
【问题描述】:
我正在尝试将密集层附加到 vgg19 网络,但它给了我以下错误。谁能帮我解决这个问题?
import tensorflow
from tensorflow.keras.applications.vgg19 import VGG19
model = VGG19()
x = tensorflow.keras.layers.Dense(10,
activation="relu",name="",trainable=True)(model.layers[-1])
model = tensorflow.keras.Model(inputs = model.layers[0], outputs = x)
Python 3.7.0(默认,2018 年 6 月 28 日,07:39:16)键入“版权”, “credits”或“license”了解更多信息。
IPython 7.8.0 -- 增强的交互式 Python。
runfile('/Users/sadegh/Dropbox/Moosavi Khorzooghi-04/test', wdir='/Users/sadegh/Dropbox/Moosavi Khorzooghi-04') 2019-11-29 01:51:22.516366:我 tensorflow/core/platform/cpu_feature_guard.cc:142] 您的 CPU 支持此 TensorFlow 二进制文件不支持的指令 编译使用:AVX2 FMA 2019-11-29 01:51:22.526913: I tensorflow/compiler/xla/service/service.cc:168] XLA 服务 0x7fc84c7a2700 在平台主机上执行计算。设备: 2019-11-29 01:51:22.526926: 我 tensorflow/compiler/xla/service/service.cc:175] StreamExecutor 设备(0):主机,默认版本回溯(最近一次调用最后一次):
文件“”,第 1 行,在 runfile('/Users/sadegh/Dropbox/Moosavi Khorzooghi-04/test', wdir='/Users/sadegh/Dropbox/Moosavi Khorzooghi-04')
文件 "/opt/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", 第 827 行,在运行文件中 execfile(文件名,命名空间)
文件 "/opt/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", 第 110 行,在 execfile 中 exec(编译(f.read(),文件名,'exec'),命名空间)
文件“/Users/sadegh/Dropbox/Moosavi Khorzooghi-04/test”,第 11 行,在 x = tensorflow.keras.layers.Dense(10, activation="relu",name="",trainable=True)(model.layers[-1])
文件 “/opt/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/base_layer.py”, 第 887 行,在 调用 self._maybe_build(输入)
文件 “/opt/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/base_layer.py”, 第 2122 行,在 _maybe_build self.input_spec,输入,self.name)
文件 “/opt/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/input_spec.py”, 第 163 行,在 assert_input_compatibility 如果 x.shape.ndims 为无:
AttributeError: 'Dense' 对象没有属性 'shape'
【问题讨论】:
标签: python tensorflow keras