亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

keras.backend 的 clear_session() 方法沒有清理擬合數據

keras.backend 的 clear_session() 方法沒有清理擬合數據

皈依舞 2022-06-28 16:06:44
我正在比較不同類型數據質量的擬合精度結果?!昂脭祿笔翘卣髦抵袥]有任何 NA 的數據?!皦臄祿笔翘卣髦抵芯哂?NA 的數據。應該通過一些值校正來修復“壞數據”。作為值校正,它可能會用零或平均值替換 NA。在我的代碼中,我試圖執行多個擬合程序。查看簡化的代碼:from keras import backend as K...xTrainGood = ... # the good version of the xTrain data xTrainBad = ... #  the bad version of the xTrain data...model = Sequential()model.add(...)...historyGood = model.fit(..., xTrainGood, ...) # fitting the model with                                               # the original data without                                              # NA, zeroes, or the feature mean values根據historyGood數據查看擬合精度圖:之后,代碼重置存儲的模型并使用“壞”數據重新訓練模型:K.clear_session()historyBad = model.fit(..., xTrainBad, ...)根據historyBad數據查看擬合過程結果:可以注意到,初始精度> 0.7,這意味著模型“記住”了之前的擬合。為了比較,這是“壞”數據的獨立擬合結果:如何將模型重置為“初始”狀態?
查看完整描述

3 回答

?
慕運維8079593

TA貢獻1876條經驗 獲得超5個贊

K.clear_session()不足以重置狀態并確保可重復性。您還需要:

  • 設置(和重置)隨機種子

  • 重置 TensorFlow 默認圖

  • 刪除以前的模型

完成以下各項的代碼。

reset_seeds()

model = make_model() # example function to instantiate model

model.fit(x_good, y_good)


del model

K.clear_session()

tf.compat.v1.reset_default_graph()


reset_seeds()

model = make_model()

model.fit(x_bad, y_bad)

請注意,如果其他變量引用模型,您也應該使用del它們 - 例如model = make_model(); model2 = model--> del model, model2- 否則它們可能會持續存在。最后,tf隨機種子不像random's 或numpy's 那樣容易重置,并且需要事先清除圖形。


使用的功能/模塊:

import tensorflow as tf

import numpy as np

import random

import keras.backend as K


def reset_seeds():

    np.random.seed(1)

    random.seed(2)

    if tf.__version__[0] == '2':

        tf.random.set_seed(3)

    else:

        tf.set_random_seed(3)

    print("RANDOM SEEDS RESET")


查看完整回答
反對 回復 2022-06-28
?
狐的傳說

TA貢獻1804條經驗 獲得超3個贊

K.clear_session()以錯誤的方式使用,要獲得具有隨機初始化權重的模型,您應該刪除舊模型(使用del關鍵字),然后繼續創建一個新模型,并對其進行訓練。

您可以K.clear_session()在每次安裝程序后使用。



查看完整回答
反對 回復 2022-06-28
?
侃侃爾雅

TA貢獻1801條經驗 獲得超16個贊

實例化一個新的同名模型對象還不夠?

model = make_model()


查看完整回答
反對 回復 2022-06-28
  • 3 回答
  • 0 關注
  • 377 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號