我正在使用tensorflow来训练一个网络来完成图像分割任务,并且我有一个关于不同时代之间的model.fit行为的问题,特别是:
model.fit和调用model.fit 512次有什么区别吗?这里是我的代码的简化版本,以防有帮助。首先,一些设置:
# Create image generators for dataset augmentation
imgGen = ImageDataGenerator(**data_augmentation_parameters)
maskGen = ImageDataGenerator(**data_augmentation_parameters)
seed = random.randint(0, 1000000000)
imgIterator = imgGen.flow(img, seed=seed, shuffle=False, batch_size=batch_size)
maskIterator = maskGen.flow(mask, seed=seed, shuffle=False, batch_size=batch_size)
# Load network structure from model.py file
network = unet(net_scale = 1)
# Calculate # of iterations
steps_per_epoch = int(num_samples / batch_size)迭代拟合的两种方法:
拟合方法1:
network.fit(
((imgBatch, maskBatch) for imgBatch, maskBatch in zip(imgIterator, maskIterator)),
steps_per_epoch=steps_per_epoch,
epochs=512,
)拟合方法2:
for epoch in range(512):
network.fit(
((imgBatch, maskBatch) for imgBatch, maskBatch in zip(imgIterator, maskIterator)),
steps_per_epoch=steps_per_epoch,
epochs=1,
)我认为这个问题和我的一样,但我不明白一个答案是如何适用于这个问题的--我只是想知道指定一个纪元数>1和在for循环中运行model.fit之间是否存在一些内部差异。
谢谢!
发布于 2022-02-12 23:55:34
根据用于Keras的github存储库中的这问题,是的,您应该能够在循环中以您想要的方式递增地训练您的模型。尽管如此,您应该在这两种方式上运行一个测试,看看它是否会产生不同的结果。
https://datascience.stackexchange.com/questions/108099
复制相似问题