MCPcopy Create free account
hub / github.com/NVIDIA/DALI / check_batch

Function check_batch

dali/test/python/test_utils.py:252–363  ·  view source on GitHub ↗

Compare two batches of data, be it dali TensorList or list of numpy arrays. Args: batch1: input batch batch2: input batch batch_size: reference batch size - if None, only equality is enforced eps (float, optional): Used for mean error validation. Defaults to 1e-0

(
    batch1,
    batch2,
    batch_size=None,
    eps=1e-07,
    max_allowed_error=None,
    expected_layout=None,
    compare_layouts=True,
    dump_artifacts=True,
)

Source from the content-addressed store, hash-verified

250
251# If the `max_allowed_error` is not None, it's checked instead of comparing mean error with `eps`.
252def check_batch(
253 batch1,
254 batch2,
255 batch_size=None,
256 eps=1e-07,
257 max_allowed_error=None,
258 expected_layout=None,
259 compare_layouts=True,
260 dump_artifacts=True,
261):
262 """Compare two batches of data, be it dali TensorList or list of numpy arrays.
263
264 Args:
265 batch1: input batch
266 batch2: input batch
267 batch_size: reference batch size - if None, only equality is enforced
268 eps (float, optional): Used for mean error validation. Defaults to 1e-07.
269 max_allowed_error (int or float, optional): If provided the max diff between elements.
270 expected_layout (str, optional): If provided, the batches that are DALI types
271 will be checked to match this layout. If None, there will be no check
272 compare_layouts (bool, optional): Whether to compare layouts between two batches.
273 Checked only if both inputs are DALI types. Defaults to True.
274 """
275
276 def is_error(mean_err, max_err, eps, max_allowed_error):
277 if max_allowed_error is not None:
278 if max_err > max_allowed_error:
279 return True
280 elif mean_err > eps:
281 return True
282 return False
283
284 import_numpy()
285 if isinstance(batch1, dali.backend.TensorListGPU):
286 batch1 = batch1.as_cpu()
287 if isinstance(batch2, dali.backend.TensorListGPU):
288 batch2 = batch2.as_cpu()
289
290 if batch_size is None:
291 batch_size = len(batch1)
292
293 def _verify_batch_size(batch):
294 if isinstance(batch, dali.backend.TensorListCPU) or isinstance(batch, list):
295 tested_batch_size = len(batch)
296 else:
297 tested_batch_size = batch.shape[0]
298 assert (
299 tested_batch_size == batch_size
300 ), "Incorrect batch size. Expected: {}, actual: {}".format(batch_size, tested_batch_size)
301
302 _verify_batch_size(batch1)
303 _verify_batch_size(batch2)
304
305 # Check layouts where possible
306 for batch in [batch1, batch2]:
307 if expected_layout is not None and isinstance(batch, dali.backend.TensorListCPU):
308 assert (
309 batch.layout() == expected_layout

Callers 15

_test_feed_inputFunction · 0.90
_test_callbackFunction · 0.90
_test_scalarFunction · 0.90
test_repeat_lastFunction · 0.90
test_repeat_last_queueFunction · 0.90
test_seed_serializeFunction · 0.90
test_gpu2cpuFunction · 0.90
test_gpu2cpu2mixedFunction · 0.90
test_shapes_gpuFunction · 0.90

Calls 9

_verify_batch_sizeFunction · 0.85
get_absdiffFunction · 0.85
is_errorFunction · 0.85
dump_as_core_artifactsFunction · 0.85
minMethod · 0.80
source_infoMethod · 0.80
import_numpyFunction · 0.70
layoutMethod · 0.45
maxMethod · 0.45

Tested by

no test coverage detected