tensorflow dataset 用法 from_tensor_slices dataset.repeat dataset.batch dataset.shuffle
列表和numpy数组是不可以训练的,要转换成dataset才能用model.fit函数来训练
import numpy as np
import tensorflow as tf
input_data = np.arange(16)
input_data
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])
dataset就是tensor组成的数组
dataset = tf.data.Dataset.from_tensor_slices(input_data # numpy数组或者list列表
) # numpy数组转tf.Tensor数组(即:TensorSliceDataset)
dataset
<TensorSliceDataset shapes: (), types: tf.int32>
for data in 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)
dataset = dataset.repeat(2) # 把dataset重复2次
dataset
<RepeatDataset shapes: (), types: tf.int32>
for data in 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)
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)
dataset = dataset.batch(4) # 把4个tensor发在一起组成一个tensor
dataset
<BatchDataset shapes: (None,), types: tf.int32>
for data in dataset:print(data)
tf.Tensor([0 1 2 3], shape=(4,), dtype=int32)
tf.Tensor([4 5 6 7], shape=(4,), dtype=int32)
tf.Tensor([ 8 9 10 11], shape=(4,), dtype=int32)
tf.Tensor([12 13 14 15], shape=(4,), dtype=int32)
tf.Tensor([0 1 2 3], shape=(4,), dtype=int32)
tf.Tensor([4 5 6 7], shape=(4,), dtype=int32)
tf.Tensor([ 8 9 10 11], shape=(4,), dtype=int32)
tf.Tensor([12 13 14 15], shape=(4,), dtype=int32)
dataset = dataset.shuffle(buffer_size=10) # 把dataset打乱顺序
dataset
<ShuffleDataset shapes: (None,), types: tf.int32>
for data in dataset:print(data)
tf.Tensor([12 13 14 15], shape=(4,), dtype=int32)
tf.Tensor([0 1 2 3], shape=(4,), dtype=int32)
tf.Tensor([ 8 9 10 11], shape=(4,), dtype=int32)
tf.Tensor([4 5 6 7], shape=(4,), dtype=int32)
tf.Tensor([0 1 2 3], shape=(4,), dtype=int32)
tf.Tensor([12 13 14 15], shape=(4,), dtype=int32)
tf.Tensor([ 8 9 10 11], shape=(4,), dtype=int32)
tf.Tensor([4 5 6 7], shape=(4,), dtype=int32)
tensorflow dataset 用法 from_tensor_slices dataset.repeat dataset.batch dataset.shuffle相关推荐
- tensorflow 读取图片 Dataset用法
目录 bmp Dataset.from_tensor_slices: Dataset简单用法 png这个测试ok: 读图片,resize,预测 构建dateset png格式可以训练: bmp Dat ...
- tf.data.Dataset 用法
tf.data.DatasetAPI支持写入的描述性和高效的输入管线.Dataset用法遵循一个常见模式: 从输入数据创建源数据集. 应用数据集转换来预处理数据. 迭代数据集并处理元素. 迭代以流式方 ...
- DataSet用法详细
DataSet用法详细 一.特点介绍 1.处理脱机数据,在多层应用程序中很有用. 2.可以在任何时候查看DataSet中任意行的内容,允许修改查询结果的方法. 3.处理分级数据 4.缓存更改 5.XM ...
- DataSet用法1
DataSet是表和列结构在内存中的表示方式,DataSet支持多表.表间关系.数据约束等,和关系数据库的模型基本一致.(本质上是微型的数据库.包含一组DataTable对象和DataTable之间的 ...
- ASP.NETnbsp;nbsp;DATASET用法
: c#.net 使用方法 1.创建DataSet对象 DataSet ds = new DataSet(); DataSet ds = new DataSet("DataSetName&q ...
- tensorflow2数据读取P3: tf.data.Dataset.from_generator通过preprocessing.image.ImageDataGenerator构造Dataset
tf.data.Dataset.from_generator通过preprocessing.image.ImageDataGenerator构造Dataset 虽然自己定义生成器就可以构建datase ...
- TensorFlow实现条件批归一化(Conditional Batch Normalization)
TensorFlow实现条件批归一化(Conditional Batch Normalization) 条件批归一化(Conditional Batch Normalization) TensorFl ...
- tensorflow学习笔记:tf.data.Dataset,from_tensor_slices(),shuffle(),batch()的用法
tf.data.Dataset.from_tensor_slices: 它的作用是切分传入Tensor的第一个维度,生成相应的dataset. 例1: dataset = tf.data.Datase ...
- tensorflow dataset.shuffle dataset.batch dataset.repeat 理解 注意点
batch很好理解,就是batch size.注意在一个epoch中最后一个batch大小可能小于等于batch size dataset.repeat就是俗称epoch,但在tf中与dataset ...
- 并不简单的翻页时钟(一):样式篇(Flex布局、line-height、data-set用法、css before after伪元素)
目录 并不简单的翻页时钟 我以为的翻页时钟 实际上的翻页时钟 关键的知识点 效果展示 代码解析 HTML CSS 详解CSS 1.display:flex 元素居中 2.:before .:after ...
最新文章
- ES6系列--对象扩展
- “中国式招标”的一些趣闻
- python(numpy,pandas9)——pandas 导入导出数据
- Geography爱好者 QGIS WGS84转其它坐标系并计算坐标
- 跟我学 Java 8 新特性之 Stream 流(七)流与迭代器,流系列大结局
- 客座编辑:吴东亚(1972-),女,中国电子技术标准化研究院信息技术研究中心高级工程师、副主任,国家OID注册中心副主任。...
- 玩转Docker镜像
- DevOps:让开发和运维告别“相爱相杀”
- 用matlab做bp神经网络预测,神经网络预测matlab代码
- install par
- windows server 2003序列号
- 优秀logo设计解析_国外30个优秀的logo的设计思维分析
- Python爬虫实战(一) QQ音乐评论爬取及可视化分析
- redis.conf文件下载与配置
- 【数据结构】线性表之单向链表的八大基操
- helm模板开发-流程控制、作用域、循环、变量(三)
- 富文本及编辑器的跨平台方案
- Java 实现图片转换为ICO以及多种格式图片之间转换
- 规约——前置条件和后置条件
- 判断字符串是否是对称字符串