【问题标题】:How to use trained Keras CNN model for prediction with new unlabeled data如何使用训练有素的 Keras CNN 模型对新的未标记数据进行预测
【发布时间】:2021-11-09 00:50:00
【问题描述】:

Google colab 上的温度预测时间序列教程很好地介绍了如何设置各种模型的训练、验证和测试性能。如何使用这个训练有素的 multi_conv_model 使用新的未标记数据运行温度预测。专门寻找如何仅使用输入数据框调用 Keras 预测函数。

https://colab.research.google.com/github/tensorflow/docs/blob/master/site/en/tutorials/structured_data/time_series.ipynb

CONV_WIDTH = 3
multi_conv_model = tf.keras.Sequential([
    # Shape [batch, time, features] => [batch, CONV_WIDTH, features]
    tf.keras.layers.Lambda(lambda x: x[:, -CONV_WIDTH:, :]),
    # Shape => [batch, 1, conv_units]
    tf.keras.layers.Conv1D(256, activation='relu', kernel_size=(CONV_WIDTH)),
    # Shape => [batch, 1,  out_steps*features]
    tf.keras.layers.Dense(OUT_STEPS*num_features,
                          kernel_initializer=tf.initializers.zeros()),
    # Shape => [batch, out_steps, features]
    tf.keras.layers.Reshape([OUT_STEPS, num_features])
])

history = compile_and_fit(multi_conv_model, multi_window)

IPython.display.clear_output()

multi_val_performance['Conv'] = multi_conv_model.evaluate(multi_window.val)
multi_performance['Conv'] = multi_conv_model.evaluate(multi_window.test, verbose=0)
multi_window.plot(multi_conv_model)

这是我尝试过的,但它没有给出有意义的 5 期预测:

predict_inputs_df = test_df[:20] # or some other input data points
predict_inputs_df =  (predict_inputs_df - train_mean) / train_std
predictions = conv_model(tf.stack([np.array(predict_inputs_df)]))
predictions

【问题讨论】:

    标签: tensorflow keras deep-learning time-series conv-neural-network


    【解决方案1】:

    你需要做conv_model.evaluate(tf.stack([np.array(predict_inputs_df)]))

    这应该会给你一些结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-04
      • 1970-01-01
      • 2017-03-13
      • 2018-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多