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

Method batch

python/paddle/static/input.py:346–381  ·  view source on GitHub ↗

Inserts `batch_size` in front of the `shape`. Args: batch_size(int): the inserted integer value of batch size. Returns: The original InputSpec instance by inserting `batch_size` in front of `shape`. Examples: .. code-block:: pyc

(self, batch_size: int | Size1)

Source from the content-addressed store, hash-verified

344 return cls(ndarray.shape, ndarray.dtype, name)
345
346 def batch(self, batch_size: int | Size1) -> Self:
347 """
348 Inserts `batch_size` in front of the `shape`.
349
350 Args:
351 batch_size(int): the inserted integer value of batch size.
352
353 Returns:
354 The original InputSpec instance by inserting `batch_size` in front of `shape`.
355
356 Examples:
357 .. code-block:: pycon
358
359 >>> from paddle.static import InputSpec
360
361 >>> x_spec = InputSpec(shape=[64], dtype='float32', name='x')
362 >>> x_spec.batch(4)
363 >>> print(x_spec)
364 InputSpec(shape=(4, 64), dtype=paddle.float32, name=x, stop_gradient=False)
365
366 """
367 if isinstance(batch_size, (list, tuple)):
368 if len(batch_size) != 1:
369 raise ValueError(
370 f"Length of batch_size: {batch_size} shall be 1, but received {len(batch_size)}."
371 )
372 batch_size = batch_size[0]
373 elif not isinstance(batch_size, int):
374 raise TypeError(
375 f"type(batch_size) shall be `int`, but received {type(batch_size).__name__}."
376 )
377
378 new_shape = [batch_size, *list(self.shape)]
379 self.shape = tuple(new_shape)
380
381 return self
382
383 def unbatch(self) -> Self:
384 """

Callers 15

_infer_item_specMethod · 0.80
set_sample_generatorMethod · 0.80
set_sample_generatorMethod · 0.80
__for_train__Function · 0.80
__for_test__Function · 0.80
setUpMethod · 0.80
trainFunction · 0.80
setUpMethod · 0.80
trainFunction · 0.80
trainFunction · 0.80
trainFunction · 0.80

Calls 4

ValueErrorClass · 0.85
TypeErrorClass · 0.85
listFunction · 0.85
typeFunction · 0.50

Tested by 15

setUpMethod · 0.64
trainFunction · 0.64
setUpMethod · 0.64
trainFunction · 0.64
trainFunction · 0.64
trainFunction · 0.64
func_qatMethod · 0.64
test_out_scale_accMethod · 0.64
run_programMethod · 0.64