• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python testing_utils.layer_test函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tensorflow.contrib.keras.python.keras.testing_utils.layer_test函数的典型用法代码示例。如果您正苦于以下问题:Python layer_test函数的具体用法?Python layer_test怎么用?Python layer_test使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_convolution_2d

  def test_convolution_2d(self):
    num_samples = 2
    filters = 2
    stack_size = 3
    kernel_size = (3, 2)
    num_row = 7
    num_col = 6

    for padding in ['valid', 'same']:
      for strides in [(1, 1), (2, 2)]:
        if padding == 'same' and strides != (1, 1):
          continue

        with self.test_session(use_gpu=True):
          # Only runs on GPU with CUDA, channels_first is not supported on CPU.
          # TODO(b/62340061): Support channels_first on CPU.
          if test.is_gpu_available(cuda_only=True):
            testing_utils.layer_test(
                keras.layers.Conv2D,
                kwargs={
                    'filters': filters,
                    'kernel_size': kernel_size,
                    'padding': padding,
                    'strides': strides,
                    'data_format': 'channels_first'
                },
                input_shape=(num_samples, stack_size, num_row, num_col))
开发者ID:AutumnQYN,项目名称:tensorflow,代码行数:27,代码来源:convolutional_test.py


示例2: test_convolution_3d

  def test_convolution_3d(self):
    num_samples = 2
    filters = 2
    stack_size = 3

    input_len_dim1 = 9
    input_len_dim2 = 8
    input_len_dim3 = 8

    for padding in ['valid', 'same']:
      for strides in [(1, 1, 1), (2, 2, 2)]:
        if padding == 'same' and strides != (1, 1, 1):
          continue

        with self.test_session(use_gpu=True):
          testing_utils.layer_test(
              keras.layers.Convolution3D,
              kwargs={
                  'filters': filters,
                  'kernel_size': 3,
                  'padding': padding,
                  'strides': strides
              },
              input_shape=(num_samples, input_len_dim1, input_len_dim2,
                           input_len_dim3, stack_size))
开发者ID:AutumnQYN,项目名称:tensorflow,代码行数:25,代码来源:convolutional_test.py


示例3: test_zero_padding_3d

  def test_zero_padding_3d(self):
    num_samples = 2
    stack_size = 2
    input_len_dim1 = 4
    input_len_dim2 = 5
    input_len_dim3 = 3

    inputs = np.ones((num_samples, input_len_dim1, input_len_dim2,
                      input_len_dim3, stack_size))

    # basic test
    with self.test_session(use_gpu=True):
      testing_utils.layer_test(
          keras.layers.ZeroPadding3D,
          kwargs={'padding': (2, 2, 2)},
          input_shape=inputs.shape)

    # correctness test
    with self.test_session(use_gpu=True):
      layer = keras.layers.ZeroPadding3D(padding=(2, 2, 2))
      layer.build(inputs.shape)
      output = layer(keras.backend.variable(inputs))
      np_output = keras.backend.eval(output)
      for offset in [0, 1, -1, -2]:
        np.testing.assert_allclose(np_output[:, offset, :, :, :], 0.)
        np.testing.assert_allclose(np_output[:, :, offset, :, :], 0.)
        np.testing.assert_allclose(np_output[:, :, :, offset, :], 0.)
      np.testing.assert_allclose(np_output[:, 2:-2, 2:-2, 2:-2, :], 1.)
开发者ID:AutumnQYN,项目名称:tensorflow,代码行数:28,代码来源:convolutional_test.py


示例4: test_conv_lstm

  def test_conv_lstm(self):
    num_row = 3
    num_col = 3
    filters = 2
    num_samples = 1
    input_channel = 2
    input_num_row = 5
    input_num_col = 5
    sequence_len = 2
    for data_format in ['channels_first', 'channels_last']:
      if data_format == 'channels_first':
        inputs = np.random.rand(num_samples, sequence_len,
                                input_channel,
                                input_num_row, input_num_col)
      else:
        inputs = np.random.rand(num_samples, sequence_len,
                                input_num_row, input_num_col,
                                input_channel)

      for return_sequences in [True, False]:
        # test for output shape:
        with self.test_session():
          testing_utils.layer_test(
              keras.layers.ConvLSTM2D,
              kwargs={'data_format': data_format,
                      'return_sequences': return_sequences,
                      'filters': filters,
                      'kernel_size': (num_row, num_col),
                      'padding': 'valid'},
              input_shape=inputs.shape)
开发者ID:AlbertXiebnu,项目名称:tensorflow,代码行数:30,代码来源:convolutional_recurrent_test.py


示例5: test_averagepooling_1d

 def test_averagepooling_1d(self):
   with self.test_session(use_gpu=True):
     for padding in ['valid', 'same']:
       for stride in [1, 2]:
         testing_utils.layer_test(
             keras.layers.AveragePooling1D,
             kwargs={'strides': stride,
                     'padding': padding},
             input_shape=(3, 5, 4))
开发者ID:astorfi,项目名称:tensorflow,代码行数:9,代码来源:pooling_test.py


示例6: test_cropping_2d

  def test_cropping_2d(self):
    num_samples = 2
    stack_size = 2
    input_len_dim1 = 9
    input_len_dim2 = 9
    cropping = ((2, 2), (3, 3))

    for data_format in ['channels_first', 'channels_last']:
      if data_format == 'channels_first':
        inputs = np.random.rand(num_samples, stack_size, input_len_dim1,
                                input_len_dim2)
      else:
        inputs = np.random.rand(num_samples, input_len_dim1, input_len_dim2,
                                stack_size)
      # basic test
      with self.test_session(use_gpu=True):
        testing_utils.layer_test(
            keras.layers.Cropping2D,
            kwargs={'cropping': cropping,
                    'data_format': data_format},
            input_shape=inputs.shape)
      # correctness test
      with self.test_session(use_gpu=True):
        layer = keras.layers.Cropping2D(
            cropping=cropping, data_format=data_format)
        layer.build(inputs.shape)
        output = layer(keras.backend.variable(inputs))
        np_output = keras.backend.eval(output)
        # compare with numpy
        if data_format == 'channels_first':
          expected_out = inputs[:, :, cropping[0][0]:-cropping[0][1], cropping[
              1][0]:-cropping[1][1]]
        else:
          expected_out = inputs[:, cropping[0][0]:-cropping[0][1], cropping[1][
              0]:-cropping[1][1], :]
        np.testing.assert_allclose(np_output, expected_out)

    for data_format in ['channels_first', 'channels_last']:
      if data_format == 'channels_first':
        inputs = np.random.rand(num_samples, stack_size, input_len_dim1,
                                input_len_dim2)
      else:
        inputs = np.random.rand(num_samples, input_len_dim1, input_len_dim2,
                                stack_size)
      # another correctness test (no cropping)
      with self.test_session(use_gpu=True):
        cropping = ((0, 0), (0, 0))
        layer = keras.layers.Cropping2D(
            cropping=cropping, data_format=data_format)
        layer.build(inputs.shape)
        output = layer(keras.backend.variable(inputs))
        np_output = keras.backend.eval(output)
        # compare with input
        np.testing.assert_allclose(np_output, inputs)
开发者ID:AutumnQYN,项目名称:tensorflow,代码行数:54,代码来源:convolutional_test.py


示例7: test_cropping_1d

  def test_cropping_1d(self):
    num_samples = 2
    time_length = 4
    input_len_dim1 = 2
    inputs = np.random.rand(num_samples, time_length, input_len_dim1)

    with self.test_session(use_gpu=True):
      testing_utils.layer_test(
          keras.layers.Cropping1D,
          kwargs={'cropping': (2, 2)},
          input_shape=inputs.shape)
开发者ID:AutumnQYN,项目名称:tensorflow,代码行数:11,代码来源:convolutional_test.py


示例8: test_return_sequences_SimpleRNN

 def test_return_sequences_SimpleRNN(self):
   num_samples = 2
   timesteps = 3
   embedding_dim = 4
   units = 2
   with self.test_session():
     testing_utils.layer_test(
         keras.layers.SimpleRNN,
         kwargs={'units': units,
                 'return_sequences': True},
         input_shape=(num_samples, timesteps, embedding_dim))
开发者ID:AlbertXiebnu,项目名称:tensorflow,代码行数:11,代码来源:simplernn_test.py


示例9: test_implementation_mode_SimpleRNN

 def test_implementation_mode_SimpleRNN(self):
   num_samples = 2
   timesteps = 3
   embedding_dim = 4
   units = 2
   with self.test_session():
     for mode in [0, 1, 2]:
       testing_utils.layer_test(
           keras.layers.SimpleRNN,
           kwargs={'units': units,
                   'implementation': mode},
           input_shape=(num_samples, timesteps, embedding_dim))
开发者ID:AlbertXiebnu,项目名称:tensorflow,代码行数:12,代码来源:simplernn_test.py


示例10: test_dropout_SimpleRNN

 def test_dropout_SimpleRNN(self):
   num_samples = 2
   timesteps = 3
   embedding_dim = 4
   units = 2
   with self.test_session():
     testing_utils.layer_test(
         keras.layers.SimpleRNN,
         kwargs={'units': units,
                 'dropout': 0.1,
                 'recurrent_dropout': 0.1},
         input_shape=(num_samples, timesteps, embedding_dim))
开发者ID:AlbertXiebnu,项目名称:tensorflow,代码行数:12,代码来源:simplernn_test.py


示例11: test_maxpooling_2d

 def test_maxpooling_2d(self):
   pool_size = (3, 3)
   with self.test_session(use_gpu=True):
     for strides in [(1, 1), (2, 2)]:
       testing_utils.layer_test(
           keras.layers.MaxPooling2D,
           kwargs={
               'strides': strides,
               'padding': 'valid',
               'pool_size': pool_size
           },
           input_shape=(3, 5, 6, 4))
开发者ID:astorfi,项目名称:tensorflow,代码行数:12,代码来源:pooling_test.py


示例12: test_upsampling_3d

  def test_upsampling_3d(self):
    num_samples = 2
    stack_size = 2
    input_len_dim1 = 10
    input_len_dim2 = 11
    input_len_dim3 = 12

    for data_format in ['channels_first', 'channels_last']:
      if data_format == 'channels_first':
        inputs = np.random.rand(num_samples, stack_size, input_len_dim1,
                                input_len_dim2, input_len_dim3)
      else:
        inputs = np.random.rand(num_samples, input_len_dim1, input_len_dim2,
                                input_len_dim3, stack_size)

      # basic test
      with self.test_session(use_gpu=True):
        testing_utils.layer_test(
            keras.layers.UpSampling3D,
            kwargs={'size': (2, 2, 2),
                    'data_format': data_format},
            input_shape=inputs.shape)

        for length_dim1 in [2, 3]:
          for length_dim2 in [2]:
            for length_dim3 in [3]:
              layer = keras.layers.UpSampling3D(
                  size=(length_dim1, length_dim2, length_dim3),
                  data_format=data_format)
              layer.build(inputs.shape)
              output = layer(keras.backend.variable(inputs))
              np_output = keras.backend.eval(output)
              if data_format == 'channels_first':
                assert np_output.shape[2] == length_dim1 * input_len_dim1
                assert np_output.shape[3] == length_dim2 * input_len_dim2
                assert np_output.shape[4] == length_dim3 * input_len_dim3
              else:  # tf
                assert np_output.shape[1] == length_dim1 * input_len_dim1
                assert np_output.shape[2] == length_dim2 * input_len_dim2
                assert np_output.shape[3] == length_dim3 * input_len_dim3

              # compare with numpy
              if data_format == 'channels_first':
                expected_out = np.repeat(inputs, length_dim1, axis=2)
                expected_out = np.repeat(expected_out, length_dim2, axis=3)
                expected_out = np.repeat(expected_out, length_dim3, axis=4)
              else:  # tf
                expected_out = np.repeat(inputs, length_dim1, axis=1)
                expected_out = np.repeat(expected_out, length_dim2, axis=2)
                expected_out = np.repeat(expected_out, length_dim3, axis=3)

              np.testing.assert_allclose(np_output, expected_out)
开发者ID:AutumnQYN,项目名称:tensorflow,代码行数:52,代码来源:convolutional_test.py


示例13: test_conv_lstm_dropout

 def test_conv_lstm_dropout(self):
   # check dropout
   with self.test_session():
     testing_utils.layer_test(
         keras.layers.ConvLSTM2D,
         kwargs={'data_format': 'channels_last',
                 'return_sequences': False,
                 'filters': 2,
                 'kernel_size': (3, 3),
                 'padding': 'same',
                 'dropout': 0.1,
                 'recurrent_dropout': 0.1},
         input_shape=(1, 2, 5, 5, 2))
开发者ID:jiayouwyhit,项目名称:tensorflow,代码行数:13,代码来源:convolutional_recurrent_test.py


示例14: test_dense

  def test_dense(self):
    with self.test_session():
      testing_utils.layer_test(
          keras.layers.Dense, kwargs={'units': 3}, input_shape=(3, 2))

    with self.test_session():
      testing_utils.layer_test(
          keras.layers.Dense, kwargs={'units': 3}, input_shape=(3, 4, 2))

    with self.test_session():
      testing_utils.layer_test(
          keras.layers.Dense, kwargs={'units': 3}, input_shape=(None, None, 2))

    with self.test_session():
      testing_utils.layer_test(
          keras.layers.Dense, kwargs={'units': 3}, input_shape=(3, 4, 5, 2))

    # Test regularization
    with self.test_session():
      layer = keras.layers.Dense(
          3,
          kernel_regularizer=keras.regularizers.l1(0.01),
          bias_regularizer='l1',
          activity_regularizer='l2',
          name='dense_reg')
      layer(keras.backend.variable(np.ones((2, 4))))
      self.assertEqual(3, len(layer.losses))

    # Test constraints
    with self.test_session():
      layer = keras.layers.Dense(
          3, kernel_constraint='max_norm', bias_constraint='max_norm')
      layer(keras.backend.variable(np.ones((2, 4))))
      self.assertEqual(2, len(layer.constraints))
开发者ID:AlbertXiebnu,项目名称:tensorflow,代码行数:34,代码来源:core_test.py


示例15: test_dilated_conv1d

 def test_dilated_conv1d(self):
   with self.test_session(use_gpu=True):
     testing_utils.layer_test(
         keras.layers.Conv1D,
         input_data=np.reshape(np.arange(4, dtype='float32'), (1, 4, 1)),
         kwargs={
             'filters': 1,
             'kernel_size': 2,
             'dilation_rate': 1,
             'padding': 'valid',
             'kernel_initializer': 'ones',
             'use_bias': False,
         },
         expected_output=[[[1], [3], [5]]])
开发者ID:AutumnQYN,项目名称:tensorflow,代码行数:14,代码来源:convolutional_test.py


示例16: test_activation

  def test_activation(self):
    # with string argument
    with self.test_session():
      testing_utils.layer_test(
          keras.layers.Activation,
          kwargs={'activation': 'relu'},
          input_shape=(3, 2))

    # with function argument
    with self.test_session():
      testing_utils.layer_test(
          keras.layers.Activation,
          kwargs={'activation': keras.backend.relu},
          input_shape=(3, 2))
开发者ID:chdinh,项目名称:tensorflow,代码行数:14,代码来源:core_test.py


示例17: test_conv_lstm

  def test_conv_lstm(self):
    num_row = 3
    num_col = 3
    filters = 2
    num_samples = 1
    input_channel = 2
    input_num_row = 5
    input_num_col = 5
    sequence_len = 2
    for data_format in ['channels_first', 'channels_last']:
      if data_format == 'channels_first':
        inputs = np.random.rand(num_samples, sequence_len,
                                input_channel,
                                input_num_row, input_num_col)
      else:
        inputs = np.random.rand(num_samples, sequence_len,
                                input_num_row, input_num_col,
                                input_channel)

      for return_sequences in [True, False]:
        with self.test_session():
          # test for return state:
          x = keras.Input(batch_shape=inputs.shape)
          kwargs = {'data_format': data_format,
                    'return_sequences': return_sequences,
                    'return_state': True,
                    'stateful': True,
                    'filters': filters,
                    'kernel_size': (num_row, num_col),
                    'padding': 'valid'}
          layer = keras.layers.ConvLSTM2D(**kwargs)
          layer.build(inputs.shape)
          outputs = layer(x)
          _, states = outputs[0], outputs[1:]
          self.assertEqual(len(states), 2)
          model = keras.models.Model(x, states[0])
          state = model.predict(inputs)
          self.assertAllClose(
              keras.backend.eval(layer.states[0]), state, atol=1e-4)

          # test for output shape:
          testing_utils.layer_test(
              keras.layers.ConvLSTM2D,
              kwargs={'data_format': data_format,
                      'return_sequences': return_sequences,
                      'filters': filters,
                      'kernel_size': (num_row, num_col),
                      'padding': 'valid'},
              input_shape=inputs.shape)
开发者ID:jiayouwyhit,项目名称:tensorflow,代码行数:49,代码来源:convolutional_recurrent_test.py


示例18: test_upsampling_2d

  def test_upsampling_2d(self):
    num_samples = 2
    stack_size = 2
    input_num_row = 11
    input_num_col = 12

    for data_format in ['channels_first', 'channels_last']:
      if data_format == 'channels_first':
        inputs = np.random.rand(num_samples, stack_size, input_num_row,
                                input_num_col)
      else:
        inputs = np.random.rand(num_samples, input_num_row, input_num_col,
                                stack_size)

      # basic test
      with self.test_session(use_gpu=True):
        testing_utils.layer_test(
            keras.layers.UpSampling2D,
            kwargs={'size': (2, 2),
                    'data_format': data_format},
            input_shape=inputs.shape)

        for length_row in [2]:
          for length_col in [2, 3]:
            layer = keras.layers.UpSampling2D(
                size=(length_row, length_col), data_format=data_format)
            layer.build(inputs.shape)
            output = layer(keras.backend.variable(inputs))
            np_output = keras.backend.eval(output)
            if data_format == 'channels_first':
              assert np_output.shape[2] == length_row * input_num_row
              assert np_output.shape[3] == length_col * input_num_col
            else:  # tf
              assert np_output.shape[1] == length_row * input_num_row
              assert np_output.shape[2] == length_col * input_num_col

            # compare with numpy
            if data_format == 'channels_first':
              expected_out = np.repeat(inputs, length_row, axis=2)
              expected_out = np.repeat(expected_out, length_col, axis=3)
            else:  # tf
              expected_out = np.repeat(inputs, length_row, axis=1)
              expected_out = np.repeat(expected_out, length_col, axis=2)

            np.testing.assert_allclose(np_output, expected_out)
开发者ID:AutumnQYN,项目名称:tensorflow,代码行数:45,代码来源:convolutional_test.py


示例19: test_averagepooling_3d

 def test_averagepooling_3d(self):
   pool_size = (3, 3, 3)
   with self.test_session(use_gpu=True):
     testing_utils.layer_test(
         keras.layers.AveragePooling3D,
         kwargs={'strides': 2,
                 'padding': 'valid',
                 'pool_size': pool_size},
         input_shape=(3, 11, 12, 10, 4))
     testing_utils.layer_test(
         keras.layers.AveragePooling3D,
         kwargs={
             'strides': 3,
             'padding': 'valid',
             'data_format': 'channels_first',
             'pool_size': pool_size
         },
         input_shape=(3, 4, 11, 12, 10))
开发者ID:astorfi,项目名称:tensorflow,代码行数:18,代码来源:pooling_test.py


示例20: test_dilated_conv_2d

  def test_dilated_conv_2d(self):
    num_samples = 2
    filters = 2
    stack_size = 3
    kernel_size = (3, 2)
    num_row = 7
    num_col = 6

    # Test dilation
    with self.test_session(use_gpu=True):
      testing_utils.layer_test(
          keras.layers.Conv2D,
          kwargs={
              'filters': filters,
              'kernel_size': kernel_size,
              'dilation_rate': (2, 2)
          },
          input_shape=(num_samples, num_row, num_col, stack_size))
开发者ID:AutumnQYN,项目名称:tensorflow,代码行数:18,代码来源:convolutional_test.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.column_to_tensors函数代码示例发布时间:2022-05-27
下一篇:
Python testing_utils.get_test_data函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap