zoukankan      html  css  js  c++  java
  • tf.Dataset

    https://www.cnblogs.com/wkslearner/p/9484443.html
    https://blog.csdn.net/dqcfkyqdxym3f8rb0/article/details/79342369

    在tensorflow的官方文档是这样介绍Dataset数据对象的:
    Dataset可以用来表示输入管道元素集合(张量的嵌套结构)和“逻辑计划“对这些元素的转换操作。在Dataset中元素可以是向量,元组或字典等形式。
    另外,Dataset需要配合另外一个类Iterator进行使用,Iterator对象是一个迭代器,可以对Dataset中的元素进行迭代提取。

    一、概述
    使用Dataset的三个步骤:

    • 载入数据:为数据创建一个Dataset实例
    • 创建一个迭代器:使用创建的数据集来构造一个Iterator实例以遍历数据集
    • 使用数据:使用创建的迭代器,我们可以从数据集中获取数据元素,从而输入到模型中去。

    二、常用的方法
    常用的Dataset方法有from_tensor_slices、from_tensors、from_generator

    2.1、Dataset.from_generator
    https://blog.csdn.net/foreseerwang/article/details/80572182
    https://blog.csdn.net/shuzfan/article/details/79051042

    @staticmethod
    from_generator(
        generator,
        output_types,
        output_shapes=None
    )
    
    #Args:
    #generator: A callable object that takes no arguments and returns an object #that supports the iter() protocol.
    #output_types: A nested structure of tf.DType objects corresponding to each #component of an element yielded by generator.
    #output_shapes: (Optional.) A nested structure of tf.TensorShape objects #corresponding to each component of an element yielded by generator.
    #Returns:
    #A Dataset.
    
    #Creates a Dataset whose elements are generated by generator.
    #The generator argument must be a callable object that returns an object that #support the iter() protocol (e.g. a generator function). The elements #generated by generator must be compatible with the given output_types and #(optional) output_shapes arguments.
    
    #For example:
    import itertools
    
    def gen():
      for i in itertools.count(1):
        yield (i, [1] * i)
    
    ds = Dataset.from_generator(
        gen, (tf.int64, tf.int64), (tf.TensorShape([]), tf.TensorShape([None])))
    value = ds.make_one_shot_iterator().get_next()
    
    sess.run(value)  # (1, array([1]))
    sess.run(value)  # (2, array([1, 1]))
    
  • 相关阅读:
    yum源服务器搭建
    hadoop常用的端口配置
    yarn组建端口
    linux上go环境配置
    mysql主从复制
    一篇比较好的F5配置介绍
    统计随机数出现个数与直方图显示的C实现
    [LinuxC-笔记1]
    [转]达夫设备(Duff's device)
    [转]Ubuntu 18.04设置1920*1080
  • 原文地址:https://www.cnblogs.com/ying-chease/p/13215659.html
Copyright © 2011-2022 走看看