如何在忙于训练时从 model.fit() 获取 output/log
How to get an output/log from model.fit() while it's busy training
我是 Tensorflow.js 的新手。
来自 Keres,我习惯于在训练期间打印这样的默认日志:
Epoch 1/2
320/320 [==============================] - 7s 21ms/step - loss: 5.6595
Epoch 2/2
320/320 [==============================] - 5s 15ms/step - loss: 5.5646
然而,当我在 Tensorflow.js 中 运行 await model.fit()
时,我的控制台只是挂起而没有输出。是否有我可以传递给 model.fit()
的设置,以便我可以在训练期间将某种基本日志输出到控制台?
您可以将回调传递给 .fit()
,它会在不同事件(onTrainBegin
、onTrainEnd
、onEpochBegin
、onEpochEnd
、onBatchBegin
, onBatchEnd
)
示例:
model.fit(xs, ys, {
callbacks: {
onTrainBegin: async () => {
console.log("onTrainBegin")
},
onTrainEnd: async (epoch, logs) => {
console.log("onTrainEnd" + epoch + JSON.stringify(logs))
},
onEpochBegin: async (epoch, logs) => {
console.log("onEpochBegin" + epoch + JSON.stringify(logs))
},
onEpochEnd: async (epoch, logs) => {
console.log("onEpochEnd" + epoch + JSON.stringify(logs))
},
onBatchBegin: async (epoch, logs) => {
console.log("onBatchBegin" + epoch + JSON.stringify(logs))
},
onBatchEnd: async (epoch, logs) => {
console.log("onBatchEnd" + epoch + JSON.stringify(logs))
}
}
})
我是 Tensorflow.js 的新手。
来自 Keres,我习惯于在训练期间打印这样的默认日志:
Epoch 1/2
320/320 [==============================] - 7s 21ms/step - loss: 5.6595
Epoch 2/2
320/320 [==============================] - 5s 15ms/step - loss: 5.5646
然而,当我在 Tensorflow.js 中 运行 await model.fit()
时,我的控制台只是挂起而没有输出。是否有我可以传递给 model.fit()
的设置,以便我可以在训练期间将某种基本日志输出到控制台?
您可以将回调传递给 .fit()
,它会在不同事件(onTrainBegin
、onTrainEnd
、onEpochBegin
、onEpochEnd
、onBatchBegin
, onBatchEnd
)
示例:
model.fit(xs, ys, {
callbacks: {
onTrainBegin: async () => {
console.log("onTrainBegin")
},
onTrainEnd: async (epoch, logs) => {
console.log("onTrainEnd" + epoch + JSON.stringify(logs))
},
onEpochBegin: async (epoch, logs) => {
console.log("onEpochBegin" + epoch + JSON.stringify(logs))
},
onEpochEnd: async (epoch, logs) => {
console.log("onEpochEnd" + epoch + JSON.stringify(logs))
},
onBatchBegin: async (epoch, logs) => {
console.log("onBatchBegin" + epoch + JSON.stringify(logs))
},
onBatchEnd: async (epoch, logs) => {
console.log("onBatchEnd" + epoch + JSON.stringify(logs))
}
}
})