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


Python ops.nearest_neighbor_upsampling方法代码示例

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


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

示例1: test_rewrite_nn_resize_op

# 需要导入模块: from object_detection.utils import ops [as 别名]
# 或者: from object_detection.utils.ops import nearest_neighbor_upsampling [as 别名]
def test_rewrite_nn_resize_op(self):
    g = tf.Graph()
    with g.as_default():
      x = array_ops.placeholder(dtypes.float32, shape=(8, 10, 10, 8))
      y = array_ops.placeholder(dtypes.float32, shape=(8, 20, 20, 8))
      s = ops.nearest_neighbor_upsampling(x, 2)
      t = s + y
      exporter.rewrite_nn_resize_op()

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

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

示例2: test_rewrite_nn_resize_op_odd_size

# 需要导入模块: from object_detection.utils import ops [as 别名]
# 或者: from object_detection.utils.ops import nearest_neighbor_upsampling [as 别名]
def test_rewrite_nn_resize_op_odd_size(self):
    g = tf.Graph()
    with g.as_default():
      x = array_ops.placeholder(dtypes.float32, shape=(8, 10, 10, 8))
      s = ops.nearest_neighbor_upsampling(x, 2)
      t = s[:, :19, :19, :]
      exporter.rewrite_nn_resize_op()

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

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

示例3: test_rewrite_nn_resize_op_quantized_odd_size

# 需要导入模块: from object_detection.utils import ops [as 别名]
# 或者: from object_detection.utils.ops import nearest_neighbor_upsampling [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

示例4: test_upsampling_with_single_scale

# 需要导入模块: from object_detection.utils import ops [as 别名]
# 或者: from object_detection.utils.ops import nearest_neighbor_upsampling [as 别名]
def test_upsampling_with_single_scale(self):

    def graph_fn(inputs):
      custom_op_output = ops.nearest_neighbor_upsampling(inputs, scale=2)
      return custom_op_output
    inputs = np.reshape(np.arange(4).astype(np.float32), [1, 2, 2, 1])
    custom_op_output = self.execute(graph_fn, [inputs])

    expected_output = [[[[0], [0], [1], [1]],
                        [[0], [0], [1], [1]],
                        [[2], [2], [3], [3]],
                        [[2], [2], [3], [3]]]]
    self.assertAllClose(custom_op_output, expected_output) 
开发者ID:ahmetozlu,项目名称:vehicle_counting_tensorflow,代码行数:15,代码来源:ops_test.py

示例5: test_upsampling_with_separate_height_width_scales

# 需要导入模块: from object_detection.utils import ops [as 别名]
# 或者: from object_detection.utils.ops import nearest_neighbor_upsampling [as 别名]
def test_upsampling_with_separate_height_width_scales(self):

    def graph_fn(inputs):
      custom_op_output = ops.nearest_neighbor_upsampling(inputs,
                                                         height_scale=2,
                                                         width_scale=3)
      return custom_op_output
    inputs = np.reshape(np.arange(4).astype(np.float32), [1, 2, 2, 1])
    custom_op_output = self.execute(graph_fn, [inputs])

    expected_output = [[[[0], [0], [0], [1], [1], [1]],
                        [[0], [0], [0], [1], [1], [1]],
                        [[2], [2], [2], [3], [3], [3]],
                        [[2], [2], [2], [3], [3], [3]]]]
    self.assertAllClose(custom_op_output, expected_output) 
开发者ID:ahmetozlu,项目名称:vehicle_counting_tensorflow,代码行数:17,代码来源:ops_test.py

示例6: test_rewrite_nn_resize_op_quantized

# 需要导入模块: from object_detection.utils import ops [as 别名]
# 或者: from object_detection.utils.ops import nearest_neighbor_upsampling [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

示例7: test_upsampling

# 需要导入模块: from object_detection.utils import ops [as 别名]
# 或者: from object_detection.utils.ops import nearest_neighbor_upsampling [as 别名]
def test_upsampling(self):

    def graph_fn(inputs):
      custom_op_output = ops.nearest_neighbor_upsampling(inputs, scale=2)
      return custom_op_output
    inputs = np.reshape(np.arange(4).astype(np.float32), [1, 2, 2, 1])
    custom_op_output = self.execute(graph_fn, [inputs])

    expected_output = [[[[0], [0], [1], [1]],
                        [[0], [0], [1], [1]],
                        [[2], [2], [3], [3]],
                        [[2], [2], [3], [3]]]]
    self.assertAllClose(custom_op_output, expected_output) 
开发者ID:cagbal,项目名称:ros_people_object_detection_tensorflow,代码行数:15,代码来源:ops_test.py

示例8: test_upsampling

# 需要导入模块: from object_detection.utils import ops [as 别名]
# 或者: from object_detection.utils.ops import nearest_neighbor_upsampling [as 别名]
def test_upsampling(self):

    def graph_fn(inputs):
      custom_op_output = ops.nearest_neighbor_upsampling(inputs, scale=2)
      tf_op_output = tf.image.resize_images(
          inputs, [4, 4], method=tf.image.ResizeMethod.NEAREST_NEIGHBOR)
      return (custom_op_output, tf_op_output)
    inputs = np.reshape(np.arange(2**4), [2, 2, 2, 2])
    (custom_op_output, tf_op_output) = self.execute(graph_fn, [inputs])
    self.assertAllClose(custom_op_output, tf_op_output) 
开发者ID:ShreyAmbesh,项目名称:Traffic-Rule-Violation-Detection-System,代码行数:12,代码来源:ops_test.py

示例9: test_upsampling

# 需要导入模块: from object_detection.utils import ops [as 别名]
# 或者: from object_detection.utils.ops import nearest_neighbor_upsampling [as 别名]
def test_upsampling(self):

        def graph_fn(inputs):
            custom_op_output = ops.nearest_neighbor_upsampling(inputs, scale=2)
            return custom_op_output
        inputs = np.reshape(np.arange(4).astype(np.float32), [1, 2, 2, 1])
        custom_op_output = self.execute(graph_fn, [inputs])

        expected_output = [[[[0], [0], [1], [1]],
                            [[0], [0], [1], [1]],
                            [[2], [2], [3], [3]],
                            [[2], [2], [3], [3]]]]
        self.assertAllClose(custom_op_output, expected_output) 
开发者ID:kujason,项目名称:monopsr,代码行数:15,代码来源:ops_test.py

示例10: create_upsample_feature_map_ops

# 需要导入模块: from object_detection.utils import ops [as 别名]
# 或者: from object_detection.utils.ops import nearest_neighbor_upsampling [as 别名]
def create_upsample_feature_map_ops(scale, use_native_resize_op, name):
  """Creates Keras layers for upsampling feature maps.

  Args:
    scale: Int. The scale factor by which to upsample input feature maps. For
      example, in the case of a typical feature map pyramid, the scale factor
      between level_i and level_i-1 is 2.
    use_native_resize_op: If True, uses tf.image.resize_nearest_neighbor op for
      the upsampling process instead of reshape and broadcasting implementation.
    name: String. The name used to prefix the constructed layers.

  Returns:
    A list of Keras layers which will upsample input feature maps by the
    desired scale factor.
  """
  layers = []
  if use_native_resize_op:

    def resize_nearest_neighbor(image):
      image_shape = shape_utils.combined_static_and_dynamic_shape(image)
      return tf.image.resize_nearest_neighbor(
          image, [image_shape[1] * scale, image_shape[2] * scale])

    layers.append(
        tf.keras.layers.Lambda(
            resize_nearest_neighbor,
            name=name + 'nearest_neighbor_upsampling_x{}'.format(scale)))
  else:

    def nearest_neighbor_upsampling(image):
      return ops.nearest_neighbor_upsampling(image, scale=scale)

    layers.append(
        tf.keras.layers.Lambda(
            nearest_neighbor_upsampling,
            name=name + 'nearest_neighbor_upsampling_x{}'.format(scale)))

  return layers 
开发者ID:tensorflow,项目名称:models,代码行数:40,代码来源:bifpn_utils.py


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