tensorflow – 分析keras模型时出错

我想根据这个
comment on github描述我的Keras模型.我使用tens.flow标记的Tf.Keras API:1.9.0-rc2和Keras版本:2.1.6-tf.

run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
run_metadata = tf.RunMetadata()

training_set = load_datasets(...) 
model.compile(loss=helpers.mean_categorical_crossentropy,optimizer='adam',options=run_options,run_metadata=run_metadata)
model.fit(training_set.make_one_shot_iterator(), steps_per_epoch=steps_per_epoch_train,epochs=num_epochs, verbose=2)

trace = timeline.Timeline(step_stats=run_metadata.step_stats)
with open('timeline.ctf.json', 'w') as f:
    f.write(trace.generate_chrome_trace_format())

错误

(‘Some keys in session_kwargs are not supported at this time: %s’,
dict_keys([‘options’, ‘run_metadata’]))

在另一个github post,有人给出了这个例子,并以某种方式运行没有错误.然而,我得到与上面相同的错误.

import keras
from keras.layers.core import Dense
from keras.models import Sequential
import tensorflow as tf
from tensorflow.python.client import timeline
import numpy as np

x = np.random.randn(10000, 2)
y = (x[:, 0] * x[:, 1]) > 0 # xor
run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
run_metadata = tf.RunMetadata()
model = Sequential()
model.add(Dense(units=64, activation='relu', input_dim=2))
model.add(Dense(units=2, activation='softmax'))
model.compile(loss='categorical_crossentropy',
              optimizer='sgd',
              options=run_options,
              run_metadata=run_metadata)
model.fit(x, keras.utils.to_categorical(y), epochs=1)
trace = timeline.Timeline(step_stats=run_metadata.step_stats)
with open('timeline.ctf.json', 'w') as f:
    f.write(trace.generate_chrome_trace_format())

我还在github上发现了这个issue,这表明使用Keras模型的分析尚未实现.我很迷惑.

有人知道怎么解决吗?

最佳答案 有一个拉取请求可以解决这个问题:
https://github.com/tensorflow/tensorflow/pull/19932

它还没有合并到master,但我通过在本地合并它,或者只是手动将更改应用到已安装的tensorflow库来实现它

点赞