abdou_dev
abdou_dev

Reputation: 827

Why tf.profiles returns a none value for flops?

I'm newer in the deep learning domain, I have a frozen graph model that was trained to detect eye region landmarks. I would like to get the number of flops of this model. I have used a code that I got from a solution posted on Stackoverflow. The problem is when I test the code, the result returned showing a none value for the number of flops.

import os
import tensorflow as tf
from tensorflow.core.framework import graph_pb2
from tensorflow.python.framework import importer
from tensorflow.python.framework import graph_util


os.environ['CUDA_VISIBLE_DEVICES'] = '0'

pb_path = 'graph_300VW_opimized.pb'
def load_pb(pb):
    with tf.gfile.GFile(pb, "rb") as f:
        graph_def = tf.GraphDef()
        graph_def.ParseFromString(f.read())
    with tf.Graph().as_default() as graph:
        tf.import_graph_def(graph_def, name='')
        return graph

'''
run_meta = tf.RunMetadata()
with tf.Graph().as_default():
    output_graph_def = graph_pb2.GraphDef()
    with open(pb_path, "rb") as f:
        output_graph_def.ParseFromString(f.read())
        _ = importer.import_graph_def(output_graph_def, name="")
        print('model loaded!')
    all_keys = sorted([n.name for n in tf.get_default_graph().as_graph_def().node])
    # for k in all_keys:
    #   print(k)

    with tf.Session() as sess:
        flops = tf.profiler.profile(tf.get_default_graph(), run_meta=run_meta,
            options=tf.profiler.ProfileOptionBuilder.float_operation())
        print("test flops:{:,}".format(flops.total_float_ops))
'''
g2 = load_pb('./frozen_model_300VW5.pb')
with g2.as_default():
    flops = tf.profiler.profile(g2, options = tf.profiler.ProfileOptionBuilder.float_operation())
    print('FLOP after freezing', flops.total_float_ops)

Logs:

==================Model Analysis Report======================

Doc: scope: The nodes in the model graph are organized by their names, which is hierarchical like filesystem. flops: Number of float operations. Note: Please read the implementation for the math behind it.

Profile: node name | # float_ops _TFProfRoot (--/0 flops)

======================End of Report==========================

FLOP after freezing 0

I would like to know the reason of why I got a none value of the number of flops?

Upvotes: 1

Views: 205

Answers (0)

Related Questions