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


Python testing_utils.layer_test函数代码示例

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


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


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