我一直试图在Tensorboard中可视化一个简单的模型。该模型使用keras在Tensorflow Eager Execution模式下构建。
拟合模型时出现以下错误:
>>> history = model.fit(x_train, y_train, epochs=1, batch_size=BatchSize, callbacks=[tensorbrd])
Traceback (most recent call last):
File "C:\...\tensorflow\python\ops\gen_logging_ops.py", line 322, in histogram_summary
"HistogramSummary", name, _ctx._post_execution_callbacks, tag, values)
tensorflow.python.eager.core._FallbackException: This function does not handle the case of the path where all inputs are not already EagerTensors.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\...\tensorflow\python\keras\engine\training.py", line 1348, in fit
validation_steps=validation_steps)
File "C:\...\tensorflow\python\keras\engine\training_eager.py", line 990, in fit_loop
callbacks.set_model(callback_model)
File "C:\...\tensorflow\python\keras\callbacks.py", line 71, in set_model
callback.set_model(model)
File "C:\...\tensorflow\python\keras\callbacks.py", line 781, in set_model
tf_summary.histogram('{}_out'.format(layer.name), layer.output)
File "C:\...\tensorflow\python\summary\summary.py", line 187, in histogram
tag=tag, values=values, name=scope)
File "C:\...\tensorflow\python\ops\gen_logging_ops.py", line 326, in histogram_summary
tag, values, name=name, ctx=_ctx)
File "C:\...\tensorflow\python\ops\gen_logging_ops.py", line 340, in histogram_summary_eager_fallback
_attr_T, (values,) = _execute.args_to_matching_eager([values], _ctx, _dtypes.float32)
File "C:\...\tensorflow\python\eager\execute.py", line 191, in args_to_matching_eager
t, dtype, preferred_dtype=default_dtype, ctx=ctx))
File "C:\...\tensorflow\python\framework\ops.py", line 1094, in internal_convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "C:\...\tensorflow\python\framework\constant_op.py", line 217, in _constant_tensor_conversion_function
return constant(v, dtype=dtype, name=name)
File "C:\...\tensorflow\python\framework\constant_op.py", line 167, in constant
t = convert_to_eager_tensor(value, ctx, dtype)
File "C:\...\tensorflow\python\framework\constant_op.py", line 113, in convert_to_eager_tensor
return ops.EagerTensor(value, context=handle, device=device, dtype=dtype)
ValueError: Attempt to convert a value (<DeferredTensor 'None' shape=(?, 5000) dtype=float32>) with an unsupported type (<class 'tensorflow.python.keras.engine.base_layer.DeferredTensor'>) to a Tensor.
这基于Tensorflow 1.10代码:
import tensorflow as tf
from tensorflow import keras
import matplotlib.pyplot as plt
import numpy as np
import os
import h5py
tf.enable_eager_execution()
BatchSize = 256
model = keras.Sequential([
keras.layers.Flatten(input_shape=(1000,5)),
keras.layers.Dense(1, activation=tf.nn.relu)
])
model.compile(optimizer=tf.train.AdamOptimizer(learning_rate=0.01, beta1=0.9, beta2=0.999),
loss='mean_squared_error',
metrics=[ 'mean_squared_error'])
tensorbrd = keras.callbacks.TensorBoard(log_dir=SUMMARIES_FOLDER, histogram_freq=1, write_graph=False, write_images=False)
history = model.fit(x_train, y_train, epochs=1, batch_size=BatchSize, callbacks=[tensorbrd])
我犯错了吗?或者Tensorboard是否以这种方式不兼容? 任何帮助将不胜感激!