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

Function _test_sample_inflate

dali/test/python/operator_1/test_inflate.py:75–118  ·  view source on GitHub ↗
(op, batch_size, np_dtype, seed)

Source from the content-addressed store, hash-verified

73
74
75def _test_sample_inflate(op, batch_size, np_dtype, seed):
76 epoch_size = 10 * batch_size
77 rng = np.random.default_rng(seed=seed)
78 permutation = rng.permutation(epoch_size)
79 dtype = np_type_to_dali(np_dtype)
80
81 def gen_iteration_sizes():
82 num_yielded_samples = 0
83 while num_yielded_samples < epoch_size:
84 iteration_size = np.int32(np.floor(rng.uniform(1, batch_size + 1)))
85 iteration_size = min(iteration_size, epoch_size - num_yielded_samples)
86 yield iteration_size
87 num_yielded_samples += iteration_size
88
89 iteration_sizes = list(gen_iteration_sizes())
90 assert sum(iteration_sizes) == epoch_size
91
92 def source():
93 num_yielded_samples = 0
94 for iteration_size in iteration_sizes:
95 sample_sizes = [permutation[num_yielded_samples + i] for i in range(iteration_size)]
96 num_yielded_samples += iteration_size
97
98 def sample(sample_size):
99 start = (sample_size - 1) * sample_size // 2
100 sample = np.arange(start, start + sample_size, dtype=np.int64).astype(np_dtype)
101 return sample, sample_to_lz4(sample)
102
103 samples, deflated = list(zip(*[sample(sample_size) for sample_size in sample_sizes]))
104 yield list(samples), list(deflated), np.array(sample_sizes, dtype=np.int32)
105
106 op, chck_ctx = _get_alias_and_ctx(op)
107
108 @pipeline_def
109 def pipeline():
110 sample, deflated, shape = fn.external_source(source=source, batch=True, num_outputs=3)
111 inflated = op(deflated.gpu(), shape=shape, dtype=dtype)
112 return inflated, sample
113
114 with chck_ctx:
115 pipe = pipeline(batch_size=batch_size, num_threads=4, device_id=0)
116 for iter_size in iteration_sizes:
117 inflated, baseline = pipe.run()
118 check_batch(inflated, baseline, iter_size)
119
120
121@has_operator("decoders.inflate")

Callers

nothing calls this directly

Calls 7

np_type_to_daliFunction · 0.90
gen_iteration_sizesFunction · 0.85
sumClass · 0.85
_get_alias_and_ctxFunction · 0.85
pipelineFunction · 0.70
check_batchFunction · 0.70
runMethod · 0.45

Tested by

no test coverage detected