简体   繁体   中英

Getting train test data from Keras ImageDataGenerator

I am using ImageDataGenerator from Keras as follows.

datagen = ImageDataGenerator(samplewise_center=True,
    samplewise_std_normalization=True, validation_split=0.30
                               )

Then .flow statement to obtain train and test split as follows.

train_iterator = datagen.flow(x, y, subset='training')
test_iterator = datagen.flow(x, y, subset='validation')

Here x represents images with a shape (588, 120, 120, 1) and y represents multiclass output (588, 4) .

In (588, 120, 120, 1) shape input data, there are total 588 samples each with a shape of (120, 120, 1) . The output is having 4 classes.

Then I train and test my CNN with the following code.

history =model.fit_generator(train_iterator,
                             
                              epochs=10,
                              validation_data=test_iterator,
                              callbacks=callbacks_list) 


pred_test = model.predict(test_iterator, steps=len(test_iterator), verbose=0)

My question is: How can I access the test data (both x and y) which test_iterator uses for prediction.

flow()返回产生 (x, y) 元组的迭代器,您可以使用test_iterator.next()访问元素。

Just an FYI. In the ImageDataGenerator you have set samplewise_center=True, samplewise_std_normalization=True,. If this is what you want you must FIRST fit the generator to accumulate the statistics of the input data so first do

datagen.fit(x)

Documentation is here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM