code-loader 1.0.185__tar.gz → 1.0.186__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {code_loader-1.0.185 → code_loader-1.0.186}/PKG-INFO +1 -1
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/contract/visualizer_classes.py +15 -5
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/inner_leap_binder/leapbinder_decorators.py +64 -9
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/plot_functions/plot_functions.py +25 -5
- {code_loader-1.0.185 → code_loader-1.0.186}/pyproject.toml +1 -1
- {code_loader-1.0.185 → code_loader-1.0.186}/LICENSE +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/README.md +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/__init__.py +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/contract/__init__.py +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/contract/datasetclasses.py +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/contract/enums.py +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/contract/exceptions.py +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/contract/mapping.py +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/contract/responsedataclasses.py +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/contract/sim_config.py +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/default_losses.py +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/default_metrics.py +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/experiment_api/__init__.py +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/experiment_api/api.py +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/experiment_api/cli_config_utils.py +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/experiment_api/client.py +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/experiment_api/epoch.py +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/experiment_api/experiment.py +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/experiment_api/experiment_context.py +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/experiment_api/types.py +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/experiment_api/utils.py +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/experiment_api/workingspace_config_utils.py +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/inner_leap_binder/__init__.py +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/inner_leap_binder/leapbinder.py +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/leaploader.py +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/leaploaderbase.py +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/mixpanel_tracker.py +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/plot_functions/__init__.py +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/plot_functions/visualize.py +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/utils.py +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/visualizers/__init__.py +0 -0
- {code_loader-1.0.185 → code_loader-1.0.186}/code_loader/visualizers/default_visualizers.py +0 -0
|
@@ -32,12 +32,14 @@ class LeapImage:
|
|
|
32
32
|
Visualizer representing an image for Tensorleap.
|
|
33
33
|
|
|
34
34
|
Attributes:
|
|
35
|
-
data (npt.NDArray[np.float32] | npt.NDArray[np.uint8]): The image data.
|
|
35
|
+
data (npt.NDArray[np.float32] | npt.NDArray[np.uint8]): The image data, shaped [H, W, 3] or [H, W, 1].
|
|
36
|
+
Expected pixel range is [0, 255]. Float values are cast to int (truncated, not scaled), so a
|
|
37
|
+
normalized [0, 1] float image renders near-black - scale it to [0, 255] or pass uint8.
|
|
36
38
|
type (LeapDataType): The data type, default is LeapDataType.Image.
|
|
37
39
|
compress: Optional[bool]: Whether to compress the image (.jpg) or not (.png)
|
|
38
40
|
|
|
39
41
|
Example:
|
|
40
|
-
image_data = np.random.rand(100, 100, 3).astype(np.float32)
|
|
42
|
+
image_data = (np.random.rand(100, 100, 3) * 255).astype(np.float32) # [0, 255]
|
|
41
43
|
leap_image = LeapImage(data=image_data)
|
|
42
44
|
"""
|
|
43
45
|
data: Union[npt.NDArray[np.float32], npt.NDArray[np.uint8]]
|
|
@@ -60,10 +62,12 @@ class LeapVideo:
|
|
|
60
62
|
|
|
61
63
|
Attributes:
|
|
62
64
|
data (npt.NDArray[np.float32] | npt.NDArray[np.uint8]): The video data, shaped [T, H, W, C], where T is the number of frames.
|
|
65
|
+
Note the range differs from still images: float video is expected in [0, 1] (it is scaled by 255),
|
|
66
|
+
while uint8 is used as-is in [0, 255]. Float values above 1 saturate to white.
|
|
63
67
|
type (LeapDataType): The data type, default is LeapDataType.Video.
|
|
64
68
|
|
|
65
69
|
Example:
|
|
66
|
-
video_data = np.random.rand(10, 100, 100, 3).astype(np.float32)
|
|
70
|
+
video_data = np.random.rand(10, 100, 100, 3).astype(np.float32) # [0, 1]
|
|
67
71
|
leap_video = LeapVideo(data=video_data)
|
|
68
72
|
"""
|
|
69
73
|
data: Union[npt.NDArray[np.float32], npt.NDArray[np.uint8]]
|
|
@@ -84,11 +88,13 @@ class LeapImageWithBBox:
|
|
|
84
88
|
|
|
85
89
|
Attributes:
|
|
86
90
|
data (npt.NDArray[np.float32] | npt.NDArray[np.uint8]): The image data, shaped [H, W, 3] or [H, W, 1].
|
|
91
|
+
Expected pixel range is [0, 255]. Float values are cast to int (truncated, not scaled), so a
|
|
92
|
+
normalized [0, 1] float image renders near-black - scale it to [0, 255] or pass uint8.
|
|
87
93
|
bounding_boxes (List[BoundingBox]): List of Tensorleap bounding boxes objects in relative size to image size.
|
|
88
94
|
type (LeapDataType): The data type, default is LeapDataType.ImageWithBBox.
|
|
89
95
|
|
|
90
96
|
Example:
|
|
91
|
-
image_data = np.random.rand(100, 100, 3).astype(np.float32)
|
|
97
|
+
image_data = (np.random.rand(100, 100, 3) * 255).astype(np.float32) # [0, 255]
|
|
92
98
|
bbox = BoundingBox(x=0.5, y=0.5, width=0.2, height=0.2, confidence=0.9, label="object")
|
|
93
99
|
leap_image_with_bbox = LeapImageWithBBox(data=image_data, bounding_boxes=[bbox])
|
|
94
100
|
"""
|
|
@@ -231,6 +237,8 @@ class LeapImageMask:
|
|
|
231
237
|
Attributes:
|
|
232
238
|
mask (npt.NDArray[np.uint8]): The mask data, shaped [H, W].
|
|
233
239
|
image (npt.NDArray[np.float32] | npt.NDArray[np.uint8]): The image data, shaped [H, W, 3] or shaped [H, W, 1].
|
|
240
|
+
Any pixel range is accepted: the image is min-max normalized to [0, 255] for display, so unlike the
|
|
241
|
+
plain Image visualizer, a normalized [0, 1] float renders fine here.
|
|
234
242
|
labels (List[str]): Labels associated with the mask regions; e.g., class names for segmented objects. The length of `labels` should match the number of unique values in `mask`.
|
|
235
243
|
type (LeapDataType): The data type, default is LeapDataType.ImageMask.
|
|
236
244
|
|
|
@@ -304,12 +312,14 @@ class LeapImageWithHeatmap:
|
|
|
304
312
|
|
|
305
313
|
Attributes:
|
|
306
314
|
image (npt.NDArray[np.float32]): The image data, shaped [H, W, C], where C is the number of channels.
|
|
315
|
+
Expected pixel range is [0, 255] (float is truncated to int, not scaled), so a normalized [0, 1] float
|
|
316
|
+
base image renders near-black - scale it to [0, 255]. The overlaid heatmaps are normalized separately.
|
|
307
317
|
heatmaps (npt.NDArray[np.float32]): The heatmap data, shaped [N, H, W], where N is the number of heatmaps.
|
|
308
318
|
labels (List[str]): Labels associated with the heatmaps; e.g., feature names or attention regions. The length of `labels` should match the number of heatmaps, N.
|
|
309
319
|
type (LeapDataType): The data type, default is LeapDataType.ImageWithHeatmap.
|
|
310
320
|
|
|
311
321
|
Example:
|
|
312
|
-
image_data = np.random.rand(100, 100, 3).astype(np.float32)
|
|
322
|
+
image_data = (np.random.rand(100, 100, 3) * 255).astype(np.float32) # [0, 255]
|
|
313
323
|
heatmaps = np.random.rand(3, 100, 100).astype(np.float32)
|
|
314
324
|
labels = ["heatmap1", "heatmap2", "heatmap3"]
|
|
315
325
|
leap_image_with_heatmap = LeapImageWithHeatmap(image=image_data, heatmaps=heatmaps, labels=labels)
|
{code_loader-1.0.185 → code_loader-1.0.186}/code_loader/inner_leap_binder/leapbinder_decorators.py
RENAMED
|
@@ -1102,19 +1102,33 @@ def _viz_prefix(viz_name: str, leap_type_name: str) -> str:
|
|
|
1102
1102
|
return f"Visualizer '{viz_name}' ({leap_type_name}):"
|
|
1103
1103
|
|
|
1104
1104
|
|
|
1105
|
+
def _warn_nonfinite(arr, viz_name: str, leap_type_name: str, field_name: str = "image data") -> None:
|
|
1106
|
+
"""Warn when a float array contains NaN/Inf. Applies to every image-like visualizer, including
|
|
1107
|
+
ImageMask (whose min-max normalization also can't render non-finite values)."""
|
|
1108
|
+
if not isinstance(arr, np.ndarray) or arr.size == 0:
|
|
1109
|
+
return
|
|
1110
|
+
if np.issubdtype(arr.dtype, np.floating) and not np.all(np.isfinite(arr)):
|
|
1111
|
+
store_general_warning(
|
|
1112
|
+
key=("viz_nonfinite", viz_name, leap_type_name, field_name),
|
|
1113
|
+
message=f"{_viz_prefix(viz_name, leap_type_name)} {field_name} contains NaN or Inf values, "
|
|
1114
|
+
f"which will render incorrectly.",
|
|
1115
|
+
link_to_docs=_VIZ_DOCS,
|
|
1116
|
+
)
|
|
1117
|
+
|
|
1118
|
+
|
|
1105
1119
|
def _warn_image_value_range(image, viz_name: str, leap_type_name: str, field_name: str = "image data") -> None:
|
|
1106
|
-
"""Warn when image pixel values sit in a range that
|
|
1120
|
+
"""Warn when still-image pixel values sit in a range that renders near-black or clipped.
|
|
1121
|
+
|
|
1122
|
+
Applies to Image / ImageWithBBox / ImageWithHeatmap, which the engine encodes with cv2
|
|
1123
|
+
(saturate_cast float->uint8, no scaling). Float is therefore expected in [0, 255]; a
|
|
1124
|
+
normalized [0, 1] float renders near-black. (Video and ImageMask use different conventions.)
|
|
1125
|
+
"""
|
|
1107
1126
|
if not isinstance(image, np.ndarray) or image.size == 0:
|
|
1108
1127
|
return
|
|
1109
1128
|
prefix = _viz_prefix(viz_name, leap_type_name)
|
|
1110
1129
|
|
|
1111
1130
|
if np.issubdtype(image.dtype, np.floating):
|
|
1112
|
-
|
|
1113
|
-
store_general_warning(
|
|
1114
|
-
key=("viz_image_nonfinite", viz_name, leap_type_name, field_name),
|
|
1115
|
-
message=f"{prefix} {field_name} contains NaN or Inf values, which will render incorrectly.",
|
|
1116
|
-
link_to_docs=_VIZ_DOCS,
|
|
1117
|
-
)
|
|
1131
|
+
_warn_nonfinite(image, viz_name, leap_type_name, field_name)
|
|
1118
1132
|
finite = image[np.isfinite(image)]
|
|
1119
1133
|
if finite.size == 0:
|
|
1120
1134
|
return
|
|
@@ -1147,6 +1161,42 @@ def _warn_image_value_range(image, viz_name: str, leap_type_name: str, field_nam
|
|
|
1147
1161
|
)
|
|
1148
1162
|
|
|
1149
1163
|
|
|
1164
|
+
def _warn_video_value_range(video, viz_name: str, leap_type_name: str, field_name: str = "video data") -> None:
|
|
1165
|
+
"""Warn when video pixel values won't survive the engine's float->uint8 scaling.
|
|
1166
|
+
|
|
1167
|
+
Unlike still images, the engine scales float video by 255 (videoencoder.py), so float is
|
|
1168
|
+
expected in [0, 1]; values above 1 saturate to white and negatives clip to black. uint8 is
|
|
1169
|
+
used as-is in [0, 255].
|
|
1170
|
+
"""
|
|
1171
|
+
if not isinstance(video, np.ndarray) or video.size == 0:
|
|
1172
|
+
return
|
|
1173
|
+
prefix = _viz_prefix(viz_name, leap_type_name)
|
|
1174
|
+
|
|
1175
|
+
if np.issubdtype(video.dtype, np.floating):
|
|
1176
|
+
_warn_nonfinite(video, viz_name, leap_type_name, field_name)
|
|
1177
|
+
finite = video[np.isfinite(video)]
|
|
1178
|
+
if finite.size == 0:
|
|
1179
|
+
return
|
|
1180
|
+
mn, mx = float(finite.min()), float(finite.max())
|
|
1181
|
+
if mn < 0.0 or mx > 1.0:
|
|
1182
|
+
store_general_warning(
|
|
1183
|
+
key=("viz_video_range", viz_name, leap_type_name, field_name),
|
|
1184
|
+
message=(f"{prefix} {field_name} is float with values in [{mn:.3g}, {mx:.3g}], outside the "
|
|
1185
|
+
f"expected [0,1] range. Tensorleap scales float video by 255, so values > 1 saturate "
|
|
1186
|
+
f"to white and negatives clip to black. Provide float video in [0,1], or uint8 in [0,255]."),
|
|
1187
|
+
link_to_docs=_VIZ_DOCS,
|
|
1188
|
+
)
|
|
1189
|
+
elif np.issubdtype(video.dtype, np.integer):
|
|
1190
|
+
mn, mx = int(video.min()), int(video.max())
|
|
1191
|
+
if mx <= 1:
|
|
1192
|
+
store_general_warning(
|
|
1193
|
+
key=("viz_video_int_low", viz_name, leap_type_name, field_name),
|
|
1194
|
+
message=(f"{prefix} {field_name} is uint8 but values span only [{mn}, {mx}] - this will appear "
|
|
1195
|
+
f"near-black. uint8 video is used as-is in [0,255]; scale to [0,255] before casting."),
|
|
1196
|
+
link_to_docs=_VIZ_DOCS,
|
|
1197
|
+
)
|
|
1198
|
+
|
|
1199
|
+
|
|
1150
1200
|
def _warn_bbox_coords(bounding_boxes, viz_name: str, leap_type_name: str) -> None:
|
|
1151
1201
|
"""Warn when bbox coords are not relative [0,1] (i.e. look like absolute pixels)."""
|
|
1152
1202
|
for bbox in bounding_boxes:
|
|
@@ -1247,9 +1297,14 @@ def _emit_visualizer_warnings(result, viz_name: str, visualizer_type: LeapDataTy
|
|
|
1247
1297
|
_warn_image_value_range(result.data, viz_name, leap_type_name)
|
|
1248
1298
|
_warn_bbox_coords(result.bounding_boxes, viz_name, leap_type_name)
|
|
1249
1299
|
elif visualizer_type == LeapDataType.Video:
|
|
1250
|
-
|
|
1300
|
+
# Engine scales float video by 255 (videoencoder.py), so float is expected in [0,1] here,
|
|
1301
|
+
# the opposite of the still-image convention.
|
|
1302
|
+
_warn_video_value_range(result.data, viz_name, leap_type_name)
|
|
1251
1303
|
elif visualizer_type == LeapDataType.ImageMask:
|
|
1252
|
-
|
|
1304
|
+
# Engine min-max normalizes the mask image (MaskEngineVisualizer._rescale_min_max), so any
|
|
1305
|
+
# finite value range renders fine - no range warning here. NaN/Inf still break normalization,
|
|
1306
|
+
# so keep that check alongside the structural mask checks.
|
|
1307
|
+
_warn_nonfinite(result.image, viz_name, leap_type_name)
|
|
1253
1308
|
_warn_image_mask(result, viz_name, leap_type_name)
|
|
1254
1309
|
elif visualizer_type == LeapDataType.ImageWithHeatmap:
|
|
1255
1310
|
_warn_image_with_heatmap(result, viz_name, leap_type_name)
|
|
@@ -21,6 +21,25 @@ import math
|
|
|
21
21
|
|
|
22
22
|
from code_loader.contract.visualizer_classes import LeapImage, LeapImageWithBBox, LeapGraph, LeapText, \
|
|
23
23
|
LeapHorizontalBar, LeapImageMask, LeapTextMask, LeapImageWithHeatmap, LeapVideo
|
|
24
|
+
from code_loader.utils import rescale_min_max
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _to_engine_image(image: np.ndarray) -> np.ndarray:
|
|
28
|
+
"""Match the engine's still-image encoding (cv2 saturate_cast): round + clip to [0,255],
|
|
29
|
+
no scaling, returned as uint8. Float is expected in [0,255]; a normalized [0,1] float
|
|
30
|
+
therefore renders near-black, exactly as it would on the platform."""
|
|
31
|
+
if np.issubdtype(image.dtype, np.floating):
|
|
32
|
+
return np.clip(np.rint(image), 0, 255).astype(np.uint8)
|
|
33
|
+
return np.clip(image, 0, 255).astype(np.uint8)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _to_engine_video(video: np.ndarray) -> np.ndarray:
|
|
37
|
+
"""Match the engine's video encoding (videoencoder.py): float is scaled by 255 then clipped,
|
|
38
|
+
uint8 is used as-is. Float is expected in [0,1]."""
|
|
39
|
+
if np.issubdtype(video.dtype, np.floating):
|
|
40
|
+
return (video * 255).clip(0, 255).astype(np.uint8)
|
|
41
|
+
return np.clip(video, 0, 255).astype(np.uint8)
|
|
42
|
+
|
|
24
43
|
|
|
25
44
|
def run_only_on_non_mapping_mode():
|
|
26
45
|
"""
|
|
@@ -51,7 +70,7 @@ def plot_image_with_b_box(leap_data: LeapImageWithBBox, title: str) -> None:
|
|
|
51
70
|
visualize(leap_image_with_bbox, title)
|
|
52
71
|
"""
|
|
53
72
|
|
|
54
|
-
image = leap_data.data
|
|
73
|
+
image = _to_engine_image(leap_data.data)
|
|
55
74
|
bounding_boxes = leap_data.bounding_boxes
|
|
56
75
|
|
|
57
76
|
# Create figure and axes
|
|
@@ -107,7 +126,7 @@ def plot_image(leap_data: LeapImage, title: str) -> None:
|
|
|
107
126
|
title = "Image"
|
|
108
127
|
visualize(leap_image, title)
|
|
109
128
|
"""
|
|
110
|
-
image_data = leap_data.data
|
|
129
|
+
image_data = _to_engine_image(leap_data.data)
|
|
111
130
|
|
|
112
131
|
# If the image has one channel, convert it to a 3-channel image for display
|
|
113
132
|
if image_data.shape[2] == 1:
|
|
@@ -305,7 +324,8 @@ def plot_image_mask(leap_data: LeapImageMask, title: str) -> None:
|
|
|
305
324
|
visualize(leap_image_mask, title)
|
|
306
325
|
"""
|
|
307
326
|
|
|
308
|
-
image
|
|
327
|
+
# Engine min-max normalizes the mask image to [0,255] (MaskEngineVisualizer._rescale_min_max)
|
|
328
|
+
image = rescale_min_max(leap_data.image)
|
|
309
329
|
mask = leap_data.mask
|
|
310
330
|
labels = leap_data.labels
|
|
311
331
|
|
|
@@ -390,7 +410,7 @@ def plot_text_mask(leap_data: LeapTextMask, title: str) -> None:
|
|
|
390
410
|
|
|
391
411
|
@run_only_on_non_mapping_mode()
|
|
392
412
|
def plot_video(leap_data: LeapVideo, title: str) -> None:
|
|
393
|
-
video_data = leap_data.data
|
|
413
|
+
video_data = _to_engine_video(leap_data.data)
|
|
394
414
|
fig, ax = plt.subplots()
|
|
395
415
|
fig.patch.set_facecolor('black')
|
|
396
416
|
ax.set_facecolor('black')
|
|
@@ -416,7 +436,7 @@ def plot_image_with_heatmap(leap_data: LeapImageWithHeatmap, title: str) -> None
|
|
|
416
436
|
title = "Image With Heatmap"
|
|
417
437
|
visualize(leap_image_with_heatmap, title)
|
|
418
438
|
"""
|
|
419
|
-
image = leap_data.image
|
|
439
|
+
image = _to_engine_image(leap_data.image)
|
|
420
440
|
heatmaps = leap_data.heatmaps
|
|
421
441
|
labels = leap_data.labels
|
|
422
442
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{code_loader-1.0.185 → code_loader-1.0.186}/code_loader/experiment_api/experiment_context.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{code_loader-1.0.185 → code_loader-1.0.186}/code_loader/experiment_api/workingspace_config_utils.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|