久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何組合兩個 keras 生成器功能

How do I combine two keras generator functions(如何組合兩個 keras 生成器功能)
本文介紹了如何組合兩個 keras 生成器功能的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

I am trying to implement a Siamese network in Keras and I want to apply image transformations to the 2 input images using Keras Image Data Generators. As per the example in the docs- https://keras.io/preprocessing/image/, I've tried to implement it like this-

datagen_args = dict(rotation_range=10,
                    width_shift_range=0.1,
                    height_shift_range=0.1,
                    horizontal_flip=True)

in_gen1 = ImageDataGenerator(**datagen_args)
in_gen2 = ImageDataGenerator(**datagen_args)

train_generator = zip(in_gen1, in_gen2)

model.fit(train_generator.flow([pair_df[:, 0,::],pair_df[:, 1,::]],
                          y_train,batch_size=16), epochs, verbose = 1)

But this code throws this error:

TypeError: zip argument #1 must support iteration

I've tried using itertools.izip as suggested in Keras - Generator for large dataset of Images and Masks but this throws the same error.

How do I resolve this?

EDIT: In case anyone is interested, this worked finally-

datagen_args = dict(
    featurewise_center=False,
    rotation_range=10,
    width_shift_range=0.1,
    height_shift_range=0.1,
    horizontal_flip=True)

in_gen1 = ImageDataGenerator(**datagen_args)
in_gen2 = ImageDataGenerator(**datagen_args)

in_gen1 = in_gen1.flow(pair_df[:, 0,::], y_train, batch_size = 16, shuffle = False)
in_gen2 = in_gen2.flow(pair_df[:, 1,::], y_train, batch_size = 16, shuffle = False)

for e in range(epochs):
    batches = 0
    for x1, x2 in itertools.izip(in_gen1,in_gen2):
    # x1, x2 are tuples returned by the generator, check whether targets match
        assert sum(x1[1] != x2[1]) == 0  
        model.fit([x1[0], x2[0]], x1[1], verbose = 1)
        batches +=1
        if(batches >= len(pair_df)/16):
            break

解決方案

Using zip() to combine generators leads to generation of an infinite iterator. Use this instead:

def combine_generator(gen1, gen2):
    while True:
        yield(next(gen1), next(gen2))

Modified code would look something like this:

datagen_args = dict(rotation_range=10,
                    width_shift_range=0.1,
                    height_shift_range=0.1,
                    horizontal_flip=True)

in_gen1 = ImageDataGenerator(**datagen_args)
in_gen2 = ImageDataGenerator(**datagen_args)

def combine_generator(gen1, gen2):
    while True:
        yield(next(gen1), next(gen2))

train_generator = combine_generator(in_gen1, in_gen2)

model.fit(train_generator.flow([pair_df[:, 0,::],pair_df[:, 1,::]],
                          y_train,batch_size=16), epochs, verbose = 1)

See this thread for further reference.

這篇關(guān)于如何組合兩個 keras 生成器功能的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區(qū)域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據(jù)文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: www.日本国产 | 国产电影精品久久 | av在线播放网站 | 瑟瑟激情 | 日韩av在线不卡 | 日韩av中文| 给我免费的视频在线观看 | 麻豆视频国产在线观看 | 亚洲 欧美 日韩在线 | 二区在线观看 | 野狼在线社区2017入口 | 男人的天堂久久 | 51ⅴ精品国产91久久久久久 | 黄色网络在线观看 | 亚洲乱码国产乱码精品精的特点 | 国产色婷婷久久99精品91 | 精品乱码一区二区三四区视频 | 91欧美 | 一级做a爰片久久毛片 | 欧美日韩国产精品一区二区 | 99视频入口 | 伊人网站在线观看 | 精品国产乱码久久久久久1区2区 | 97狠狠干| 日本中文字幕视频 | 成人精品鲁一区一区二区 | 亚洲欧美一区二区三区在线 | 伊人久久在线 | 国产免费看 | 亚洲视频中文字幕 | 欧美日韩成人在线 | 天天天天操 | 久久夜视频 | 激情一区二区三区 | 99这里只有精品视频 | 亚洲欧美网站 | 精品欧美乱码久久久久久 | 99久久免费精品视频 | 二区在线观看 | 成人在线小视频 | 亚洲 精品 综合 精品 自拍 |