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

Class SliceSynthDataPipelinePythonOp

dali/test/python/operator_1/test_slice.py:313–365  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

311
312
313class SliceSynthDataPipelinePythonOp(Pipeline):
314 def __init__(
315 self,
316 batch_size,
317 layout,
318 iterator,
319 pos_size_iter,
320 num_threads=1,
321 device_id=0,
322 num_gpus=1,
323 axes=None,
324 axis_names=None,
325 normalized_anchor=True,
326 normalized_shape=True,
327 input_type=types.FLOAT,
328 output_type=None,
329 ):
330 super().__init__(
331 batch_size, num_threads, device_id, seed=12345, exec_async=False, exec_pipelined=False
332 )
333 self.device = "cpu"
334 self.layout = layout
335 self.iterator = iterator
336 self.pos_size_iter = pos_size_iter
337 self.inputs = ops.ExternalSource()
338 self.input_crop_pos = ops.ExternalSource()
339 self.input_crop_size = ops.ExternalSource()
340 self.cast_in = ops.Cast(dtype=input_type)
341 function = partial(
342 slice_func_helper, axes, axis_names, self.layout, normalized_anchor, normalized_shape
343 )
344 self.slice = ops.PythonFunction(function=function, output_layouts=layout)
345 self.output_type = output_type
346 if self.output_type is not None:
347 self.cast_out = ops.Cast(dtype=output_type)
348
349 def define_graph(self):
350 self.data = self.inputs()
351 self.crop_pos = self.input_crop_pos()
352 self.crop_size = self.input_crop_size()
353 out = self.cast_in(self.data)
354 out = self.slice(out, self.crop_pos, self.crop_size)
355 if self.output_type is not None:
356 out = self.cast_out(out)
357 return out
358
359 def iter_setup(self):
360 data = self.iterator.next()
361 self.feed_input(self.data, data, layout=self.layout)
362
363 crop_pos, crop_size = self.pos_size_iter.next()
364 self.feed_input(self.crop_pos, crop_pos)
365 self.feed_input(self.crop_size, crop_size)
366
367
368class SlicePythonOp(Pipeline):

Callers 1

Calls

no outgoing calls

Tested by 1