0

I'm trying to build an app that uses Tensorflow 2 custom trained object detection model which i succeeded but now that I'm trying to track the detected objects to create statistics about time on screen and the amount of objects with unique id captured by the screen or video.

The problem is i can't find any guides or example using Object Tracker such as DeepSORT for which there are sources using it with Tensorflow such as this one. The problem is that it uses Tensorflow 1 to obtain a feature extractor from the saved_model.pb and from which this source code:

class ImageEncoder(object):

def __init__(self, checkpoint_filename, input_name="images",
             output_name="features"):
    self.session = tf.Session()
    with tf.gfile.GFile(checkpoint_filename, "rb") as file_handle:
        graph_def = tf.GraphDef()
        graph_def.ParseFromString(file_handle.read())
    tf.import_graph_def(graph_def, name="net")
    self.input_var = tf.get_default_graph().get_tensor_by_name(
        "%s:0" % input_name)
    self.output_var = tf.get_default_graph().get_tensor_by_name(
        "%s:0" % output_name)

    assert len(self.output_var.get_shape()) == 2
    assert len(self.input_var.get_shape()) == 4
    self.feature_dim = self.output_var.get_shape().as_list()[-1]
    self.image_shape = self.input_var.get_shape().as_list()[1:]

def __call__(self, data_x, batch_size=32):
    out = np.zeros((len(data_x), self.feature_dim), np.float32)
    _run_in_batches(
        lambda x: self.session.run(self.output_var, feed_dict=x),
        {self.input_var: data_x}, out, batch_size)
    return out

To which im passing the path to the saved_model.pb but throws this error.

line 83, in __init__
graph_def.ParseFromString(file_handle.read())
google.protobuf.message.DecodeError: Error parsing message with type 'tensorflow.GraphDef'

My limited knowledge is from using tensorflow 2 object detection tutorial found here, so I'm puzzled on how to continue and i just have questions such as:

Can i extract features from Tensorflow 2 Object Detection saved_model.pb (exported by using the same library of TF2)?

And/or how can i change the source code to accept a TF2 Object Detection model?

SaltyCode
  • 67
  • 1
  • 2
  • 11

0 Answers0