MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / set_transform_hash

Method set_transform_hash

monai/data/dataset.py:303–321  ·  view source on GitHub ↗

Get hashable transforms, and then hash them. Hashable transforms are deterministic transforms that inherit from `Transform`. We stop at the first non-deterministic transform, or first that does not inherit from MONAI's `Transform` class.

(self, hash_xform_func: Callable[..., bytes])

Source from the content-addressed store, hash-verified

301 self.weights_only = weights_only
302
303 def set_transform_hash(self, hash_xform_func: Callable[..., bytes]):
304 """Get hashable transforms, and then hash them. Hashable transforms
305 are deterministic transforms that inherit from `Transform`. We stop
306 at the first non-deterministic transform, or first that does not
307 inherit from MONAI's `Transform` class."""
308 hashable_transforms = []
309 for _tr in self.transform.flatten().transforms:
310 if isinstance(_tr, RandomizableTrait) or not isinstance(_tr, Transform):
311 break
312 hashable_transforms.append(_tr)
313 # Try to hash. Fall back to a hash of their names
314 try:
315 transform_hash = hash_xform_func(hashable_transforms)
316 except TypeError as te:
317 if "is not JSON serializable" not in str(te):
318 raise te
319 names = "".join(tr.__class__.__name__ for tr in hashable_transforms)
320 transform_hash = hash_xform_func(names)
321 self.transform_hash = transform_hash.decode("utf-8")
322
323 def set_data(self, data: Sequence):
324 """

Callers 1

__init__Method · 0.95

Calls 3

flattenMethod · 0.45
appendMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected