tf.train.slice_input_producer()和tf.train.batch()

1.tf.train.slice_input_producer函數(shù)白粉,一種模型數(shù)據(jù)的排隊(duì)輸入方法传泊。

tf.train.slice_input_producer(
    tensor_list,
    num_epochs=None, 
    shuffle=True,
    seed=None,
    capacity=32,
    shared_name=None,
    name=None
)

其參量為:

Args:
tensor_list: A list of Tensor objects. Every Tensor in tensor_list must have the same size in the first dimension.

# 循環(huán)Queue輸入次數(shù)
num_epochs: An integer (optional). If specified, slice_input_producer produces each slice num_epochs times before generating an OutOfRange error. If not specified, slice_input_producer can cycle through the slices an unlimited number of times.

shuffle: Boolean. If true, the integers are randomly shuffled within each epoch.
seed: An integer (optional). Seed used if shuffle == True.

# Queue的容量
capacity: An integer. Sets the queue capacity.

shared_name: (optional). If set, this queue will be shared under the given name across multiple sessions.
name: A name for the operations (optional).

相關(guān)代碼實(shí)例:

    # 生成包含輸入和目標(biāo)圖片地址名的list
    input_files = [os.path.join(dirname, 'input', f) for f in flist]
    output_files = [os.path.join(dirname, 'output', f) for f in flist]

    # 內(nèi)部自動(dòng)轉(zhuǎn)換為Constant String的Tensor,并排隊(duì)進(jìn)入隊(duì)列
    input_queue, output_queue = tf.train.slice_input_producer(
        [input_files, output_files], shuffle=self.shuffle,
        seed=0123, num_epochs=self.num_epochs)

    # tf.train.slice_input_producer()每次取一對(duì)【輸入-目標(biāo)】對(duì),交給ReadFile這
    # 個(gè)Op
    input_file = tf.read_file(input_queue)
    output_file = tf.read_file(output_queue)
    
    # 生成RGB格式的圖像tensor
    im_input = tf.image.decode_jpeg(input_file, channels=3)
    im_output = tf.image.decode_jpeg(output_file, channels=3)

2.tf.train.batch()函數(shù)

tf.train.batch(
    tensors,
    batch_size,
    num_threads=1,
    capacity=32,
    enqueue_many=False,
    shapes=None,
    dynamic_pad=False,
    allow_smaller_final_batch=False,
    shared_name=None,
    name=None
)

其參量為:

Args:
tensors: The list or dictionary of tensors to enqueue.
batch_size: The new batch size pulled from the queue.
num_threads: The number of threads enqueuing tensors. The batching will be nondeterministic if num_threads > 1.
capacity: An integer. The maximum number of elements in the queue.

#進(jìn)行shuffle的輸入是否為單個(gè)tensor
enqueue_many: Whether each tensor in tensors is a single example.

shapes: (Optional) The shapes for each example. Defaults to the inferred shapes for tensors.
dynamic_pad: Boolean. Allow variable dimensions in input shapes. The given dimensions are padded upon dequeue so that tensors within a batch have the same shapes.
allow_smaller_final_batch: (Optional) Boolean. If True, allow the final batch to be smaller if there are insufficient items left in the queue.
shared_name: (Optional). If set, this queue will be shared under the given name across multiple sessions.
name: (Optional) A name for the operations.

相關(guān)代碼實(shí)例

samples = tf.train.batch(
        sample,
        batch_size=self.batch_size,
        num_threads=self.nthreads,
        capacity=self.capacity)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末鸭巴,一起剝皮案震驚了整個(gè)濱河市眷细,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌鹃祖,老刑警劉巖溪椎,帶你破解...
    沈念sama閱讀 216,544評(píng)論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異恬口,居然都是意外死亡校读,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,430評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門祖能,熙熙樓的掌柜王于貴愁眉苦臉地迎上來歉秫,“玉大人,你說我怎么就攤上這事养铸⊙丬剑” “怎么了?”我有些...
    開封第一講書人閱讀 162,764評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵钞螟,是天一觀的道長兔甘。 經(jīng)常有香客問我,道長鳞滨,這世上最難降的妖魔是什么洞焙? 我笑而不...
    開封第一講書人閱讀 58,193評(píng)論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮拯啦,結(jié)果婚禮上闽晦,老公的妹妹穿的比我還像新娘。我一直安慰自己提岔,他們只是感情好仙蛉,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,216評(píng)論 6 388
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著碱蒙,像睡著了一般荠瘪。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上赛惩,一...
    開封第一講書人閱讀 51,182評(píng)論 1 299
  • 那天哀墓,我揣著相機(jī)與錄音,去河邊找鬼喷兼。 笑死篮绰,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的季惯。 我是一名探鬼主播吠各,決...
    沈念sama閱讀 40,063評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼臀突,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了贾漏?” 一聲冷哼從身側(cè)響起候学,我...
    開封第一講書人閱讀 38,917評(píng)論 0 274
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎纵散,沒想到半個(gè)月后梳码,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,329評(píng)論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡伍掀,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,543評(píng)論 2 332
  • 正文 我和宋清朗相戀三年掰茶,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片蜜笤。...
    茶點(diǎn)故事閱讀 39,722評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡符匾,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出瘩例,到底是詐尸還是另有隱情,我是刑警寧澤甸各,帶...
    沈念sama閱讀 35,425評(píng)論 5 343
  • 正文 年R本政府宣布垛贤,位于F島的核電站,受9級(jí)特大地震影響趣倾,放射性物質(zhì)發(fā)生泄漏聘惦。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,019評(píng)論 3 326
  • 文/蒙蒙 一儒恋、第九天 我趴在偏房一處隱蔽的房頂上張望善绎。 院中可真熱鬧,春花似錦诫尽、人聲如沸禀酱。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,671評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽剂跟。三九已至,卻和暖如春酣藻,著一層夾襖步出監(jiān)牢的瞬間曹洽,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,825評(píng)論 1 269
  • 我被黑心中介騙來泰國打工辽剧, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留送淆,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 47,729評(píng)論 2 368
  • 正文 我出身青樓怕轿,卻偏偏與公主長得像偷崩,于是被迫代替她去往敵國和親辟拷。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,614評(píng)論 2 353