MCPcopy Create free account
hub / github.com/activeloopai/deeplake / transform

Function transform

python/deeplake/integrations/mmseg/compose_transform_.py:23–64  ·  view source on GitHub ↗
(
    sample_in,
    images_tensor: str,
    masks_tensor: str,
    pipeline: Callable,
)

Source from the content-addressed store, hash-verified

21
22
23def transform(
24 sample_in,
25 images_tensor: str,
26 masks_tensor: str,
27 pipeline: Callable,
28):
29 try:
30 img = upcast_array(sample_in[images_tensor])
31 except Exception as e:
32 raise InvalidImageError(images_tensor, e)
33 if isinstance(img, (bytes, bytearray)):
34 img = np.array(Image.open(io.BytesIO(img)))
35 elif not isinstance(img, np.ndarray):
36 img = np.array(img)
37
38 try:
39 mask = sample_in[masks_tensor]
40 except Exception as e:
41 raise InvalidSegmentMaskError(images_tensor, e)
42 if not isinstance(mask, np.ndarray):
43 mask = np.array(mask)
44
45 if img.ndim == 2:
46 img = np.expand_dims(img, -1)
47
48 img = img[..., ::-1] # rgb_to_bgr should be optional
49 if img.shape[2] == 1:
50 img = np.repeat(img, 3, axis=2)
51 shape = img.shape
52
53 pipeline_dict = {
54 "img": np.ascontiguousarray(img, dtype=np.float32),
55 "img_fields": ["img"],
56 "filename": None,
57 "ori_filename": None,
58 "img_shape": shape,
59 "ori_shape": shape,
60 "gt_semantic_seg": np.ascontiguousarray(mask, np.int64),
61 "seg_fields": ["gt_semantic_seg"],
62 }
63
64 return pipeline(pipeline_dict)
65
66
67def compose_transform(

Callers

nothing calls this directly

Calls 4

upcast_arrayFunction · 0.90
InvalidImageErrorClass · 0.90
arrayMethod · 0.45
repeatMethod · 0.45

Tested by

no test coverage detected