0

当我训练我的模型时,它有一个二维输出 - 它是 (none, 1) - 对应于我试图预测的时间序列。但每当我加载保存的模型以进行预测时,它都有一个三维输出 - (none, 40, 1) - 其中 40 对应于拟合 conv1D 网络所需的 n_steps。怎么了?

这是代码:

 df = np.load('Principal.npy')


        # Conv1D
    #model = load_model('ModeloConv1D.h5')
    model = autoencoder_conv1D((2, 20, 17), n_steps=40)

    model.load_weights('weights_35067.hdf5')

    # summarize model.
    model.summary()

        # load dataset
    df = df


        # split into input (X) and output (Y) variables
    X = f.separar_interface(df, n_steps=40)
    # THE X INPUT SHAPE (59891, 17) length and attributes, respectively ##    

    # conv1D input format
    X = X.reshape(X.shape[0], 2, 20, X.shape[2])

    # Make predictions    

    test_predictions = model.predict(X)
    ## test_predictions.shape =  (59891, 40, 1)

    test_predictions = model.predict(X).flatten()
    ##test_predictions.shape = (2395640, 1)


    plt.figure(3) 
    plt.plot(test_predictions)
    plt.legend('Prediction')
    plt.show()

在下面的图中,您可以看到它正在绘制输入格式。 在此处输入图像描述

这是网络架构:

 _________________________________________________________________
    Layer (type)                 Output Shape              Param #   
    =================================================================
    time_distributed_70 (TimeDis (None, 1, 31, 24)         4104      
    _________________________________________________________________
    time_distributed_71 (TimeDis (None, 1, 4, 24)          0         
    _________________________________________________________________
    time_distributed_72 (TimeDis (None, 1, 4, 48)          9264      
    _________________________________________________________________
    time_distributed_73 (TimeDis (None, 1, 1, 48)          0         
    _________________________________________________________________
    time_distributed_74 (TimeDis (None, 1, 1, 64)          12352     
    _________________________________________________________________
    time_distributed_75 (TimeDis (None, 1, 1, 64)          0         
    _________________________________________________________________
    time_distributed_76 (TimeDis (None, 1, 64)             0         
    _________________________________________________________________
    lstm_17 (LSTM)               (None, 100)               66000     
    _________________________________________________________________
    repeat_vector_9 (RepeatVecto (None, 40, 100)           0         
    _________________________________________________________________
    lstm_18 (LSTM)               (None, 40, 100)           80400     
    _________________________________________________________________
    time_distributed_77 (TimeDis (None, 40, 1024)          103424    
    _________________________________________________________________
    dropout_9 (Dropout)          (None, 40, 1024)          0         
    _________________________________________________________________
    dense_18 (Dense)             (None, 40, 1)             1025      
    =================================================================
4

1 回答 1

0

由于我发现了我的错误,并且我认为它可能对其他人有用,我将回答我自己的问题:事实上,网络输出与训练数据集标签具有相同的格式。这意味着,保存的模型正在生成形状为 (None, 40, 1) 的输出,因为它与您(我)为训练输出标签赋予的形状完全相同。

您(即我)欣赏训练时的网络输出和预测时的网络之间的差异,因为您很可能在训练时使用了诸如 train_test_split 之类的方法,该方法使网络输出随机化。因此,您在训练结束时看到的是这个随机批次的生产。

为了纠正您的问题(我的问题),您应该将数据集标签的形状从 (None, 40, 1) 更改为 (None, 1),因为您有时间序列的回归问题。为了在上面的网络中解决这个问题,你最好在密集输出层之前设置一个扁平层。因此,我会得到你正在寻找的结果。

于 2020-04-03T18:37:20.330 回答