Moblenet V2:将具有较低生产者版本的图形导入具有较高生产者版本的图形

Moblenet V2: Importing graph with lower producer version into a graph with higher producer version

我正在开发一个迁移学习应用程序,我正在为我的数据流重新训练 MobileNetV2。

我正在使用来自 tensorflow-hub 的 retrain.py 重新训练模型并且没有做任何修改。

当我从终端 运行 脚本时,我在模型下载到我的用户配置文件中的临时目录后直接收到此警告。

Importing a graph with a lower producer version 26 into an existing graph with producer 
version 27. Shape inference will have run different parts of the graph with different 
producer versions.

在调试过程中,我创建了一个 test.py 脚本来找出警告的来源:

import tensorflow as tf
import tensorflow_hub as hub

def create_module_graph(module_spec):
  """Creates a graph and loads Hub Module into it.

  Args:
    module_spec: the hub.ModuleSpec for the image module being used.

  Returns:
    graph: the tf.Graph that was created.
    bottleneck_tensor: the bottleneck values output by the module.
    resized_input_tensor: the input images, resized as expected by the module.
    wants_quantization: a boolean, whether the module has been instrumented
      with fake quantization ops.
  """
  FAKE_QUANT_OPS = ('FakeQuantWithMinMaxVars',
                     'FakeQuantWithMinMaxVarsPerChannel')
  height, width = hub.get_expected_image_size(module_spec)
  with tf.Graph().as_default() as graph:
    resized_input_tensor = tf.placeholder(tf.float32, [None, height, width, 3])
    m = hub.Module(module_spec)
    bottleneck_tensor = m(resized_input_tensor)
    wants_quantization = any(node.op in FAKE_QUANT_OPS
                             for node in graph.as_graph_def().node)
  return graph, bottleneck_tensor, resized_input_tensor, wants_quantization


def main():



   module_spec = hub.load_module_spec('https://tfhub.dev/google/imagenet/mobilenet_v2_100_96/classification/2')

   graph, bottleneck_tensor, resized_input_tensor, wants_quantization = create_module_graph(module_spec)



if __name__ =='__main__':
   main()

发现它起源于retrain.py中的create_module_graph函数。当我 运行 来自终端的脚本使用 python test.py 时,我从上面收到生产者警告。但是,当我从 ipython 控制台 运行 main() 时,我没有收到生产者版本警告。

我不确定为什么会发生这种情况,而我所做的只是从 tensorflow-hub 存储库创建图表。我看了version compatibility docs and did not see anything particularly relevant to the error. Looking through the source code,好像是我的图降到最低版本才建的

  1. 这有什么好担心的吗?
  2. 它会改变您加载图表以进行预测的方式吗?

来自我的 tensorflow-hub issue:

TensorFlow Hub 模块的核心包含 tf.GraphDefs,这些模块具有格式版本号,可帮助将图形正确导入较新版本的 TensorFlow。巧合的是,在为 2018 年 3 月 31 日 public 发布的 TF-Hub 模块上传和当前的 TensorFlow 版本之间,此格式版本从 26 增加到 27。

但是,我们目前尚未发现所报告的形状推断变化对模块用户有任何可见影响,因此我们目前的建议是忽略这些警告。他们将与 下次刷新模块。