简体   繁体   English

在VGG19 Keras模型中使用TimeDistributed时出错

[英]Error while using TimeDistributed with VGG19 Keras model

While using pre-trained VGG19 with with TimeDistributed in Keras, I have the following Error : 在Keras中将经过训练的VGG19与TimeDistributed一起使用时,出现以下错误:

TypeError: can only concatenate tuple (not "list") to tuple

This is in windows, Keras, python3.6 这是在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

I am expecting the trained VGG19 model will be loaded and TimeDistributed wrapper will use the trained model and make it works in Video. 我期望将加载经过训练的VGG19模型,并且TimeDistributed包装器将使用经过训练的模型并使它在视频中工作。

The error displayed when executing this line on code: 在代码上执行此行时显示的错误:

h2 = layers.wrappers.TimeDistributed(vggmodel)(img)

i re-write it that way and it works fine 我用这种方式重写它,并且效果很好

def build_vgg(self): def build_vgg():

    video  = 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
    vgg.outputs = [vgg.layers[i].output for i in self.vgg_layers]

    # Create model and compile, 


    vggmodel = Model(inputs=vgg.inputs, outputs=vgg.outputs)
    #vggmodel.trainable = False
    h2 = []
    for out in vggmodel.output:
        h2.append(layers.wrappers.TimeDistributed(Model(vggmodel.input,out))(video))

    model = Model(inputs=video, outputs=h2)
    model.trainable = False
    model.compile(loss='mse', optimizer='adam')

    return model

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM