W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
繼承自: Dataset
定義在:tensorflow/contrib/data/python/ops/dataset_ops.py
使用 TensorFlow 函數(shù):tf.contrib.data.TFRecordDataset 表示包含一個或多個 TFRecord 文件的記錄的數(shù)據(jù)集.
__init__(
filenames,
compression_type=None
)
創(chuàng)建一個 TFRecordDataset.
batch(batch_size)
將此數(shù)據(jù)集的連續(xù)元素組合成批.
返回一個 Dataset.
cache(filename='')
緩存這個數(shù)據(jù)集中的元素.
返回一個 Dataset.
concatenate(dataset)
通過將給定的數(shù)據(jù)集與此數(shù)據(jù)集連接來創(chuàng)建數(shù)據(jù)集.
# NOTE: The following examples use `{ ... }` to represent the
# contents of a dataset.
a = { 1, 2, 3 }
b = { 4, 5, 6, 7 }
# Input dataset and dataset to be concatenated should have same
# nested structures and output types.
# c = { (8, 9), (10, 11), (12, 13) }
# d = { 14.0, 15.0, 16.0 }
# a.concatenate(c) and a.concatenate(d) would result in error.
a.concatenate(b) == { 1, 2, 3, 4, 5, 6, 7 }
該操作件返回一個 Dataset.
dense_to_sparse_batch ( batch_size , row_shape )
將該數(shù)據(jù)集的不規(guī)則元素批量放入到 tf . sparsetenUNK 中.
像 Dataset.padded_batch() 一樣,此方法將此數(shù)據(jù)集的多個連續(xù)元素 (可能具有不同的形狀) 合并到單個元素中.所得到的元素具有三個組件(indices,values 和dense_shape),它們中包含一個 tf.SparseTensor 表示相同數(shù)據(jù)的組件.row_shape 表示生成的 tf.SparseTensor 中每行所得的稠密形狀,其中有效的批量大小被前置.例如:
# 注意: 以下示例使用 `{ ... }` 來表示數(shù)據(jù)集的內(nèi)容
a = { ['a', 'b', 'c'], ['a', 'b'], ['a', 'b', 'c', 'd'] }
a.dense_to_sparse_batch(batch_size=2, row_shape=[6]) == {
([[0, 0], [0, 1], [0, 2], [1, 0], [1, 1]], # indices
['a', 'b', 'c', 'a', 'b'], # values
[2, 6]), # dense_shape
([[2, 0], [2, 1], [2, 2], [2, 3]],
['a', 'b', 'c', 'd'],
[1, 6])
}
返回一個 Dataset.
enumerate(start=0)
枚舉此數(shù)據(jù)集的元素.類似于 python 的枚舉.
例如:
# 注意:以下示例使用 `{ ... }` 來表示數(shù)據(jù)集的內(nèi)容
a = { 1, 2, 3 }
b = { (7, 8), (9, 10), (11, 12) }
# The nested structure of the `datasets` argument determines the
# structure of elements in the resulting dataset.
a.enumerate(start=5) == { (5, 1), (6, 2), (7, 3) }
b.enumerate() == { (0, (7, 8)), (1, (9, 10)), (2, (11, 12)) }
返回一個 Dataset.
filter(predicate)
根據(jù) predicate 過濾此數(shù)據(jù)集.
返回一個 Dataset.
flat_map(map_func)
將 map_func 映射到這個數(shù)據(jù)集,并拼合結(jié)果.
返回一個 Dataset.
from_sparse_tensor_slices(sparse_tensor)
在此數(shù)據(jù)集中逐行分割每個秩為 N 的 tf.SparseTensor.
秩為(N-1)的稀疏張量的數(shù)據(jù)集.
from_tensor_slices(tensors)
創(chuàng)建一個數(shù)據(jù)集,其元素是給定張量的 slices.
返回一個 Dataset.
from_tensors(tensors)
創(chuàng)建一個包含給定張量的單個元素的數(shù)據(jù)集.
返回一個 Dataset.
group_by_window(
key_func,
reduce_func,
window_size
)
對此數(shù)據(jù)集執(zhí)行窗口化的 “group-by” 操作.
該方法將該數(shù)據(jù)集中的每個連續(xù)元素映射到一個使用 key_func 的 key,并通過該 key 對元素進行分組.然后將 reduce_func 最多應(yīng)用于與同一 key 匹配的大多數(shù) window_size 元素.每個 key 將包含 window_size 元素,除了最后的窗口,最后的窗口可能較小.
返回一個 Dataset.
ignore_errors()
從此項創(chuàng)建數(shù)據(jù)集,并默認(rèn)忽略任何錯誤.
使用此轉(zhuǎn)換可以生成包含與輸入相同元素的數(shù)據(jù)集,但會默認(rèn)刪除導(dǎo)致錯誤的任何元素.例如:
dataset = tf.contrib.data.Dataset.from_tensor_slices([1., 2., 0., 4.])
# Computing `tf.check_numerics(1. / 0.)` will raise an InvalidArgumentError.
dataset = dataset.map(lambda x: tf.check_numerics(1. / x, "error"))
# Using `ignore_errors()` will drop the element that causes an error.
dataset = dataset.ignore_errors() # ==> { 1., 0.5, 0.2 }
返回一個 Dataset.
interleave(
map_func,
cycle_length,
block_length=1
)
將 map_func 映射到這個數(shù)據(jù)集,并插入結(jié)果.
例如,您可以 Dataset.interleave() 同時處理多個輸入文件:
# 同時處理4個文件,并從每個文件的16個記錄塊中插入結(jié)果.
filenames = ["/var/data/file1.txt", "/var/data/file2.txt", ..."]
dataset = (Dataset.from_tensor_slices(filenames)
.interleave(
lambda x: TextLineDataset(x).map(parse_fn, num_threads=1),
cycle_length=4, block_length=16))
cycle_length 和 block_length 參數(shù)控制元素的生成順序.cycle_length 控制并發(fā)處理的輸入元素的數(shù)量.如果設(shè)置 cycle_length 為1,則此轉(zhuǎn)換將一次處理一個輸入元素,并將產(chǎn)生與 tf.contrib.data.Dataset.flat_map 相同的結(jié)果.一般來說,這種轉(zhuǎn)換將適用 map_func 到 cycle_length 的輸入元素,開啟迭代器對返回的Dataset 對象,并循環(huán)通過它們生成每個迭代器的 block_length 連續(xù)元素,并且每次當(dāng)?shù)鹘Y(jié)束時,都要使用下一個輸入元素.
例如:
# 注意:以下示例使用 `{ ... }` 來表示數(shù)據(jù)集的內(nèi)容
a = { 1, 2, 3, 4, 5 }
# 注意:新行顯示 "block" 邊界
a.interleave(lambda x: Dataset.from_tensors(x).repeat(6),
cycle_length=2, block_length=4) == {
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,
}
返回一個 Dataset.
list_files(file_pattern)
與模式匹配的所有文件的數(shù)據(jù)集.
示例:如果我們的文件系統(tǒng)上有以下文件: - /path/to/dir/a.txt - /path/to/dir/b.py - /path/to/dir/c.py;如果我們傳遞 “/ path / to / dir / *.py“ 作為目錄,數(shù)據(jù)集將產(chǎn)生: - /path/to/dir/b.py - /path/to/dir/c.py
返回一個與文件名相對應(yīng)的字符串的數(shù)據(jù)集.
make_dataset_resource ()
make_initializable_iterator(shared_name=None)
創(chuàng)建一個 Iterator 用來枚舉這個數(shù)據(jù)集的元素.
注意:返回的 Iterator 將處于未初始化狀態(tài),您必須先運行 iterator.initializer 操作,然后再使用它.
返回一個此數(shù)據(jù)集的元素上的 Iterator.
make_one_shot_iterator()
創(chuàng)建一個 Iterator 用來枚舉這個數(shù)據(jù)集的元素.
注意:返回的 Iterator 將自動初始化."one-shot" Iterator 當(dāng)前不支持重新初始化.
返回一個此數(shù)據(jù)集的元素上的 Iterator.
map(
map_func,
num_threads=None,
output_buffer_size=None
)
將 map_func 映射到這個數(shù)據(jù)集.
返回一個 Dataset.
padded_batch ( batch_size , padded_shapes , padding_values = None )
將此數(shù)據(jù)集的連續(xù)元素合并到填充的批處理中.
和 Dataset.dense_to_sparse_batch() 相同,此方法將此數(shù)據(jù)集的多個連續(xù)元素 (可能具有不同的形狀) 合并到單個元素中.所得元素中的張量具有一個額外的外部維度,并且被填充到 padded_shapes 中的相應(yīng)形狀.
返回一個 Dataset.
range(*args)
創(chuàng)建一個逐步分離的值范圍的數(shù)據(jù)集.
例如:
Dataset.range(5) == [0, 1, 2, 3, 4]
Dataset.range(2, 5) == [2, 3, 4]
Dataset.range(1, 5, 2) == [1, 3]
Dataset.range(1, 5, -2) == []
Dataset.range(5, 1) == []
Dataset.range(5, 1, -2) == [5, 3]
* args:遵循與 python 的 xrange 相同的語義.即: len(args) == 1 -> start = 0,stop = args[0],step = 1 len(args) == 2 -> start = args[0], stop = args[1], step = 1 len(args) == 3 -> start = args[0], stop = args[1, stop = args[2]
返回一個 RangeDataset.
read_batch_features(
file_pattern,
batch_size,
features,
reader,
reader_args=None,
randomize_input=True,
num_epochs=None,
capacity=10000
)
讀取實例的批次.
返回一個 Dataset.
repeat(count=None)
重復(fù)此數(shù)據(jù)集的 count 次數(shù).
返回一個 Dataset.
shuffle(
buffer_size,
seed=None
)
隨機地打亂這個數(shù)據(jù)集的元素.
返回一個 Dataset.
skip(count)
創(chuàng)建一個從該數(shù)據(jù)集中跳過 count 元素的數(shù)據(jù)集.
返回一個 Dataset.
take(count)
使用此數(shù)據(jù)集中的最多 count 元素創(chuàng)建數(shù)據(jù)集.
返回一個 Dataset.
unbatch()
將此數(shù)據(jù)集的元素分解為連續(xù)元素的序列.
例如,如果此數(shù)據(jù)集的元素被塑造為 [B, a0, a1, ...],其中 B 可能會因元素而異,那么對于此數(shù)據(jù)集中的每個元素, unbatched 數(shù)據(jù)集將包含B連續(xù)的形狀元素[a0, a1, ...].
返回一個 Dataset.
zip(datasets)
通過將給定數(shù)據(jù)集壓縮在一起來創(chuàng)建數(shù)據(jù)集.
此方法與 Python 中內(nèi)置的 zip () 函數(shù)具有相似的語義,主要區(qū)別在于數(shù)據(jù)集參數(shù)可以是數(shù)據(jù)集對象的任意嵌套結(jié)構(gòu).例如:
# 注意:以下示例使用 `{ ... }` 來表示數(shù)據(jù)集的內(nèi)容
a = { 1, 2, 3 }
b = { 4, 5, 6 }
c = { (7, 8), (9, 10), (11, 12) }
d = { 13, 14 }
# The nested structure of the `datasets` argument determines the
# structure of elements in the resulting dataset.
Dataset.zip((a, b)) == { (1, 4), (2, 5), (3, 6) }
Dataset.zip((b, a)) == { (4, 1), (5, 2), (6, 3) }
# The `datasets` argument may contain an arbitrary number of
# datasets.
Dataset.zip((a, b, c)) == { (1, 4, (7, 8)),
(2, 5, (9, 10)),
(3, 6, (11, 12)) }
# The number of elements in the resulting dataset is the same as
# the size of the smallest dataset in `datasets`.
Dataset.zip((a, d)) == { (1, 13), (2, 14) }
返回一個 Dataset.
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: