0

I am working with MobileNetv2, and using deeplab as the preprocessor (if that's the right term?). I have done transfer learning to train the example network on my own dataset, creating .meta, .index and .pbtxt files. When I try to convert these to a pb file, I have hit a number of problems.

freeze_graph.py needs to know the output_node_names. If I were using InceptionV3 instead of deeplab, that would be "InceptionV3/Predictions/Reshape_1". Elsewhere I have seen people use "softmax".

  1. I have tried listing the node names with

    print([node.name for node in graph.as_graph_def().node])

but that list is way too long. Searching for variations of "prediction", "output", "reshape", "softmax" didn't reveal anything promising.

  1. I had a look on the tensorboard, but I was overwhelmed by the complexity of the diagram. I couldn't find anything which looked like an output node.

  2. Some people suggest bazel, but when I tried

    bazel build tensorflow/tools/graph_transforms:summarize_graph

I get

ERROR: no such package 'tensorflow/tools/graph_transforms': BUILD file not found on package path`

Edit: in case it is relevant, I used the mobilenetv2_coco_voc_trainaug checkpoint as the starting point for my transfer learning from https://github.com/tensorflow/models/blob/master/research/deeplab/g3doc/model_zoo.md

craq
  • 1,441
  • 2
  • 20
  • 39

1 Answers1

1

Given that the code to generate the graph is on github, I'd just construct it from scratch and check the final name.

import tensorflow as tf
# you'll need `models/research/slim` on your PYTHONPATH FOR THE FOLLOWING
from nets.mobilenet import mobilenet_v2

image = tf.zeros((1, 224, 224, 3), dtype=tf.float32)  # values don't matter
out, endpoints = mobilenet_v2.mobilenet(image)
print(out.name)
DomJack
  • 4,098
  • 1
  • 17
  • 32
  • thanks, that looks promising. I added `import sys` `sys.path.append('/path/to/models/research/slim')` to make sure mobilenet was on my PYTHONPATH. But I still ran into an error: `from tensorflow.contrib import batching ImportError: cannot import name batching`. What is name batching? Any idea how I can work around that error? – craq Aug 28 '18 at 23:25
  • What version of tensorflow are you using? You might have to use earlier versions of the models repository. – DomJack Aug 29 '18 at 01:09
  • I can confirm its in version 1.10 - not sure about earlier. – DomJack Aug 29 '18 at 01:10
  • the tensorflow repo (https://github.com/tensorflow/tensorflow) doesn't include mobilenet, so I assume you mean the models repo (https://github.com/tensorflow/models). I have just updated that repo, but I can't see a version number. `tf.__version__` gives 1.8.0, which is what I installed with pip. – craq Aug 29 '18 at 01:40
  • The models repo is calling tensorflow, and the issue is that it is expecting a later version of tensorflow than you have installed. You can either go searching for an earlier node in the models repo, or upgrade your tensorflow version. – DomJack Aug 29 '18 at 04:37
  • after upgrading tensorflow, your script is working - thanks for that. It gives `MobilenetV2/Logits/output:0` as an output, but when I try to search for this in tensorboard or by `print([node.name for node in graph.as_graph_def().node if node.name in (u'MobilenetV2/Logits')])` (or any substring) it comes up empty. When I try to freeze the graph I get `AssertionError: MobilenetV2/Logits/output is not in graph`. – craq Aug 29 '18 at 22:50
  • What do you get if you do `print([node.name for node in graph.as_graph_def().node if 'MobilenetV2/Logits' in node.name])`? I'm not 100% sure on tensorflow's naming convention when it comes to ops, tensors etc in frozen graphs, but I suspect you'll be missing a `:0` or something. – DomJack Aug 29 '18 at 22:54
  • I tried with and without a `:0`. I tried every substring of `MobilenetV2/Logits/output:0` I could think of. Using something like `u'gradients/AddN_9'` returns multiple results: `[u'AddN', u'gradients/AddN', u'gradients/AddN_9', u'AddN_9']` – craq Aug 29 '18 at 23:19