日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python中history()_keras中的History对象用法

發(fā)布時(shí)間:2023/12/2 python 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python中history()_keras中的History对象用法 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

keras中的fit_generator和fit函數(shù)均返回History對(duì)象,那么History怎么用呢?事實(shí)上History對(duì)象已經(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類對(duì)象包含兩個(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對(duì)象用法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

總結(jié)

以上是生活随笔為你收集整理的python中history()_keras中的History对象用法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。