【发布时间】:2019-11-09 08:04:05
【问题描述】:
在 Keras 中使用带有 TimeDistributed 的预训练 VGG19 时,出现以下错误:
TypeError: can only concatenate tuple (not "list") to tuple
这是在 windows、Keras、python3.6 中
def build_vgg(self):
img = Input(shape=(self.n_frames, self.img_rows, self.img_cols, 3))
# Get the vgg network from Keras applications
vgg = VGG19(weights="imagenet", include_top=False, input_shape=(self.img_rows, self.img_cols, 3))
# Output the first three pooling layers
outputs = [vgg.layers[i].output for i in self.vgg_layers]
vgg.outputs = outputs
# Create model and compile,
vggmodel = Model(inputs=vgg.inputs, outputs=outputs)
vggmodel.trainable = False
h2 = layers.wrappers.TimeDistributed(vggmodel)(img)
model = Model(inputs=img,outputs=h2)
model.compile(loss='mse', optimizer='adam')
return model
我预计将加载经过训练的 VGG19 模型,并且 TimeDistributed 包装器将使用经过训练的模型并使其在视频中工作。
在代码上执行此行时显示的错误:
h2 = layers.wrappers.TimeDistributed(vggmodel)(img)
【问题讨论】:
-
这里的问题是:在 Keras 的 Wrapper 类中,在计算输出形状时,此行返回 (child_output_shape[0], timesteps) + child_output_shape[1:],其中 ipdb> child_output_shape[1 :] [(None, 128, 128, 128), (None, 128, 128, 256)] ipdb> (child_output_shape[0], timesteps) ((None, 256, 256, 64), 4)