tensorflow / tensorflow/models

Big computational overhead for inference run?

Open
#8,251 0 comments 0 reactions 1 assignee View on GitHub

@aquariusjay is already working on this.

Since May 14, 2020.

models:research type:support
Dominant language
Python
Stars
77.7k
Forks
44.8k
PR merge metrics
No merged PRs in 30d

Description

Dear fellow developers,

I have been trying to run Deeplab v3+ with real time inference on a video, so the actual runtime for each inference is really critical to me. If I wanted to maintain 30fps, it means each inference call should take less than 30ms. However, when I tried 3 different models with much different compute, the runtime are slow and unexpected:

I went with the mobilenetv2 frozen inference graph from the official site.

Below are the three model I tried out and the code below is modified from the official Colaboratory sample by adding a simple time.time() before and after sess.run(...) to see how much time it takes per inference call.
name of model : multiply-adds
mobilenetv2_dm05_coco_voc_trainaug : 0.88B
mobilenetv2_coco_voc_trainval : 152.59B
xception65_coco_voc_trainval : 3055.35B

However I found on my i7 machine the runtimes for inferencing one image are:

mobilenetv2_dm05_coco_voc_trainaug : 170ms
mobilenetv2_coco_voc_trainval : 300ms
xception65_coco_voc_trainval : 2.5s

I'm especially confused by the first 2 models, as their multiply-adds count differ by 100 times but why the first model still takes similar amount of time for the inference_call? I was hoping it could be ~ 100 times faster so be suitable for the 30fps realtime segmentation. Does this mean there is some big overhead in the inference call? If yes, are there ways to shave them off?

Could you please advise? Thank you so much!

Best,
Bo

`
def run(self, image):
"""Runs inference on a single image.

Args:
  image: A PIL.Image object, raw input image.

Returns:
  resized_image: RGB image resized from original input image.
  seg_map: Segmentation map of `resized_image`.
"""
width, height = image.size
resize_ratio = 1.0 * self.INPUT_SIZE / max(width, height)
target_size = (int(resize_ratio * width), int(resize_ratio * height))
resized_image = image.convert('RGB').resize(target_size, Image.ANTIALIAS)

oldtime = time.time()

batch_seg_map = self.sess.run(
    self.OUTPUT_TENSOR_NAME,
    feed_dict={self.INPUT_TENSOR_NAME: [np.asarray(resized_image)]})

newtime = time.time()
print(newtime-oldtime)

seg_map = batch_seg_map[0]
return resized_image, seg_map

`

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.