tf.data.Dataset.from_tensor_slices 的用法
将python列表和numpy数组转换成tensorflow的dataset 只有dataset才能被model.fit函数训练
import tensorflow as tf
import numpy as np
numpy_data = np.arange(16) # 创建numpy数组
numpy_data
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])
numpy_dataset = tf.data.Dataset.from_tensor_slices(numpy_data # numpy数组转tf.Tensor数组(即:TensorSliceDataset)
)
numpy_dataset
<TensorSliceDataset shapes: (), types: tf.int32>
for data in numpy_dataset:print(data)
tf.Tensor(0, shape=(), dtype=int32)
tf.Tensor(1, shape=(), dtype=int32)
tf.Tensor(2, shape=(), dtype=int32)
tf.Tensor(3, shape=(), dtype=int32)
tf.Tensor(4, shape=(), dtype=int32)
tf.Tensor(5, shape=(), dtype=int32)
tf.Tensor(6, shape=(), dtype=int32)
tf.Tensor(7, shape=(), dtype=int32)
tf.Tensor(8, shape=(), dtype=int32)
tf.Tensor(9, shape=(), dtype=int32)
tf.Tensor(10, shape=(), dtype=int32)
tf.Tensor(11, shape=(), dtype=int32)
tf.Tensor(12, shape=(), dtype=int32)
tf.Tensor(13, shape=(), dtype=int32)
tf.Tensor(14, shape=(), dtype=int32)
tf.Tensor(15, shape=(), dtype=int32)
list_data = list(range(10)) # 创建列表
list_data
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
list_data = tf.data.Dataset.from_tensor_slices(list_data # list转tf.Tensor数组(即:TensorSliceDataset)
)
list_data
<TensorSliceDataset shapes: (), types: tf.int32>
for data in list_data:print(data)
tf.Tensor(0, shape=(), dtype=int32)
tf.Tensor(1, shape=(), dtype=int32)
tf.Tensor(2, shape=(), dtype=int32)
tf.Tensor(3, shape=(), dtype=int32)
tf.Tensor(4, shape=(), dtype=int32)
tf.Tensor(5, shape=(), dtype=int32)
tf.Tensor(6, shape=(), dtype=int32)
tf.Tensor(7, shape=(), dtype=int32)
tf.Tensor(8, shape=(), dtype=int32)
tf.Tensor(9, shape=(), dtype=int32)
tf.data.Dataset.from_tensor_slices 的用法相关推荐
- tensorflow tf.data.Dataset.from_tensor_slices() (创建一个“数据集”,其元素是给定张量的切片)
from tensorflow\python\data\ops\dataset_ops.py @staticmethoddef from_tensor_slices(tensors):"&q ...
- tf.data.Dataset.from_tensor_slices() 详解
函数原型: tf.data.Dataset.from_tensor_slices(tensors, name=None ) 官网地址:https://www.tensorflow.org/api_do ...
- 记录 之 tensorflow函数:tf.data.Dataset.from_tensor_slices
tf.data.Dataset.from_tensor_slices(),是常见的数据处理函数,它的作用是将给定的元组(turple).列表(list).张量(tensor)等特征进行特征切片.切片的 ...
- tensorflow基础:tf.data.Dataset.from_tensor_slices() 与 tf.data.Dataset.from_generator()的异同
tf.data.Dataset.from_tensor_slices(tensor): -->将tensor沿其第一个维度切片,返回一个含有N个样本的数据集(假设tensor的第一个维度为N). ...
- tensorflow基础:tf.data.Dataset.from_tensor_slices()
tf.data.Dataset.from_tensor_slices() 语义解释:from_tensor_slices,从张量的切片读取数据. 工作原理:将输入的张量的第一个维度看做样本的个数,沿其 ...
- tensorflow学习笔记:tf.data.Dataset,from_tensor_slices(),shuffle(),batch()的用法
tf.data.Dataset.from_tensor_slices: 它的作用是切分传入Tensor的第一个维度,生成相应的dataset. 例1: dataset = tf.data.Datase ...
- tf.data.Dataset 用法
tf.data.DatasetAPI支持写入的描述性和高效的输入管线.Dataset用法遵循一个常见模式: 从输入数据创建源数据集. 应用数据集转换来预处理数据. 迭代数据集并处理元素. 迭代以流式方 ...
- TensorFlow数据读取机制:文件队列 tf.train.slice_input_producer和 tf.data.Dataset机制
TensorFlow数据读取机制:文件队列 tf.train.slice_input_producer和tf.data.Dataset机制 之前写了一篇博客,关于<Tensorflow生成自己的 ...
- tfds.load()和tf.data.Dataset的简介
tfds.load()和tf.data.Dataset的简介 tfds.load()有以下参数 tfds.load(name, split=None, data_dir=None, batch_siz ...
最新文章
- hihoCoder-1830 2018亚洲区预选赛北京赛站网络赛 C.Cheat 模拟
- es6-Set与Map
- POJ 1611 -The Suspects (并查集)
- Ubuntu系统如何安装软件
- C# 位域[flags]
- 1张手稿图讲明白 Kubernetes 是怎么运行的
- 面积积分_袁颖妍:用定理积分求平面区域面积(有代表性的9个例题)
- 管理刀片服务器的KVM切换器
- python实现一种相似图片搜索算法
- 微软android桌面壁纸,微软桌面(com.microsoft.launcher) - 6.210402.0.960830 - 应用 - 酷安
- PAT难题精选题汇总,代码保存下来以供自己学习
- 自动读取短信中心号码
- qt控制程序打开记事本_基于QT记事本应用程序开发.doc
- 张量网络系列(一 从张量到张量网络)
- mfc: 获取打印机列表
- 啧啧啧。。。加壳失败
- 求两个不超过 200 位的非负整数的和(逐句解释)
- 【转】float与double的范围和精度
- 孔明锁(1)——中国馆
- DirectSound回放