keras中的History對象用法
keras中的fit_generator和fit函數(shù)均返回History對象,那么History怎么用呢?事實(shí)上History對象已經(jīng)記錄了運(yùn)行輸出。在了解之前,我們甚至自己定義回調(diào)函數(shù)記錄損失和準(zhǔn)確率等。
相關(guān)keras源碼位于網(wǎng)址:
class History(Callback): """Callback that records events into a `History` object. This callback is automatically applied to every Keras model. The `History` object gets returned by the `fit` method of models. """ def on_train_begin(self, logs=None): self.epoch = [] self.history = {} def on_epoch_end(self, epoch, logs=None): logs = logs or {} self.epoch.append(epoch) for k, v in logs.items(): self.history.setdefault(k, []).append(v)
可以看出History類對象包含兩個(gè)屬性,分別為epoch和history,epoch為訓(xùn)練輪數(shù)。
根據(jù)compile參數(shù)metrics,history包含不同的內(nèi)容。比如,當(dāng)某一次metrics=['accuracy']時(shí),運(yùn)行如下部分代碼我們可以看出,history字典類型,包含val_loss,val_acc,loss,acc四個(gè)key值。
####省略若干 history = model.fit_generator( mp.train_flow, steps_per_epoch=32, epochs=3, validation_data=mp.test_flow, validation_steps=32) print(history.history) print(history.epoch) print(history.history['val_loss'])
{‘val_loss': [0.4231100323200226, 0.3713115310668945, 0.3836631367206573], ‘val_acc': [0.815, 0.84, 0.83], ‘loss': [0.8348453622311354, 0.5010451343324449, 0.4296100065112114], ‘a(chǎn)cc': [0.630859375, 0.7509920634920635, 0.783203125]}
[0, 1, 2]
[0.4231100323200226, 0.3713115310668945, 0.3836631367206573]
補(bǔ)充知識(shí):在ipython中使用%history快速查找歷史命令
1、輸出所有歷史記錄,且?guī)в行蛱?hào)
%history -n 150: %cpaste 151: %cpaste 152: print(r">>>>>>>>>") 153: print(r'>>>>>>>>>') 154: print(r'>>>>>>>>><') 155: print(r'>') 156: print(r'>>') 157: print(r'>>>') ...
2、按序號(hào),查找某些序號(hào)區(qū)間的歷史紀(jì)錄
%history -n 168-170 178 185-190 168: planets 169: for method, group in planets.groupby('method'): print(f'{method:30s} method={group}') 170: for method, group in planets.groupby('method'): print(f'{method:30s} method={group.shape}') 178: %history? 185: %history -u 186: %history -n -u 187: ?%history 188: %history -g method 189: %history -g method print 190: %history -g for method,
3、模糊查找
%history -g print*metho* 120: for method, group in planets.groupby('method'): print(f"{method:30s} shape={groupe.shape}") 121: for method, group in planets.groupby('method'): print(f"{method:30s} shape={group.shape}") 169: for method, group in planets.groupby('method'): print(f'{method:30s} method={group}') 170: for method, group in planets.groupby('method'): print(f'{method:30s} method={group.shape}') 182: for method, group in planets.groupby('method'): print(f"{method:30s shape=group.shape}") 198: %history -g print*metho*
以上這篇keras中的History對象用法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
python cx_Oracle的基礎(chǔ)使用方法(連接和增刪改查)
這篇文章主要給大家介紹了關(guān)于python cx_Oracle的基礎(chǔ)使用方法,其中包括連接、增刪改查等基本操作,并給大家分享了python 連接Oracle 亂碼問題的解決方法,需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-11-11Python類的動(dòng)態(tài)修改的實(shí)例方法
這篇文章主要介紹了Python類的動(dòng)態(tài)修改的實(shí)例方法的相關(guān)資料,需要的朋友可以參考下2017-03-03jupyter notebook 調(diào)用環(huán)境中的Keras或者pytorch教程
這篇文章主要介紹了jupyter notebook 調(diào)用環(huán)境中的Keras或者pytorch教程,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-04-04Python中實(shí)現(xiàn)switch功能實(shí)例解析
這篇文章主要介紹了Python中實(shí)現(xiàn)switch功能實(shí)例解析,具有一定借鑒價(jià)值,需要的朋友可以參考下2018-01-01自動(dòng)化Nginx服務(wù)器的反向代理的配置方法
這篇文章主要介紹了自動(dòng)化Nginx服務(wù)器的反向代理的配置方法,反向代理是Nginx服務(wù)器的招牌功能,需要的朋友可以參考下2015-06-06