我正在尝试使用我在网上获得的以下代码找出我的模型使用的 FLOPS 数量:
def get_flops(model):
run_meta = tf.RunMetadata()
opts = tf.profiler.ProfileOptionBuilder.float_operation()
# We use the Keras session graph in the call to the profiler.
flops = tf.profiler.profile(graph=K.get_session().graph,
run_meta=run_meta, cmd='op', options=opts)
return flops.total_float_ops # Prints the "flops" of the model.
# .... Define your model here ....
print(get_flops(model))
但是,运行此代码会给我这个错误:
Traceback (most recent call last):
File "/Users/Desktop/FYP/Code/Python/code/main.py", line 243, in <module>
print(get_flops(model))
File "/Users/Desktop/FYP/Code/Python/code/main.py", line 232, in get_flops
run_meta = tf.RunMetadata()
AttributeError: module 'tensorflow' has no attribute 'RunMetadata'
我怎样才能绕过这个错误?我已经在线阅读,我得到的唯一帮助是更新我的 tensorflow 版本。但是,这是最新的版本。