tensorflow dataset API
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import sklearn
import pandas as pd
import os
import sys
import time
import tensorflow as tf
from tensorflow import keras
#
# (x,y), (x_test, y_test) = keras.datasets.cifar100.load_data()
# y = tf.squeeze(y, axis=1)
# y_test = tf.squeeze(y_test, axis=1)
# print(x.shape, y.shape, x_test.shape, y_test.shape)
# train_db = tf.data.Dataset.from_tensor_slices((x,y))
dataset = tf.data.Dataset.from_tensor_slices(np.arange(5))
dataset=dataset.repeat(3)
for i in dataset:
print(i)
'''
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(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(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)
'''
print("*"*30)
dataset=dataset.shuffle(100).batch(4)
print(type(dataset))
for i in dataset:
print(i)
'''
dataset=dataset.shuffle(100).batch(4)
tf.Tensor([3 0 3 1], shape=(4,), dtype=int32)
tf.Tensor([3 1 2 4], shape=(4,), dtype=int32)
tf.Tensor([0 4 4 2], shape=(4,), dtype=int32)
tf.Tensor([0 1 2], shape=(3,), dtype=int32)
dataset=dataset.batch(4).shuffle(100)
tf.Tensor([3 4 0 1], shape=(4,), dtype=int32)
tf.Tensor([2 3 4], shape=(3,), dtype=int32)
tf.Tensor([0 1 2 3], shape=(4,), dtype=int32)
tf.Tensor([4 0 1 2], shape=(4,), dtype=int32)
'''
x = np.array([[1, 2], [3, 4], [5, 6]])
y = np.array(['cat', 'dog', 'fox'])
dataset3 = tf.data.Dataset.from_tensor_slices((x, y))
print(dataset3)
dataset4 = tf.data.Dataset.from_tensor_slices({"feature": x,
"label": y})
for item in dataset4:
print(item["feature"].numpy(), item["label"].numpy())
'''
[1 2] b'cat'
[3 4] b'dog'
[5 6] b'fox'
'''
a = tf.data.Dataset.range(1, 6) # ==> [ 1, 2, 3, 4, 5 ]
# NOTE: New lines indicate "block" boundaries.
b=a.interleave(lambda x: tf.data.Dataset.from_tensors(x).repeat(6),
cycle_length=2, block_length=4)
for item in b:
print(item.numpy(),end=', ')
'''
1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 3, 3, 4, 4, 5, 5, 5, 5, 5, 5,
'''
參考:interleave
相關文章
- 如何使用TensorFlow中的高階API:Estimator、Experiment和DatasetAPI
- Spark API 全集(1):Spark SQL Dataset & DataFrame APISparkAPISQL
- Tensorflow 1.x 之 dataset.make_initializable_iterator
- 第04講:Flink 常用的 DataSet 和 DataStream APIASTAPI
- TensorFlow Java API 學習筆記JavaAPI筆記
- Tensorflow Python API 翻譯(nn)PythonAPI
- JavaScript datasetJavaScript
- SciTech-BigDataAIML-Tensorflow-Keras是用在Tensorflow的高層APIAIKerasAPI
- 【Dataset】Maple-IDS - Network Security Malicious Traffic Detection Dataset
- Tensorflow Python API 翻譯(array_ops)PythonAPI
- Tensorflow Python API 翻譯(sparse_ops)PythonAPI
- image-classification-dataset
- Tensorflow快餐教程(11) – 不懂機器學習就只調API行不行?機器學習API
- Tensorflow快餐教程(11)-不懂機器學習就只調API行不行?機器學習API
- Flink整合面向使用者的資料流SDKs/API(Flink關於棄用Dataset API的論述)API
- Mmdetection dataset pipline
- 淺談DataSet 的用法
- Pytorch Dataset入門PyTorch
- Spark2 Dataset聚合操作Spark
- asp.net---Dataset的用法ASP.NET
- DataSet的幾個基本操作
- DataAdapter & DataSet 使用小結APT
- SqlDataAdapter DataSet DataTable 詳解SQLLDAAPT
- [譯]標準化Keras:TensorFlow 2.0中的高階API指南KerasAPI
- 谷歌開源TensorFlow Object Detection API物體識別系統谷歌ObjectAPI
- Spark SQL學習——DataFrame和DataSetSparkSQL
- flink batch dataset 的基本操作BAT
- RDD、DataFrame和DataSet的區別
- XML與DataSet的相互轉換XML
- Spark Streaming之dataset例項Spark
- C# DataSet效能最佳實踐C#
- MLE 5217 : Take-Home Dataset Classification
- 05-快速理解SparkSQL的DataSetSparkSQL
- Windows10 使用 Tensorflow Object_detection API 訓練自己的資料WindowsObjectAPI
- dataset、setAttribute()和getAttribute() 區別
- org.dbunit.dataset.NoSuchTableException: t_groupException
- 離線資料處理-DataSet物件物件
- DataAdapter & DataSet 使用小結_轉摘APT