[英]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.