如果这有一个简单的答案,请道歉!我刚刚进入Keras .

我有50个视频,模型每秒一次将7个测量指标输出到列表中 . 视频有不同的长度,所以我最终有7套7个指标的[num_seconds]组 . 所以形状是(50,num_seconds,7) .

我刚刚发现here对model.fit()的连续调用将逐步训练模型,这很好 - 这意味着我可以为每个单独的视频训练模型并回避这个问题用于训练数据 . 但是,我现在遇到与验证数据相同的问题 - 因为x_test的每个元素都有不同的形状,我收到 "ValueError: Error when checking input: expected input_1 to have 3 dimensions, but got array with shape (50, 1)". 尽管它说x_test是 (50,1) 我可以看到 x_test[0] = (592,7)x_test[1] = (718,7) 等等 . 是否有类似的方法来验证这些锯齿状数组的数据,并设置检查点以保存具有最佳val_loss的模型?

checkpoint = ModelCheckpoint(checkpointFilePath, monitor='val_loss', verbose=1, save_best_only=True, mode='min')
    early_stop = EarlyStopping('val_loss', patience=100)
    callbacks_list = [checkpoint, early_stop]

    for i,_ in enumerate(x_train):
        newx = np.expand_dims(x_train[i],0)
        newy = np.asarray([y_train[i]])

        model.fit(
            newx,
            newy,
            batch_size=50,
            epochs=500,
            verbose=1,
            callbacks=callbacks_list,
            validation_data=(x_test,y_test),
            shuffle=True)