TF.DATA 模块
tf.data模块简介
import tensorflow as tf
dataset = tf.data.Dataset.from_tensor_slices([1,2,3,4,5])
dataset
for ele in dataset:
print(ele)
for ele in dataset:
print(ele.numpy())
dataset = tf.data.Dataset.from_tensor_slices([[1,2,3,],[4,5,6],[7,8,9]])
dataset
for ele in dataset:
print(ele)
for ele in dataset:
print(ele.numpy())
dataset_dic = tf.data.Dataset.from_tensor_slices({
"A":[1,2,3,4],
"B":[5,6,7,8],
"C":[10,11,12,13]
})
dataset_dic
for ele in dataset_dic:
print(ele)
import numpy as np
dataset = tf.data.Dataset.from_tensor_slices(np.array([1,2,3,4,5]))
for ele in dataset:
print(ele.numpy())
dataset = tf.data.Dataset.from_tensor_slices([1,2,3,4,5,6,7,8,9])
for ele in dataset.take(4):
print(ele.numpy())
next(iter(dataset.take(1)))
dataset = dataset.shuffle(9)
dataset = dataset.repeat(count=3)
for ele in dataset:
print(ele.numpy())
dataset = dataset.batch(3)
for ele in dataset:
print(ele.numpy())
dataset = tf.data.Dataset.from_tensor_slices([1,2,3,4,5])
dataset = dataset.shuffle(5)
dataset = dataset.repeat(count=3)
dataset = dataset.batch(3)
dataset = dataset.repeat(count=3)
for ele in dataset:
print(ele.numpy())
dataset = tf.data.Dataset.from_tensor_slices([1,2,3,4,5])
dataset = dataset.map(tf.square)
for ele in dataset:
print(ele.numpy())