从Keras调用方法timeseries_dataset_from_array时出错

问题描述

我正在阅读以下教程:

https://www.tensorflow.org/tutorials/structured_data/time_series

有趣的是,当我运行代码时,我得到了错误

AttributeError: module 'tensorflow_core.keras.preprocessing' has no attribute 'timeseries_dataset_from_array'

我尝试显式导入以下方法

from tensorflow.keras.preprocessing import timeseries_dataset_from_array

但随后:

ImportError: cannot import name 'timeseries_dataset_from_array'

我正在使用Spyder 4,Python 3.6.9,TensorFlow 2.1.0和Keras 2.2.4-tf。谁能向我澄清一下?

解决方法

我认为它是在tensorflow 2.3.0中引入的,因此您需要更新tensorflow。 tf.keras.preprocessing.timeseries_dataset_from_array