keras train_on_batch
On Keras Batch train
2023-09-14 09:15:51 时间
import numpy as np
import tensorflow as tf
from keras.callbacks import TensorBoard
from keras.layers import Input, Dense
from keras.models import Model
def write_log(callback, names, logs, batch_no):
for name, value in zip(names, logs):
summary = tf.Summary()
summary_value = summary.value.add()
summary_value.simple_value = value
summary_value.tag = name
callback.writer.add_summary(summary, batch_no)
callback.writer.flush()
net_in = Input(shape=(3,))
net_out = Dense(1)(net_in)
model = Model(net_in, net_out)
model.compile(loss='mse', optimizer='sgd', metrics=['mae'])
log_path = './graph'
callback = TensorBoard(log_path)
callback.set_model(model)
train_names = ['train_loss', 'train_mae']
val_names = ['val_loss', 'val_mae']
for batch_no in range(100):
X_train, Y_train = np.random.rand(32, 3), np.random.rand(32, 1)
logs = model.train_on_batch(X_train, Y_train)
write_log(callback, train_names, logs, batch_no)
if batch_no % 10 == 0:
X_val, Y_val = np.random.rand(32, 3), np.random.rand(32, 1)
logs = model.train_on_batch(X_val, Y_val)
write_log(callback, val_names, logs, batch_no//10)
相关文章
- Keras学习(一)—— Keras 模型(keras.model): Sequential 顺序模型 和 Model 模型
- Hands on Reinforcement Learning 07 Deep Q Network
- ORA-25005: cannot CREATE INSTEAD OF trigger on a read-only view ORACLE 报错 故障修复 远程处理
- ORA-25122: Only LOCAL bitmap indexes are permitted on partitioned tables ORACLE 报错 故障修复 远程处理
- ORA-26810: Apply “string” on database “string” is in the mode of combined capture and apply. ORACLE 报错 故障修复 远程处理
- ORA-28060: A data redaction policy already exists on this column. ORACLE 报错 故障修复 远程处理
- ORA-29373: resource manager is not on ORACLE 报错 故障修复 远程处理
- ORA-04089: cannot create triggers on objects owned by SYS ORACLE 报错 故障修复 远程处理
- ORA-29846: cannot create a local domain index on a string partitioned table ORACLE 报错 故障修复 远程处理
- ORA-38914: Either mutate the error or ignore row on unique violation ORACLE 报错 故障修复 远程处理
- ORA-47061: Identity map for Identity string.string, Factor Link string, string not found for operation string on string ORACLE 报错 故障修复 远程处理
- ORA-56867: Cannot connect to Master Diskmon on pipe “string” ORACLE 报错 故障修复 远程处理
- ORA-16124: transaction string string string is waiting on another transaction ORACLE 报错 故障修复 远程处理
- Exploring the Stack: An Introduction to Viewing Stacks on Linux(linux查看栈)
- MySQL中使用ON子句进行精准查询(mysql中on子句查询)
- MySQL中的ON子句有什么作用(mysql中on代表什么)
- MySQL 中的 ON 含义及应用场景解析(mysql中on什么意思)
- Oracle中妙用ON子句优化SQL查询(oracle on子句)
- 通过Jscript中@cc_on语句识别IE浏览器及版本的代码