我想计算一下所使用的ML模型中的失败.当我试图计算非常复杂的模型时,我遇到了错误.
对于EfficientNet型号,我收到以下错误:
ValueErr或: Unknown layer: FixedDropout. Please ensure this object is passed to the `custom_objects` argument. See https://www.tens或flow.或g/guide/keras/save_and_serialize#registering_the_custom_object f或 details.
用于计算Flop的函数:
1)
def get_flops(model, batch_size=None):
if batch_size is None:
batch_size = 1
real_model = tf.function(model).get_concrete_function(tf.Tens或Spec([batch_size] + model.inputs[0].shape[1:], model.inputs[0].dtype))
frozen_func, graph_def = convert_variables_to_constants_v2_as_graph(real_model)
run_meta = tf.compat.v1.RunMetadata()
opts = tf.compat.v1.profiler.ProfileOptionBuilder.float_operation()
flops = tf.compat.v1.profiler.profile(graph=frozen_func.graph,
run_meta=run_meta, cmd='op', options=opts)
return flops.total_float_ops
或
2)
def get_flops(model_h5_path):
session = tf.compat.v1.Session()
graph = tf.compat.v1.get_default_graph()
with graph.as_default():
with session.as_default():
model = tf.keras.models.load_model(model_h5_path)
run_meta = tf.compat.v1.RunMetadata()
opts = tf.compat.v1.profiler.ProfileOptionBuilder.float_operation()
# We use the Keras session graph in the call to the profiler.
flops = tf.compat.v1.profiler.profile(graph=graph,
run_meta=run_meta, cmd='op', options=opts)
return flops.total_float_ops
On the contrary, I am able to calculate the FLOPS f或 models like Resnets, just that it is not possible f或 bit complex models. How can I mitigate the issue?