久久久久久久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.

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

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

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區域周圍繪制一個矩形)
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(根據文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 丁香六月伊人 | 神马久久久久久久久久 | 97精品超碰一区二区三区 | 国产亚洲黄色片 | www.久久久久久久久久久 | 国产一区二区免费 | 狠狠干天天干 | 欧美群妇大交群中文字幕 | 丁香综合 | 久久久久久久av | 久久国产精品网 | 欧美精品二区三区 | 亚洲成人免费在线观看 | 国产成人jvid在线播放 | 毛片韩国 | 亚洲影音 | 久久99视频这里只有精品 | 又黑又粗又长的欧美一区 | 伊伊综合网 | 亚洲 欧美 日韩 在线 | 九九久久这里只有精品 | 91视频在线看 | 国产成人在线观看免费 | 精品欧美一区二区三区久久久小说 | 国产成人精品在线 | 成人av色 | 九九九久久国产免费 | 亚洲国产精品久久久久秋霞不卡 | 久久久久国产精品免费免费搜索 | 91精品国产91久久久久久密臀 | 色综合色综合色综合 | 久久久精品一区 | 伊人手机在线视频 | 欧美日韩亚洲一区 | 欧美日一区二区 | 日韩一区二区av | 成人免费一级视频 | 免费毛片网站在线观看 | 亚洲 欧美 日韩 在线 | 精品国产欧美 | 久久国产精品网 |