MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / MapData

Class MapData

tensorpack/dataflow/common.py:287–318  ·  view source on GitHub ↗

Apply a mapper/filter on the datapoints of a DataFlow. Note: 1. Please make sure func doesn't modify its arguments in place, unless you're certain it's safe. 2. If you discard some datapoints, ``len(MapData(ds))`` will be incorrect. Example: .. code

Source from the content-addressed store, hash-verified

285
286
287class MapData(ProxyDataFlow):
288 """
289 Apply a mapper/filter on the datapoints of a DataFlow.
290
291 Note:
292 1. Please make sure func doesn't modify its arguments in place,
293 unless you're certain it's safe.
294 2. If you discard some datapoints, ``len(MapData(ds))`` will be incorrect.
295
296 Example:
297
298 .. code-block:: none
299
300 ds = Mnist('train') # each datapoint is [img, label]
301 ds = MapData(ds, lambda dp: [dp[0] * 255, dp[1]])
302 """
303
304 def __init__(self, ds, func):
305 """
306 Args:
307 ds (DataFlow): input DataFlow
308 func (datapoint -> datapoint | None): takes a datapoint and returns a new
309 datapoint. Return None to discard/skip this datapoint.
310 """
311 super(MapData, self).__init__(ds)
312 self.func = func
313
314 def __iter__(self):
315 for dp in self.ds:
316 ret = self.func(copy(dp)) # shallow copy the list
317 if ret is not None:
318 yield ret
319
320
321class MapDataComponent(MapData):

Callers 14

get_train_dataflowFunction · 0.90
get_dataFunction · 0.90
dataflow_to_datasetMethod · 0.85
SelectComponentFunction · 0.85
loadMethod · 0.85
loadMethod · 0.85
get_dataFunction · 0.85
sampleFunction · 0.85
sampleFunction · 0.85
get_dataFunction · 0.85
get_dataFunction · 0.85
inferenceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected