Python Tensorflow-多次运行model.fit而不重新初始化模型 [英] Python Tensorflow - Running model.fit multiple times without reinstantiating the model

查看:895
本文介绍了Python Tensorflow-多次运行model.fit而不重新初始化模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在观看有关机器学习的受欢迎的YouTube速成班.

I am watching a popular YouTube crash course on machine learning.

3:35:50 时,他提到该模型可能过度拟合,因此用更少的时间再次适合它.

At 3:35:50, he mentions that the model is likely overfit, so fits it again with less epochs.

由于他没有重新实例化模型,这不等于用相同的数据拟合模型,从而继续对其进行过度训练吗?

Since he didn't reinstantiate the model, isn't this equivalent to fitting the model with that same data, thereby continuing to overtrain it?

假设您已经创建了一个模型并且可以使用数据了.

Assume you have a model created and data ready to go.

您运行:

model.fit(train_images, train_labels, epochs=10)
model.fit(train_images, train_labels, epochs=8)

这等同于运行:

model.fit(train_images, train_labels, epochs=18)

或:

model.fit(train_images, train_labels, epochs=8)

如果先前拟合的数据被覆盖,为什么第二次运行model.fit是从先前模型的准确性开始的?

If previously fitted data is overwritten, why does running model.fit a second time begin with the accuracy of the previous model?

多个,可以接受的解决方案是加载先前训练的模型,然后再次运行model.fit.

如果这将覆盖预先存在的权重,那么这是否会破坏首先保存模型的目的?不会在新数据上首次训练模型是否等效吗?

If this will overwrite the pre-existing weights, doesn't that defeat the purpose of saving the model in the first place? Wouldn't training the model for the first time on the new data be equivalent?

在多个相似数据集中训练模型,同时又保持所有数据的准确性的合适方法是什么?

What is the appropriate way to train a model across multiple, similar datasets while retaining accuracy across all of the data?

推荐答案

由于他没有重新实例化模型,所以这不等于 用相同的数据拟合模型,从而继续过度训练 它吗?

Since he didn't reinstantiate the model, isn't this equivalent to fitting the model with that same data, thereby continuing to overtrain it?

您是对的!为了检查在他的示例中哪个时期更好,他应该重新编译网络(即再次执行上述单元格).

You are correct! In order to check which number of epochs would do better in his example, he should have compiled the network again (that is, execute the above cell again).

请记住,通常,每当再次实例化模型时,它很可能将从全新的权重开始,与过去的权重完全不同(除非您手动更改此权重).因此,即使您保持相同的时期数,最终精度也会根据初始权重而改变.

Just remember that in general, whenever you instantiate a model again it most likely will start with completely new weights, totally different from past weights (unless you change this manually). So even though you keep the same amount of epochs, your final accuracy can change depending on the initial weights.

这两个命令是否等效?

model.fit(train_images, train_labels, epochs=10)
model.fit(train_images, train_labels, epochs=8)

model.fit(train_images, train_labels, epochs=18)

否.

在第一种情况下,您正在使用某些权重X来训练网络10次遍历所有训练集,然后将权重更新为某个值y. 然后,尽管所有训练集都设置了8次,但是您将再次训练网络,但是现在您正在使用权重X+y的网络.

In the first case, you are training your network with some weights X going through all your training set 10 times, then you update your weights for some value y. Then you will train your network again though all your training set 8 times but now you are using a network with weights X+y.

对于第二种情况,您将使用权重X通过所有训练数据对网络进行18次训练.

For the second case, you will train your network through all your training data 18 times with the weights X.

这不一样!

这篇关于Python Tensorflow-多次运行model.fit而不重新初始化模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆