简体   繁体   English

在Keras ResNet50模型中获取每批图像的名称

[英]Getting name of images per batch in Keras ResNet50 model

I'm finetuning a ResNet50 model with a few additional layers using Keras. 我正在使用Keras对带有几个附加层的ResNet50模型进行微调。 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. 我的问题是,只有图像数据及其标签,而没有图像名称才能在fit和fit_generator中传递,以便将经过批量训练的图像名称输出到文件中。

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: 然后将fit_generator与新定义的生成器函数一起使用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 预处理使用 keras function ImageDataGenerator() 生成的图像来训练 re.net50 model - preprocessing images generated using keras function ImageDataGenerator() to train resnet50 model 为什么我在 Keras 中的 resnet50 model 不收敛? - Why is my resnet50 model in Keras not converging? 简单的 tf.keras Resnet50 model 不收敛 - Simple tf.keras Resnet50 model not converging Output 使用 keras ResNet50 model 进行二进制分类的层 - Output layer for binary classification using keras ResNet50 model ResNet50 Model 没有在 keras 中使用迁移学习进行学习 - ResNet50 Model is not learning with transfer learning in keras ResNet50 Model 总是预测 1 Class - ResNet50 Model Always Predicts 1 Class 在 PyTorch 中加载 resnet50 prettriated model - Loading resnet50 prettrianed model in PyTorch Keras Resnet50 preprocess_input 与 ImageDataGenerator 一起使用时会出现灰度图像错误 - Keras Resnet50 preprocess_input gives error with Grayscale images when used with ImageDataGenerator 无法使用权​​重文件离线加载 keras resnet50 模型 - Failed to load keras resnet50 model offline using weight file 假设来自 Keras Model 的 Re.net50 的中间 Output - Intermediate Output of let' s say Resnet50 from Keras Model
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM