在GPflow中有没有可能会失败呢?我找到了一个使用Tensorflow的示例,但不知道如何在GPflow上下文中使用它:
g = tf.Graph()
run_meta = tf.RunMetadata()
with g.as_default():
A = tf.Variable(tf.random_normal( [25,16] ))
B = tf.Variable(tf.random_normal( [16,9] ))
C = tf.matmul(A,B)
opts = tf.profiler.ProfileOptionBuilder.float_operation()
flops = tf.profiler.profile(g, run_meta=run_meta, cmd='op', options=opts)
if flops is not None:
print('TF stats gives',flops.total_float_ops)发布于 2019-11-14 23:04:55
我在GPFlow的源代码中挖掘了一点。让它工作的关键是在GPFlow的AutoFlows创建新图形之前拦截您想要分析的Tensorflow操作。
在我的例子中,我想分析predict()函数。您需要的函数是model._build_predict() (对数似然函数有一个等价物)。下面是它的工作原理:
gpflow.reset_default_graph_and_session()
kernel = gpflow.kernels.RBF(1)
model = gpflow.models.GPR(X, Y, kernel)
run_metadata = tf.RunMetadata()
with model.enquire_session(session=None) as tf_session:
predict_op = model._build_predict(X)
tf_session.run(predict_op, options=tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE),
run_metadata=run_metadata)
opts = tf.profiler.ProfileOptionBuilder.float_operation()
prof = tf.profiler.profile(tf_session.graph, run_meta=run_metadata,
cmd='op', options=opts)
print('FOps: ', prof.total_float_ops)https://stackoverflow.com/questions/56290008
复制相似问题