2 回答

TA貢獻1804條經驗 獲得超7個贊
當然,你可以定義一個回調函數委托來停止訓練階段。
您可以在這里查看更多信息:
https ://towardsdatascience.com/neural-network-with-tensorflow-how-to-stop-training-using-callback-5c8d575c18a9
在此示例中,創建了一個回調函數,以便在“準確度”超過閾值時停止訓練階段。您可以修改函數以進行時間計算,以驗證經過的時間。
這是一段工作代碼:
class TimeOut(Callback):
def __init__(self, t0, timeout):
super().__init__()
self.t0 = t0
self.timeout = timeout # time in minutes
def on_train_batch_end(self, batch, logs=None):
if time.time() - self.t0 > self.timeout * 60: # 58 minutes
print(f"\nReached {(time.time() - self.t0) / 60:.3f} minutes of training, stopping")
self.model.stop_training = True
callbacks = [TimeOut(t0=time.time(), timeout=58)]

TA貢獻1827條經驗 獲得超8個贊
Tensorflow 最近制作了一個可以做到這一點的插件。
在你的情況下,它看起來像這樣
import tensorflow_addons as tfa
time_stopping_callback = tfa.callbacks.TimeStopping(seconds=60*58, verbose=1) #58min
model.fit(........, callbacks = [time_stopping_callback])
鏈接: https ://www.tensorflow.org/addons/tutorials/time_stopping
添加回答
舉報