当前位置: 首页>>代码示例>>Python>>正文


Python graph_rewriter_pb2.GraphRewriter方法代码示例

本文整理汇总了Python中object_detection.protos.graph_rewriter_pb2.GraphRewriter方法的典型用法代码示例。如果您正苦于以下问题:Python graph_rewriter_pb2.GraphRewriter方法的具体用法?Python graph_rewriter_pb2.GraphRewriter怎么用?Python graph_rewriter_pb2.GraphRewriter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在object_detection.protos.graph_rewriter_pb2的用法示例。


在下文中一共展示了graph_rewriter_pb2.GraphRewriter方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _save_checkpoint_from_mock_model

# 需要导入模块: from object_detection.protos import graph_rewriter_pb2 [as 别名]
# 或者: from object_detection.protos.graph_rewriter_pb2 import GraphRewriter [as 别名]
def _save_checkpoint_from_mock_model(self,
                                       checkpoint_path,
                                       use_moving_averages,
                                       enable_quantization=False):
    g = tf.Graph()
    with g.as_default():
      mock_model = FakeModel()
      preprocessed_inputs, true_image_shapes = mock_model.preprocess(
          tf.placeholder(tf.float32, shape=[None, None, None, 3]))
      predictions = mock_model.predict(preprocessed_inputs, true_image_shapes)
      mock_model.postprocess(predictions, true_image_shapes)
      if use_moving_averages:
        tf.train.ExponentialMovingAverage(0.0).apply()
      tf.train.get_or_create_global_step()
      if enable_quantization:
        graph_rewriter_config = graph_rewriter_pb2.GraphRewriter()
        graph_rewriter_config.quantization.delay = 500000
        graph_rewriter_fn = graph_rewriter_builder.build(
            graph_rewriter_config, is_training=False)
        graph_rewriter_fn()
      saver = tf.train.Saver()
      init = tf.global_variables_initializer()
      with self.test_session() as sess:
        sess.run(init)
        saver.save(sess, checkpoint_path) 
开发者ID:ahmetozlu,项目名称:vehicle_counting_tensorflow,代码行数:27,代码来源:exporter_test.py

示例2: testQuantizationBuilderSetsUpCorrectTrainArguments

# 需要导入模块: from object_detection.protos import graph_rewriter_pb2 [as 别名]
# 或者: from object_detection.protos.graph_rewriter_pb2 import GraphRewriter [as 别名]
def testQuantizationBuilderSetsUpCorrectTrainArguments(self):
    with mock.patch.object(
        tf.contrib.quantize, 'create_training_graph') as mock_quant_fn:
      with mock.patch.object(tf.contrib.layers,
                             'summarize_collection') as mock_summarize_col:
        graph_rewriter_proto = graph_rewriter_pb2.GraphRewriter()
        graph_rewriter_proto.quantization.delay = 10
        graph_rewriter_proto.quantization.weight_bits = 8
        graph_rewriter_proto.quantization.activation_bits = 8
        graph_rewrite_fn = graph_rewriter_builder.build(
            graph_rewriter_proto, is_training=True)
        graph_rewrite_fn()
        _, kwargs = mock_quant_fn.call_args
        self.assertEqual(kwargs['input_graph'], tf.get_default_graph())
        self.assertEqual(kwargs['quant_delay'], 10)
        mock_summarize_col.assert_called_with('quant_vars') 
开发者ID:ahmetozlu,项目名称:vehicle_counting_tensorflow,代码行数:18,代码来源:graph_rewriter_builder_test.py

示例3: _save_checkpoint_from_mock_model

# 需要导入模块: from object_detection.protos import graph_rewriter_pb2 [as 别名]
# 或者: from object_detection.protos.graph_rewriter_pb2 import GraphRewriter [as 别名]
def _save_checkpoint_from_mock_model(self,
                                       checkpoint_path,
                                       use_moving_averages,
                                       quantize=False,
                                       num_channels=3):
    g = tf.Graph()
    with g.as_default():
      mock_model = FakeModel()
      inputs = tf.placeholder(tf.float32, shape=[1, 10, 10, num_channels])
      mock_model.predict(inputs, true_image_shapes=None)
      if use_moving_averages:
        tf.train.ExponentialMovingAverage(0.0).apply()
      tf.train.get_or_create_global_step()
      if quantize:
        graph_rewriter_config = graph_rewriter_pb2.GraphRewriter()
        graph_rewriter_config.quantization.delay = 500000
        graph_rewriter_fn = graph_rewriter_builder.build(
            graph_rewriter_config, is_training=False)
        graph_rewriter_fn()

      saver = tf.train.Saver()
      init = tf.global_variables_initializer()
      with self.test_session() as sess:
        sess.run(init)
        saver.save(sess, checkpoint_path) 
开发者ID:ahmetozlu,项目名称:vehicle_counting_tensorflow,代码行数:27,代码来源:export_tflite_ssd_graph_lib_test.py

示例4: testQuantizationBuilderSetsUpCorrectTrainArguments

# 需要导入模块: from object_detection.protos import graph_rewriter_pb2 [as 别名]
# 或者: from object_detection.protos.graph_rewriter_pb2 import GraphRewriter [as 别名]
def testQuantizationBuilderSetsUpCorrectTrainArguments(self):
    with mock.patch.object(
        tf.contrib.quantize,
        'experimental_create_training_graph') as mock_quant_fn:
      with mock.patch.object(tf.contrib.layers,
                             'summarize_collection') as mock_summarize_col:
        graph_rewriter_proto = graph_rewriter_pb2.GraphRewriter()
        graph_rewriter_proto.quantization.delay = 10
        graph_rewriter_proto.quantization.weight_bits = 8
        graph_rewriter_proto.quantization.activation_bits = 8
        graph_rewrite_fn = graph_rewriter_builder.build(
            graph_rewriter_proto, is_training=True)
        graph_rewrite_fn()
        _, kwargs = mock_quant_fn.call_args
        self.assertEqual(kwargs['input_graph'], tf.get_default_graph())
        self.assertEqual(kwargs['quant_delay'], 10)
        mock_summarize_col.assert_called_with('quant_vars') 
开发者ID:ShivangShekhar,项目名称:Live-feed-object-device-identification-using-Tensorflow-and-OpenCV,代码行数:19,代码来源:graph_rewriter_builder_test.py

示例5: test_rewrite_nn_resize_op_quantized_odd_size

# 需要导入模块: from object_detection.protos import graph_rewriter_pb2 [as 别名]
# 或者: from object_detection.protos.graph_rewriter_pb2 import GraphRewriter [as 别名]
def test_rewrite_nn_resize_op_quantized_odd_size(self):
    g = tf.Graph()
    with g.as_default():
      x = array_ops.placeholder(dtypes.float32, shape=(8, 10, 10, 8))
      x_conv = slim.conv2d(x, 8, 1)
      s = ops.nearest_neighbor_upsampling(x_conv, 2)
      t = s[:, :19, :19, :]

      graph_rewriter_config = graph_rewriter_pb2.GraphRewriter()
      graph_rewriter_config.quantization.delay = 500000
      graph_rewriter_fn = graph_rewriter_builder.build(
          graph_rewriter_config, is_training=False)
      graph_rewriter_fn()

      exporter.rewrite_nn_resize_op(is_quantized=True)

    resize_op_found = False
    for op in g.get_operations():
      if op.type == 'ResizeNearestNeighbor':
        resize_op_found = True
        self.assertEqual(op.inputs[0].op.type, 'FakeQuantWithMinMaxVars')
        self.assertEqual(op.outputs[0].consumers()[0], t.op)
        break

    self.assertTrue(resize_op_found) 
开发者ID:tensorflow,项目名称:models,代码行数:27,代码来源:exporter_tf1_test.py

示例6: testQuantizationBuilderSetsUpCorrectTrainArguments

# 需要导入模块: from object_detection.protos import graph_rewriter_pb2 [as 别名]
# 或者: from object_detection.protos.graph_rewriter_pb2 import GraphRewriter [as 别名]
def testQuantizationBuilderSetsUpCorrectTrainArguments(self):
    with mock.patch.object(
        contrib_quantize,
        'experimental_create_training_graph') as mock_quant_fn:
      with mock.patch.object(slim,
                             'summarize_collection') as mock_summarize_col:
        graph_rewriter_proto = graph_rewriter_pb2.GraphRewriter()
        graph_rewriter_proto.quantization.delay = 10
        graph_rewriter_proto.quantization.weight_bits = 8
        graph_rewriter_proto.quantization.activation_bits = 8
        graph_rewrite_fn = graph_rewriter_builder.build(
            graph_rewriter_proto, is_training=True)
        graph_rewrite_fn()
        _, kwargs = mock_quant_fn.call_args
        self.assertEqual(kwargs['input_graph'], tf.get_default_graph())
        self.assertEqual(kwargs['quant_delay'], 10)
        mock_summarize_col.assert_called_with('quant_vars') 
开发者ID:tensorflow,项目名称:models,代码行数:19,代码来源:graph_rewriter_builder_tf1_test.py

示例7: testQuantizationBuilderSetsUpCorrectTrainArguments

# 需要导入模块: from object_detection.protos import graph_rewriter_pb2 [as 别名]
# 或者: from object_detection.protos.graph_rewriter_pb2 import GraphRewriter [as 别名]
def testQuantizationBuilderSetsUpCorrectTrainArguments(self):
    with mock.patch.object(
        contrib_quantize,
        'experimental_create_training_graph') as mock_quant_fn:
      with mock.patch.object(contrib_layers,
                             'summarize_collection') as mock_summarize_col:
        graph_rewriter_proto = graph_rewriter_pb2.GraphRewriter()
        graph_rewriter_proto.quantization.delay = 10
        graph_rewriter_proto.quantization.weight_bits = 8
        graph_rewriter_proto.quantization.activation_bits = 8
        graph_rewrite_fn = graph_rewriter_builder.build(
            graph_rewriter_proto, is_training=True)
        graph_rewrite_fn()
        _, kwargs = mock_quant_fn.call_args
        self.assertEqual(kwargs['input_graph'], tf.get_default_graph())
        self.assertEqual(kwargs['quant_delay'], 10)
        mock_summarize_col.assert_called_with('quant_vars') 
开发者ID:tensorflow,项目名称:models,代码行数:19,代码来源:graph_rewriter_builder_test.py

示例8: get_graph_rewriter_config_from_file

# 需要导入模块: from object_detection.protos import graph_rewriter_pb2 [as 别名]
# 或者: from object_detection.protos.graph_rewriter_pb2 import GraphRewriter [as 别名]
def get_graph_rewriter_config_from_file(graph_rewriter_config_file):
  """Parses config for graph rewriter.

  Args:
    graph_rewriter_config_file: file path to the graph rewriter config.

  Returns:
    graph_rewriter_pb2.GraphRewriter proto
  """
  graph_rewriter_config = graph_rewriter_pb2.GraphRewriter()
  with tf.gfile.GFile(graph_rewriter_config_file, "r") as f:
    text_format.Merge(f.read(), graph_rewriter_config)
  return graph_rewriter_config 
开发者ID:ahmetozlu,项目名称:vehicle_counting_tensorflow,代码行数:15,代码来源:config_util.py

示例9: test_rewrite_nn_resize_op_quantized

# 需要导入模块: from object_detection.protos import graph_rewriter_pb2 [as 别名]
# 或者: from object_detection.protos.graph_rewriter_pb2 import GraphRewriter [as 别名]
def test_rewrite_nn_resize_op_quantized(self):
    g = tf.Graph()
    with g.as_default():
      x = array_ops.placeholder(dtypes.float32, shape=(8, 10, 10, 8))
      x_conv = tf.contrib.slim.conv2d(x, 8, 1)
      y = array_ops.placeholder(dtypes.float32, shape=(8, 20, 20, 8))
      s = ops.nearest_neighbor_upsampling(x_conv, 2)
      t = s + y

      graph_rewriter_config = graph_rewriter_pb2.GraphRewriter()
      graph_rewriter_config.quantization.delay = 500000
      graph_rewriter_fn = graph_rewriter_builder.build(
          graph_rewriter_config, is_training=False)
      graph_rewriter_fn()

      exporter.rewrite_nn_resize_op(is_quantized=True)

    resize_op_found = False
    for op in g.get_operations():
      if op.type == 'ResizeNearestNeighbor':
        resize_op_found = True
        self.assertEqual(op.inputs[0].op.type, 'FakeQuantWithMinMaxVars')
        self.assertEqual(op.outputs[0].consumers()[0], t.op)
        break

    self.assertTrue(resize_op_found) 
开发者ID:ahmetozlu,项目名称:vehicle_counting_tensorflow,代码行数:28,代码来源:exporter_test.py

示例10: testQuantizationBuilderSetsUpCorrectEvalArguments

# 需要导入模块: from object_detection.protos import graph_rewriter_pb2 [as 别名]
# 或者: from object_detection.protos.graph_rewriter_pb2 import GraphRewriter [as 别名]
def testQuantizationBuilderSetsUpCorrectEvalArguments(self):
    with mock.patch.object(tf.contrib.quantize,
                           'create_eval_graph') as mock_quant_fn:
      with mock.patch.object(tf.contrib.layers,
                             'summarize_collection') as mock_summarize_col:
        graph_rewriter_proto = graph_rewriter_pb2.GraphRewriter()
        graph_rewriter_proto.quantization.delay = 10
        graph_rewrite_fn = graph_rewriter_builder.build(
            graph_rewriter_proto, is_training=False)
        graph_rewrite_fn()
        _, kwargs = mock_quant_fn.call_args
        self.assertEqual(kwargs['input_graph'], tf.get_default_graph())
        mock_summarize_col.assert_called_with('quant_vars') 
开发者ID:ambakick,项目名称:Person-Detection-and-Tracking,代码行数:15,代码来源:graph_rewriter_builder_test.py

示例11: testQuantizationBuilderSetsUpCorrectEvalArguments

# 需要导入模块: from object_detection.protos import graph_rewriter_pb2 [as 别名]
# 或者: from object_detection.protos.graph_rewriter_pb2 import GraphRewriter [as 别名]
def testQuantizationBuilderSetsUpCorrectEvalArguments(self):
    with mock.patch.object(tf.contrib.quantize,
                           'experimental_create_eval_graph') as mock_quant_fn:
      with mock.patch.object(tf.contrib.layers,
                             'summarize_collection') as mock_summarize_col:
        graph_rewriter_proto = graph_rewriter_pb2.GraphRewriter()
        graph_rewriter_proto.quantization.delay = 10
        graph_rewrite_fn = graph_rewriter_builder.build(
            graph_rewriter_proto, is_training=False)
        graph_rewrite_fn()
        _, kwargs = mock_quant_fn.call_args
        self.assertEqual(kwargs['input_graph'], tf.get_default_graph())
        mock_summarize_col.assert_called_with('quant_vars') 
开发者ID:ShivangShekhar,项目名称:Live-feed-object-device-identification-using-Tensorflow-and-OpenCV,代码行数:15,代码来源:graph_rewriter_builder_test.py


注:本文中的object_detection.protos.graph_rewriter_pb2.GraphRewriter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。