我正在训练一个基于logistic回归的模型,并试图在张量板中查看计算图。但是,当我运行代码时,我会得到下面提到的错误。
在不附加回调的情况下,我的model.fit()运行得很好。另外,正如建议的那样,我添加了update_freq = 1000
logdir = os.path.join("logs", datetime.datetime.now().strftime("%Y%m%d-%H%M%S"))
tensorboard_callback = tf.keras.callbacks.TensorBoard(logdir, histogram_freq=1, update_freq=1000)
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(10, activation=tf.nn.softmax)])
model.compile(optimizer='sgd',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model.fit(np.matrix(train_X), np.matrix(train_y).T, epochs=10, callbacks=[tensorboard_callback])
但是,我得到了这个错误:
AttributeError Traceback (most recent call last)
<ipython-input-73-90c175274a55> in <module>()
8 metrics=['accuracy'])
9
---> 10 model.fit(np.matrix(train_X), np.matrix(train_y).T, epochs=20, callbacks=[tensorboard_callback])
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, max_queue_size, workers, use_multiprocessing, **kwargs)
878 """Returns the loss value & metrics values for the model in test mode.
879
--> 880 Computation is done in batches.
881
882 Arguments:
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training_arrays.py in model_iteration(model, inputs, targets, sample_weights, batch_size, epochs, verbose, callbacks, val_inputs, val_targets, val_sample_weights, shuffle, initial_epoch, steps_per_epoch, validation_steps, mode, validation_in_fit, **kwargs)
250 # Loop over dataset for the specified number of steps.
251 target_steps = steps_per_epoch
--> 252
253 step = 0
254 while step < target_steps:
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/callbacks.py in on_epoch_begin(self, epoch, logs, mode)
235 'to the batch update (%f). Check your callbacks.', hook_name,
236 delta_t_median)
--> 237
238 def _call_begin_hook(self, mode):
239 """Helper function for on_{train|test|predict}_begin methods."""
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/callbacks.py in on_epoch_begin(self, epoch, logs)
1139 samples. Note that writing too frequently to TensorBoard can slow down
1140 your training.
-> 1141 profile_batch: Profile the batch to sample compute characteristics. By
1142 default, it will profile the second batch. Set profile_batch=0 to
1143 disable profiling. Must run in TensorFlow eager mode.
AttributeError: 'NoneType' object has no attribute 'fetches'
需要帮助!
发布于 2019-03-16 06:22:07
这些文件指出:
histogram_freq:用于计算模型各层的激活和权重直方图的频率(以年代为单位)。如果设置为0,则不会计算直方图。必须为直方图可视化指定验证数据(或拆分)。
设置histogram_freq =1使它在每一个时期都计算直方图。因此出现了错误。将其设置为0不会计算直方图,而将其设置为5将计算每5周期一次的直方图。
发布于 2019-07-30 18:15:11
必须在validation_data
中设置fit
以使用histogram_freq
。
只需以(x,y)或数据集/数据集迭代器的格式传入一些数据。
这很好,因为它允许您使用与您在张量板中的培训不同的数据集。
model = create_model()
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
log_dir="logs/fit/" +
datetime.datetime.now().strftime("%Y%m%d-%H%M%S") tensorboard_callback
= tf.keras.callbacks.TensorBoard(log_dir=log_dir, histogram_freq=1)
model.fit(x=x_train, # works with generator/iterator datasets, too.
y=y_train,
epochs=5,
--------> validation_data=(x_test, y_test), # or pass in your dataset iterator/generator
callbacks=[tensorboard_callback])
使用回调文档的TF示例:modelfit
然后,启动坦索恩板:
tensorboard --logdir=path/to/logs/
https://stackoverflow.com/questions/55085661
复制相似问题