Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
187 views
in Technique[技术] by (71.8m points)

python - How to get tuple from ImageDataGenerator?

I've been working with ImageDataGenerator and flow_from_directory in many examples:

val_gen = ImageDataGenerator()
val_imageflow = val_gen.flow_from_directory(validation_path, ...) 

and then use it in fit funtion for training and validation data:

hist = model.fit(..., validation_data=val_imageflow,...)

But now I need to use validation_data in shape (x_data, y_data), like for case

hist = model.fit(..., validation_data=(x_data, y_data),...)

The reason is that I want to use callback in my fine-tuned CNN on end of every epoch to show correct classification for each class. Unfortunately I cannot get the point how to get generator val_imageflow into tuple. I'd tried to run following code, but it consumed all RAM very quickly and processing was interrupted (I probably do something wrong)

x_data = []
y_data = []
while True:
    try:
        n = next(val_imageflow)
        x_data.append(n[0])
        y_data.append(n[1])
    except StopIteration:
        break

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...