我只是在按照《Hands on Machine Learning with scikit-learn and tensorflow》这本书中的代码示例进行操作。
import tensorflow as tf
X = tf.range(10)
dataset = tf.data.Dataset.from_tensor_slices(X)
根据书中的描述,变量’dataset’的类型应该是’TensorSliceDataset shapes:(), types: tf.int32’,但我得到的却是’DatasetV1Adapter shapes: (), types: tf.int32′
回答:
根据他们的文档,如果您使用的是 TensorFlow 2.0(或更低版本),它不支持 TensorSliceDataset,会返回 DatasetV1Adapterhttps://www.tensorflow.org/versions/r2.0/api_docs/python/tf/raw_ops
您需要使用 TensorFlow 2.1.x 及以上版本