當前位置: 首頁>>代碼示例>>Python>>正文


Python layers.separable_conv2d方法代碼示例

本文整理匯總了Python中tensorflow.contrib.layers.separable_conv2d方法的典型用法代碼示例。如果您正苦於以下問題:Python layers.separable_conv2d方法的具體用法?Python layers.separable_conv2d怎麽用?Python layers.separable_conv2d使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tensorflow.contrib.layers的用法示例。


在下文中一共展示了layers.separable_conv2d方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: gconvbn

# 需要導入模塊: from tensorflow.contrib import layers [as 別名]
# 或者: from tensorflow.contrib.layers import separable_conv2d [as 別名]
def gconvbn(*args, **kwargs):
    scope = kwargs.pop('scope', None)
    with tf.variable_scope(scope):
        x = sconv2d(*args, **kwargs)
        c = args[-1]
        infilters = int(x.shape[-1]) if tf_later_than('2') else x.shape[-1].value
        f = infilters // c
        g = f // c
        kernel = np.zeros((1, 1, f * c, f), np.float32)
        for i in range(f):
            start = (i // c) * c * c + i % c
            end = start + c * c
            kernel[:, :, start:end:c, i] = 1.
        x = conv2d_primitive(x, tf.constant(kernel), strides=[1, 1, 1, 1],
                             padding='VALID', name='gconv')
        return batch_norm(x) 
開發者ID:taehoonlee,項目名稱:tensornets,代碼行數:18,代碼來源:layers.py

示例2: sconvbn

# 需要導入模塊: from tensorflow.contrib import layers [as 別名]
# 或者: from tensorflow.contrib.layers import separable_conv2d [as 別名]
def sconvbn(*args, **kwargs):
    scope = kwargs.pop('scope', None)
    with tf.variable_scope(scope):
        return batch_norm(sconv2d(*args, **kwargs)) 
開發者ID:taehoonlee,項目名稱:tensornets,代碼行數:6,代碼來源:layers.py

示例3: sconvbnact

# 需要導入模塊: from tensorflow.contrib import layers [as 別名]
# 或者: from tensorflow.contrib.layers import separable_conv2d [as 別名]
def sconvbnact(*args, **kwargs):
    scope = kwargs.pop('scope', None)
    activation_fn = kwargs.pop('activation_fn', None)
    with tf.variable_scope(scope):
        return activation_fn(batch_norm(sconv2d(*args, **kwargs))) 
開發者ID:taehoonlee,項目名稱:tensornets,代碼行數:7,代碼來源:layers.py

示例4: sconvbnrelu

# 需要導入模塊: from tensorflow.contrib import layers [as 別名]
# 或者: from tensorflow.contrib.layers import separable_conv2d [as 別名]
def sconvbnrelu(*args, **kwargs):
    scope = kwargs.pop('scope', None)
    with tf.variable_scope(scope):
        return relu(batch_norm(sconv2d(*args, **kwargs))) 
開發者ID:taehoonlee,項目名稱:tensornets,代碼行數:6,代碼來源:layers.py

示例5: sconvbnrelu6

# 需要導入模塊: from tensorflow.contrib import layers [as 別名]
# 或者: from tensorflow.contrib.layers import separable_conv2d [as 別名]
def sconvbnrelu6(*args, **kwargs):
    scope = kwargs.pop('scope', None)
    with tf.variable_scope(scope):
        return relu6(batch_norm(sconv2d(*args, **kwargs))) 
開發者ID:taehoonlee,項目名稱:tensornets,代碼行數:6,代碼來源:layers.py

示例6: test_get_input_activation2

# 需要導入模塊: from tensorflow.contrib import layers [as 別名]
# 或者: from tensorflow.contrib.layers import separable_conv2d [as 別名]
def test_get_input_activation2(self, rank, fn, op_name):
    g = tf.get_default_graph()
    inputs = tf.zeros([6] * rank)
    with arg_scope([
        layers.conv2d, layers.conv2d_transpose, layers.separable_conv2d,
        layers.conv3d
    ],
                   scope='test_layer'):
      _ = fn(inputs)
    for op in g.get_operations():
      print(op.name)
    self.assertEqual(
        inputs,
        cc.get_input_activation(
            g.get_operation_by_name('test_layer/' + op_name))) 
開發者ID:google-research,項目名稱:morph-net,代碼行數:17,代碼來源:cost_calculator_test.py

示例7: separable_conv2d

# 需要導入模塊: from tensorflow.contrib import layers [as 別名]
# 或者: from tensorflow.contrib.layers import separable_conv2d [as 別名]
def separable_conv2d(self, *args, **kwargs):
    """Masks NUM_OUTPUTS from the function pointed to by 'separable_conv2d'.

    The object's parameterization has precedence over the given NUM_OUTPUTS
    argument. The resolution of the op names uses
    tf.contrib.framework.get_name_scope() and kwargs['scope'].

    Args:
      *args: Arguments for the operation.
      **kwargs: Key arguments for the operation.

    Returns:
      The result of the application of the function_map['separable_conv2d'] to
      the given 'inputs', '*args', and '**kwargs' while possibly overriding
      NUM_OUTPUTS according the parameterization.

    Raises:
      ValueError: If kwargs does not contain a key named 'scope'.
    """
    # This function actually only decorates the num_outputs of the Conv2D after
    # the depthwise convolution, as the former does not have any free params.
    fn, suffix = self._get_function_and_suffix('separable_conv2d')
    num_outputs_kwarg_name = self._get_num_outputs_kwarg_name(fn)
    num_outputs = _get_from_args_or_kwargs(
        num_outputs_kwarg_name, 1, args, kwargs, False)
    if num_outputs is None:
      tf.logging.warning(
          'Trying to decorate separable_conv2d with num_outputs = None')
      kwargs[num_outputs_kwarg_name] = None

    return self._mask(fn, suffix, *args, **kwargs) 
開發者ID:google-research,項目名稱:morph-net,代碼行數:33,代碼來源:configurable_ops.py

示例8: constructed_ops

# 需要導入模塊: from tensorflow.contrib import layers [as 別名]
# 或者: from tensorflow.contrib.layers import separable_conv2d [as 別名]
def constructed_ops(self):
    """Returns a dictionary between op names built to their NUM_OUTPUTS.

       The dictionary will contain an op.name: NUM_OUTPUTS pair for each op
       constructed by the decorator. The dictionary is ordered according to the
       order items were added.
       The parameterization is accumulated during all the calls to the object's
       members, such as `conv2d`, `fully_connected` and `separable_conv2d`.
       The values used are either the values from the parameterization set for
       the object, or the values that where passed to the members.
    """
    return self._constructed_ops 
開發者ID:google-research,項目名稱:morph-net,代碼行數:14,代碼來源:configurable_ops.py

示例9: _get_num_outputs_kwarg_name

# 需要導入模塊: from tensorflow.contrib import layers [as 別名]
# 或者: from tensorflow.contrib.layers import separable_conv2d [as 別名]
def _get_num_outputs_kwarg_name(self, function):
    """Gets the `num_outputs`-equivalent kwarg for a supported function."""
    alt_num_outputs_kwarg = {
        tf_layers.conv2d: 'filters',
        tf_layers.separable_conv2d: 'filters',
        tf_layers.dense: 'units',
    }
    return alt_num_outputs_kwarg.get(function, _DEFAULT_NUM_OUTPUTS_KWARG) 
開發者ID:google-research,項目名稱:morph-net,代碼行數:10,代碼來源:configurable_ops.py

示例10: testMapBinding

# 需要導入模塊: from tensorflow.contrib import layers [as 別名]
# 或者: from tensorflow.contrib.layers import separable_conv2d [as 別名]
def testMapBinding(self):
    # TODO(e1): Clean up this file/test. Split to different tests
    function_dict = {
        'fully_connected': mock_fully_connected,
        'conv2d': mock_conv2d,
        'separable_conv2d': mock_separable_conv2d,
        'concat': mock_concat,
        'add_n': mock_add_n,
    }
    parameterization = {
        'fc/MatMul': 13,
        'conv/Conv2D': 15,
        'sep/separable_conv2d': 17
    }
    num_outputs = lambda res: res['args'][1]
    decorator = ops.ConfigurableOps(
        parameterization=parameterization, function_dict=function_dict)
    fc = decorator.fully_connected(self.fc_inputs, num_outputs=88, scope='fc')
    self.assertEqual('myfully_connected', fc['mock_name'])
    self.assertEqual(parameterization['fc/MatMul'], num_outputs(fc))

    conv2d = decorator.conv2d(
        self.inputs, num_outputs=11, kernel_size=3, scope='conv')
    self.assertEqual('myconv2d', conv2d['mock_name'])
    self.assertEqual(parameterization['conv/Conv2D'], num_outputs(conv2d))

    separable_conv2d = decorator.separable_conv2d(
        self.inputs, num_outputs=88, kernel_size=3, scope='sep')
    self.assertEqual('myseparable_conv2d', separable_conv2d['mock_name'])
    self.assertEqual(parameterization['sep/separable_conv2d'],
                     num_outputs(separable_conv2d))

    concat = decorator.concat(axis=1, values=[1, None, 2])
    self.assertEqual(concat['args'][0], [1, 2])
    self.assertEqual(concat['kwargs']['axis'], 1)
    with self.assertRaises(ValueError):
      _ = decorator.concat(inputs=[1, None, 2])

    add_n = decorator.add_n(name='add_n', inputs=[1, None, 2])
    self.assertEqual(add_n['args'][0], [1, 2]) 
開發者ID:google-research,項目名稱:morph-net,代碼行數:42,代碼來源:configurable_ops_test.py

示例11: testSeparableConv2dOp

# 需要導入模塊: from tensorflow.contrib import layers [as 別名]
# 或者: from tensorflow.contrib.layers import separable_conv2d [as 別名]
def testSeparableConv2dOp(self):
    parameterization = {'test/separable_conv2d': 12}
    decorator = ops.ConfigurableOps(parameterization=parameterization)
    output = decorator.separable_conv2d(
        self.inputs,
        num_outputs=88,
        kernel_size=3,
        depth_multiplier=1,
        scope='test')
    self.assertEqual(12, output.shape.as_list()[-1]) 
開發者ID:google-research,項目名稱:morph-net,代碼行數:12,代碼來源:configurable_ops_test.py

示例12: testDefaultScopesRepeated

# 需要導入模塊: from tensorflow.contrib import layers [as 別名]
# 或者: from tensorflow.contrib.layers import separable_conv2d [as 別名]
def testDefaultScopesRepeated(self):
    inputs = tf.ones([1, 3, 3, 2])
    parameterization = {
        's1/SeparableConv2d/separable_conv2d': 1,
        's1/SeparableConv2d_1/separable_conv2d': 2,
        's1/s2/SeparableConv2d/separable_conv2d': 3,
        's1/s2/SeparableConv2d_1/separable_conv2d': 4,
    }
    decorator = ops.ConfigurableOps(
        parameterization=parameterization,
        function_dict={'separable_conv2d': tf_contrib.slim.separable_conv2d})

    with tf.variable_scope('s1'):
      # first call in s1: op scope should be `s1/SeparableConv2d`
      _ = decorator.separable_conv2d(inputs, num_outputs=8, kernel_size=2)

      with tf.variable_scope('s2'):
        # first call in s2: op scope should be `s1/s2/SeparableConv2d`
        _ = decorator.separable_conv2d(inputs, num_outputs=8, kernel_size=2)

        # second call in s2: op scope should be `s1/s2/SeparableConv2d_1`
        _ = decorator.separable_conv2d(inputs, num_outputs=8, kernel_size=2)

      # second call in s1: op scope should be `s1/SeparableConv2d_1`
      _ = decorator.separable_conv2d(inputs, num_outputs=8, kernel_size=2)

    conv_op_names = [op.name for op in tf.get_default_graph().get_operations()
                     if op.name.endswith('separable_conv2d')]
    self.assertCountEqual(parameterization, conv_op_names)
    self.assertDictEqual(parameterization, decorator.constructed_ops) 
開發者ID:google-research,項目名稱:morph-net,代碼行數:32,代碼來源:configurable_ops_test.py

示例13: __init__

# 需要導入模塊: from tensorflow.contrib import layers [as 別名]
# 或者: from tensorflow.contrib.layers import separable_conv2d [as 別名]
def __init__(self):
    self.conv2d = layers.conv2d
    self.fully_connected = layers.fully_connected
    self.separable_conv2d = layers.separable_conv2d
    self.concat = tf.concat 
開發者ID:google-research,項目名稱:morph-net,代碼行數:7,代碼來源:configurable_ops_test.py

示例14: testHijack

# 需要導入模塊: from tensorflow.contrib import layers [as 別名]
# 或者: from tensorflow.contrib.layers import separable_conv2d [as 別名]
def testHijack(self, fake_module, has_conv2d, has_separable_conv2d,
                 has_fully_connected):
    # This test verifies that hijacking works with arg scope.
    # TODO(e1): Test that all is correct when hijacking a real module.
    def name_and_output_fn(name):
      # By design there is no add arg_scope here.
      def fn(*args, **kwargs):
        return (name, args[1], kwargs['scope'])

      return fn

    function_dict = {
        'fully_connected': name_and_output_fn('testing_fully_connected'),
        'conv2d': name_and_output_fn('testing_conv2d'),
        'separable_conv2d': name_and_output_fn('testing_separable_conv2d')
    }

    decorator = ops.ConfigurableOps(function_dict=function_dict)
    originals = ops.hijack_module_functions(decorator, fake_module)

    self.assertEqual('conv2d' in originals, has_conv2d)
    self.assertEqual('separable_conv2d' in originals, has_separable_conv2d)
    self.assertEqual('fully_connected' in originals, has_fully_connected)

    if has_conv2d:
      with arg_scope([fake_module.conv2d], num_outputs=2):
        out = fake_module.conv2d(
            inputs=tf.zeros([10, 3, 3, 4]), scope='test_conv2d')
      self.assertAllEqual(['testing_conv2d', 2, 'test_conv2d'], out)

    if has_fully_connected:
      with arg_scope([fake_module.fully_connected], num_outputs=3):
        out = fake_module.fully_connected(
            inputs=tf.zeros([10, 4]), scope='test_fc')
      self.assertAllEqual(['testing_fully_connected', 3, 'test_fc'], out)

    if has_separable_conv2d:
      with arg_scope([fake_module.separable_conv2d], num_outputs=4):
        out = fake_module.separable_conv2d(
            inputs=tf.zeros([10, 3, 3, 4]), scope='test_sep')
      self.assertAllEqual(['testing_separable_conv2d', 4, 'test_sep'], out) 
開發者ID:google-research,項目名稱:morph-net,代碼行數:43,代碼來源:configurable_ops_test.py

示例15: testOpAssumptions

# 需要導入模塊: from tensorflow.contrib import layers [as 別名]
# 或者: from tensorflow.contrib.layers import separable_conv2d [as 別名]
def testOpAssumptions(self):
    # Verify that op assumptions are true.  For example, verify that specific
    # inputs are at expected indices.
    conv_transpose = layers.conv2d_transpose(
        self.batch_norm_op.outputs[0], num_outputs=8, kernel_size=3,
        scope='conv_transpose')
    layers.separable_conv2d(
        conv_transpose, num_outputs=9, kernel_size=3, scope='dwise_conv')
    layers.fully_connected(tf.zeros([1, 7]), 10, scope='fc')

    g = tf.get_default_graph()

    # Verify that FusedBatchNormV3 has gamma as inputs[1].
    self.assertEqual('conv1/BatchNorm/gamma/read:0',
                     self.batch_norm_op.inputs[1].name)

    # Verify that Conv2D has weights at expected index.
    index = op_handler_util.WEIGHTS_INDEX_DICT[self.conv_op.type]
    self.assertEqual('conv1/weights/read:0',
                     self.conv_op.inputs[index].name)

    # Verify that Conv2DBackpropInput has weights at expected index.
    conv_transpose_op = g.get_operation_by_name(
        'conv_transpose/conv2d_transpose')
    index = op_handler_util.WEIGHTS_INDEX_DICT[conv_transpose_op.type]
    self.assertEqual('conv_transpose/weights/read:0',
                     conv_transpose_op.inputs[index].name)

    # Verify that DepthwiseConv2dNative has weights at expected index.
    depthwise_conv_op = g.get_operation_by_name(
        'dwise_conv/separable_conv2d/depthwise')
    index = op_handler_util.WEIGHTS_INDEX_DICT[depthwise_conv_op.type]
    self.assertEqual('dwise_conv/depthwise_weights/read:0',
                     depthwise_conv_op.inputs[index].name)

    # Verify that MatMul has weights at expected index.
    matmul_op = g.get_operation_by_name('fc/MatMul')
    index = op_handler_util.WEIGHTS_INDEX_DICT[matmul_op.type]
    self.assertEqual('fc/weights/read:0',
                     matmul_op.inputs[index].name) 
開發者ID:google-research,項目名稱:morph-net,代碼行數:42,代碼來源:op_handler_util_test.py


注:本文中的tensorflow.contrib.layers.separable_conv2d方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。