我正在将模型训练为:
with tf.Graph().as_default():
with tf.Session(config=tf.ConfigProto(allow_soft_placement = True)) as sess:
K.set_session(sess)
tf.train.create_global_step()
#with tf.device('/gpu:0:'):
m = GAReader.Model(nlayers, data.vocab_size, data.num_chars, W_init,
nhidden, embed_dim, dropout, train_emb,
char_dim, use_feat, gating_fn, words).build_network()
m.compile(optimizer=tf.train.AdamOptimizer(0.01),
loss=tf.keras.losses.categorical_crossentropy,
metrics=[tf.keras.metrics.categorical_accuracy])
tensorboard = TensorBoardCustom(log_dir="logs", sess=sess)
m.fit_generator(generator=batch_loader_train, steps_per_epoch=len(batch_loader_train.batch_pool), epochs=100, callbacks=[tensorboard])
并且我定义了一个自定义回调,将keras.callbacks.Tensorboard扩展为:
class TensorBoardCustom(TensorBoard):
def __init__(self, log_dir, sess, **kwargs):
super(TensorBoardCustom, self).__init__(log_dir, **kwargs)
self.sess = sess
def on_batch_end(self, batch, logs={}):
summary = tf.summary.merge_all()
writer = tf.summary.FileWriter(self.log_dir)
s = self.sess.run(summary)
writer.add_summary(s, batch)
writer.close()
super(TensorBoardCustom, self).on_batch_end(batch, logs)
并且我要添加一个新的摘要:
l_docin = tf.keras.layers.Input(shape=(None,))
with tf.name_scope('summaries'):
table = tf.contrib.lookup.index_to_string_table_from_tensor(
self.mapping_string, default_value="UNKNOWN")
words = table.lookup(tf.cast(l_qin, tf.int64))
text = tf.reduce_join(words, 1, separator=' ')
tf.summary.text('text', text)
但是,这不起作用,并且出现以下错误:
InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'input_2' with dtype float and shape [?,?]
[[{{node input_2}} = Placeholder[dtype=DT_FLOAT, shape=[?,?], _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
有人可以解释为什么会发生这种情况以及我如何纠正它?有没有更简单/更好的方法来添加自定义摘要?
答案 0 :(得分:0)
TensorFlow回调SQL> with longest as
2 (select min(hiredate) min_hiredate,
3 to_char(min(hiredate), 'dy', 'nls_date_language=english') day
4 from emp
5 )
6 select min_hiredate,
7 day,
8 case when day in ('sat', 'sun') then 'weekend'
9 else 'weekday'
10 end result
11 from longest;
MIN_HIREDA DAY RESULT
---------- ------------ ----------
17.12.1980 wed weekday
SQL>
记录累积训练和评估批处理时间。
它依赖于私有属性TensorBoardWithTime
和TensorBoard._train_writer
。
它可以与TensorFlow 2.4.0rc2一起使用。
TensorBoard._val_writer