使用时间分布式包装器使用keras约束cnn和LSTM时的问题

时间:2018-07-26 23:05:04

标签: tensorflow keras lstm

我想使用时间贡献的包装器来组合cnn和lstm来进行图像分类。并在每个时间步进行预测。

    model.add(TimeDistributed(Convolution2D(32, 3, 3,
                                border_mode='valid'),batch_input_shape= 
    (None,10,227,227,1)))

    model.add(Activation('relu'))
    model.add(TimeDistributed(MaxPooling2D(pool_size=(2, 2))))
    model.add(Dropout(0.25))

    model.add(TimeDistributed(Convolution2D(32, 3, 3, border_mode='valid')))

    model.add(Activation('relu'))
    model.add(TimeDistributed(MaxPooling2D(pool_size=(2, 2))))
    model.add(Dropout(0.25))

    model.add(TimeDistributed(Convolution2D(32, 3, 3, border_mode='valid')))

    model.add(Activation('relu'))
    model.add(TimeDistributed(MaxPooling2D(pool_size=(2, 2))))
    model.add(Dropout(0.25))

    model.add(TimeDistributed(Flatten()))
    model.add(TimeDistributed(Dense(256,activation='relu')))


    model.add(LSTM(output_dim=256,return_sequences=True))


    model.add(Dense(10,activation='softmax'))
    #print(model.output_shape)

    sgd = SGD(lr = 0.1, decay = 1e-5, momentum=0.9, nesterov=True)
    model.compile(loss='categorical_crossentropy',
      optimizer=sgd,
      metrics=['accuracy'])
    model.summary()

但是在输入数据时出现了这个错误

     File "lstm.py", line 187, in <module>
     model.fit(a,b, nb_epoch=20, batch_size=100)
     File "D:\anaconda\envs\702\lib\site-packages\keras\engine\training.py", line 955, in fit
     batch_size=batch_size)
     File "D:\anaconda\envs\702\lib\site-packages\keras\engine\training.py", line 792, in _standardize_user_data
     exception_prefix='target')
     File "D:\anaconda\envs\702\lib\site-packages\keras\engine\training_utils.py", line 126, in standardize_input_data
    'with shape ' + str(data_shape))
     ValueError: Error when checking target: expected dense_2 to have 3 dimensions, but got array with shape (100, 10)

0 个答案:

没有答案