MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / InputSpec

Class InputSpec

python/paddle/static/input.py:227–453  ·  view source on GitHub ↗

InputSpec describes the signature information of the model input, such as ``shape`` , ``dtype`` , ``name`` . This interface is often used to specify input tensor information of models in high-level API. It's also used to specify the tensor information for each input parameter of the fo

Source from the content-addressed store, hash-verified

225
226
227class InputSpec:
228 """
229 InputSpec describes the signature information of the model input, such as ``shape`` , ``dtype`` , ``name`` .
230
231 This interface is often used to specify input tensor information of models in high-level API.
232 It's also used to specify the tensor information for each input parameter of the forward function
233 decorated by `@paddle.jit.to_static`.
234
235 Args:
236 shape (tuple(integers)|list[integers]): List|Tuple of integers
237 declaring the shape. You can set "None" or -1 at a dimension
238 to indicate the dimension can be of any size. For example,
239 it is useful to set changeable batch size as "None" or -1.
240 dtype (np.dtype|str, optional): The type of the data. Supported
241 dtype: bool, float16, float32, float64, int8, int16, int32, int64,
242 uint8. Default: float32.
243 name (str): The name/alias of the variable, see :ref:`api_guide_Name`
244 for more details.
245 stop_gradient (bool, optional): A boolean that mentions whether gradient should flow. Default is False, means don't stop calculate gradients.
246
247 Examples:
248 .. code-block:: pycon
249
250 >>> import paddle
251 >>> from paddle.static import InputSpec
252
253 >>> input = InputSpec([None, 784], 'float32', 'x')
254 >>> label = InputSpec([None, 1], 'int64', 'label')
255
256 >>> print(input)
257 InputSpec(shape=(-1, 784), dtype=paddle.float32, name=x, stop_gradient=False)
258
259 >>> print(label)
260 InputSpec(shape=(-1, 1), dtype=paddle.int64, name=label, stop_gradient=False)
261 """
262
263 def __init__(
264 self,
265 shape: ShapeLike,
266 dtype: DTypeLike = 'float32',
267 name: str | None = None,
268 stop_gradient: bool = False,
269 ) -> None:
270 # replace `None` in shape with -1
271 self.shape = self._verify(shape)
272 # convert dtype into united representation
273 if dtype is not None:
274 if isinstance(dtype, (np.dtype, str)):
275 dtype = convert_np_dtype_to_dtype_(dtype)
276
277 self.dtype = dtype
278 self.name = name
279 self.stop_gradient = stop_gradient
280
281 def _create_feed_layer(self):
282 return data(self.name, shape=self.shape, dtype=self.dtype)
283
284 def __repr__(self) -> str:

Callers 15

_infer_item_specMethod · 0.90
_get_input_specFunction · 0.90
trainMethod · 0.90
test_with_errorMethod · 0.90
test_concrete_programMethod · 0.90
test_concrete_programMethod · 0.90
test_input_specMethod · 0.90
test_conv2dMethod · 0.90
test_bnMethod · 0.90
test_depthwise_conv2dMethod · 0.90

Calls

no outgoing calls

Tested by 15

trainMethod · 0.72
test_with_errorMethod · 0.72
test_concrete_programMethod · 0.72
test_concrete_programMethod · 0.72
test_input_specMethod · 0.72
test_conv2dMethod · 0.72
test_bnMethod · 0.72
test_depthwise_conv2dMethod · 0.72
test_group_normMethod · 0.72
test_functional_convMethod · 0.72