简体   繁体   中英

Getting name of images per batch in Keras ResNet50 model

I'm finetuning a ResNet50 model with a few additional layers using Keras. I need to know which images are trained per batch.

The problem I have is that only the imagedata and their labels, but no image names can be passed on in the fit and fit_generator in order to output the image names, which are trained in a batch, to a file.

You can make your own generator so you could track what is fed into the network, and do whatever you like with the data (ie match indices to images).

Here is a basic example of a generator function which you can build upon:

def gen_data():
    x_train = np.random.rand(100, 784)
    y_train = np.random.randint(0, 1, 100)

    i = 0
    while True:  
        indices = np.arange(i*10, 10*i+10)

        # Those are indices being fed to network which can be saved to a file.
        print(indices)
        out = x_train[indices],  y_train[indices]
        i = (i+1) % 10
        yield out

And then use fit_generator with the new defined generator function:

model.fit_generator(gen_data(), steps_per_epoch=10, epochs=20)

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