Test routine for a layer with a single input and single output. Arguments: layer_cls: Layer class object. kwargs: Optional dictionary of keyword arguments for instantiating the layer. input_shape: Input shape tuple. input_dtype: Data type of the input data. input_data: N
(layer_cls, kwargs=None, input_shape=None, input_dtype=None,
input_data=None, expected_output=None,
expected_output_dtype=None, expected_output_shape=None,
validate_training=True, adapt_data=None)
| 71 | |
| 72 | @test_util.disable_cudnn_autotune |
| 73 | def layer_test(layer_cls, kwargs=None, input_shape=None, input_dtype=None, |
| 74 | input_data=None, expected_output=None, |
| 75 | expected_output_dtype=None, expected_output_shape=None, |
| 76 | validate_training=True, adapt_data=None): |
| 77 | """Test routine for a layer with a single input and single output. |
| 78 | |
| 79 | Arguments: |
| 80 | layer_cls: Layer class object. |
| 81 | kwargs: Optional dictionary of keyword arguments for instantiating the |
| 82 | layer. |
| 83 | input_shape: Input shape tuple. |
| 84 | input_dtype: Data type of the input data. |
| 85 | input_data: Numpy array of input data. |
| 86 | expected_output: Numpy array of the expected output. |
| 87 | expected_output_dtype: Data type expected for the output. |
| 88 | expected_output_shape: Shape tuple for the expected shape of the output. |
| 89 | validate_training: Whether to attempt to validate training on this layer. |
| 90 | This might be set to False for non-differentiable layers that output |
| 91 | string or integer values. |
| 92 | adapt_data: Optional data for an 'adapt' call. If None, adapt() will not |
| 93 | be tested for this layer. This is only relevant for PreprocessingLayers. |
| 94 | |
| 95 | Returns: |
| 96 | The output data (Numpy array) returned by the layer, for additional |
| 97 | checks to be done by the calling code. |
| 98 | |
| 99 | Raises: |
| 100 | ValueError: if `input_shape is None`. |
| 101 | """ |
| 102 | if input_data is None: |
| 103 | if input_shape is None: |
| 104 | raise ValueError('input_shape is None') |
| 105 | if not input_dtype: |
| 106 | input_dtype = 'float32' |
| 107 | input_data_shape = list(input_shape) |
| 108 | for i, e in enumerate(input_data_shape): |
| 109 | if e is None: |
| 110 | input_data_shape[i] = np.random.randint(1, 4) |
| 111 | input_data = 10 * np.random.random(input_data_shape) |
| 112 | if input_dtype[:5] == 'float': |
| 113 | input_data -= 0.5 |
| 114 | input_data = input_data.astype(input_dtype) |
| 115 | elif input_shape is None: |
| 116 | input_shape = input_data.shape |
| 117 | if input_dtype is None: |
| 118 | input_dtype = input_data.dtype |
| 119 | if expected_output_dtype is None: |
| 120 | expected_output_dtype = input_dtype |
| 121 | |
| 122 | # instantiation |
| 123 | kwargs = kwargs or {} |
| 124 | layer = layer_cls(**kwargs) |
| 125 | |
| 126 | # Test adapt, if data was passed. |
| 127 | if adapt_data is not None: |
| 128 | layer.adapt(adapt_data) |
| 129 | |
| 130 | # test get_weights , set_weights at layer level |
nothing calls this directly
no test coverage detected