zoukankan      html  css  js  c++  java
  • tensorflow 之Dataset数据集之批量数据

    ###生成批次数据
    import tensorflow as tf
    
    '''reapt()生成重复数据集  batch()将数据集按批次组合'''
    file_name = ['img1','img2','img3','img4']
    label = [1,2,3,4]
    dataset =tf.data.Dataset.from_tensor_slices((file_name,label))
    dataset1 = dataset.repeat().batch(3)
    ##定义一个迭代器迭代取批量数据
    def getone(dataset):
        iterator = dataset.make_one_shot_iterator()  #生成一个迭代器
        one_element = iterator.get_next()            #迭代器取值
        return one_element
    one_element1 = getone(dataset)
    one_element2 = getone(dataset1)
    
    ##定义一个会话内调用的函数,用于显示批量数据
    def showbatch(onebatch_element):
        for ii in range(3):
            datav = sess.run(onebatch_element)
            print('第%s批次'%ii,datav)
    ##开启会话,调用数据
    with tf.Session() as sess:
        showbatch(one_element1)
        showbatch(one_element2)
        
    '''
    第0批次 (b'img1', 1)
    第1批次 (b'img2', 2)
    第2批次 (b'img3', 3)
    
    第0批次 (array([b'img1', b'img2', b'img3'], dtype=object), array([1, 2, 3]))
    第1批次 (array([b'img4', b'img1', b'img2'], dtype=object), array([4, 1, 2]))
    第2批次 (array([b'img3', b'img4', b'img1'], dtype=object), array([3, 4, 1]))
    '''
  • 相关阅读:
    c#配置文件
    C#预处理指令
    C#面向对象详解
    231. Power of Two
    226. Invert Binary Tree
    C语言函数入参压栈顺序为什么是从右向左?
    对C++ 虚函数的理解
    悲观锁和乐观锁
    什么是索引
    CHAR 和VARCHAR的区别
  • 原文地址:https://www.cnblogs.com/liuhuacai/p/11735196.html
Copyright © 2011-2022 走看看