【问题标题】:Do I need to reset model weights in Kfold loop?我需要在 Kfold 循环中重置模型权重吗?
【发布时间】:2019-09-30 13:23:01
【问题描述】:

我想用 Kfold 检查我的模型的准确性。我希望在每次迭代之间重置模型权重,因此我不会继续计算之前的迭代权重。下面的代码够吗?或者模型是否存在于keras后端的循环之外?

from keras.models import Sequential
from keras.layers import Dense
from sklearn.model_selection import StratifiedKFold
from sklearn.utils import shuffle
import tensorflow as tf

kfold = StratifiedKFold(n_splits=10, shuffle=True, random_state=seed)
sess = tf.InteractiveSession()

for train, test in kfold.split(X, Y):
    model = Sequential()
    model.add(Conv2D)
    #Add more layers
    model.compile()
    model.fit()

    #Calculate accuracy for each test element (pseudo code)
    modelprediction=model.predict(testvalue1,2,3,4,5)
    indexes = tf.argmax(modelprediction, axis=1)

    print(totalAccuracy)

sess = tf.Interactive 和 Keras 后端是否以某种方式保存权重?我应该同时重置 sess 和 keras 吗?我该怎么做?

【问题讨论】:

    标签: python machine-learning keras scikit-learn deep-learning


    【解决方案1】:

    由于您使用model = Sequential()(即您定义模型)循环中,您的模型确实在每次迭代中“重置”(实际上是新定义的),所以您不需要采取任何进一步的行动。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-09
      • 1970-01-01
      • 1970-01-01
      • 2021-08-02
      相关资源
      最近更新 更多