code-loader 1.0.199__tar.gz → 1.0.201.dev0__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.
Files changed (37) hide show
  1. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/PKG-INFO +1 -1
  2. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/contract/datasetclasses.py +4 -3
  3. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/contract/visualizer_classes.py +3 -10
  4. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/visualizers/default_visualizers.py +21 -28
  5. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/pyproject.toml +1 -1
  6. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/LICENSE +0 -0
  7. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/README.md +0 -0
  8. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/__init__.py +0 -0
  9. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/contract/__init__.py +0 -0
  10. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/contract/enums.py +0 -0
  11. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/contract/exceptions.py +0 -0
  12. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/contract/mapping.py +0 -0
  13. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/contract/responsedataclasses.py +0 -0
  14. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/contract/sim_config.py +0 -0
  15. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/default_losses.py +0 -0
  16. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/default_metrics.py +0 -0
  17. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/experiment_api/__init__.py +0 -0
  18. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/experiment_api/api.py +0 -0
  19. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/experiment_api/cli_config_utils.py +0 -0
  20. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/experiment_api/client.py +0 -0
  21. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/experiment_api/epoch.py +0 -0
  22. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/experiment_api/experiment.py +0 -0
  23. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/experiment_api/experiment_context.py +0 -0
  24. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/experiment_api/types.py +0 -0
  25. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/experiment_api/utils.py +0 -0
  26. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/experiment_api/workingspace_config_utils.py +0 -0
  27. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/inner_leap_binder/__init__.py +0 -0
  28. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/inner_leap_binder/leapbinder.py +0 -0
  29. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/inner_leap_binder/leapbinder_decorators.py +0 -0
  30. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/leaploader.py +0 -0
  31. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/leaploaderbase.py +0 -0
  32. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/mixpanel_tracker.py +0 -0
  33. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/plot_functions/__init__.py +0 -0
  34. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/plot_functions/plot_functions.py +0 -0
  35. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/plot_functions/visualize.py +0 -0
  36. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/utils.py +0 -0
  37. {code_loader-1.0.199 → code_loader-1.0.201.dev0}/code_loader/visualizers/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: code-loader
3
- Version: 1.0.199
3
+ Version: 1.0.201.dev0
4
4
  Summary:
5
5
  Home-page: https://github.com/tensorleap/code-loader
6
6
  License: MIT
@@ -8,7 +8,7 @@ import numpy.typing as npt
8
8
  from code_loader.contract.enums import DataStateType, DataStateEnum, LeapDataType, ConfusionMatrixValue, \
9
9
  MetricDirection, DatasetMetadataType
10
10
  from code_loader.contract.visualizer_classes import LeapImage, LeapText, LeapGraph, LeapHorizontalBar, \
11
- LeapTextMask, LeapImageMask, LeapImageWithBBox, LeapImageWithHeatmap, LeapVideo
11
+ LeapTextMask, LeapImageMask, LeapImageWithBBox, LeapImageWithHeatmap, LeapVideo, LeapAudio
12
12
  from code_loader.contract.sim_config import SimConfig
13
13
 
14
14
  custom_latent_space_attribute = "custom_latent_space"
@@ -194,11 +194,12 @@ VisualizerCallableInterface = Union[
194
194
  Callable[..., LeapImageMask],
195
195
  Callable[..., LeapTextMask],
196
196
  Callable[..., LeapImageWithBBox],
197
- Callable[..., LeapImageWithHeatmap]
197
+ Callable[..., LeapImageWithHeatmap],
198
+ Callable[..., LeapAudio]
198
199
  ]
199
200
 
200
201
  LeapData = Union[LeapImage, LeapText, LeapGraph, LeapHorizontalBar, LeapImageMask, LeapTextMask, LeapImageWithBBox,
201
- LeapImageWithHeatmap, LeapVideo]
202
+ LeapImageWithHeatmap, LeapVideo, LeapAudio]
202
203
 
203
204
  CustomCallableInterface = Callable[..., Any]
204
205
 
@@ -357,16 +357,14 @@ class LeapAudio:
357
357
  should be mixed down before constructing LeapAudio.
358
358
  sample_rate (int): Samples per second — needed to encode the clip and to map
359
359
  the playhead position to time.
360
- visual (Union[LeapImage, LeapGraph]): The thing you look at.
361
- x_range (Optional[Tuple[float, float]]): Time extent (in seconds) that the
362
- visual's horizontal axis spans, used to align the tick. Defaults to
363
- (0, N / sample_rate).
360
+ visual (Union[LeapImage, LeapGraph]): The thing you look at. For a waveform
361
+ the nested LeapGraph carries its own x_range (time span); the playhead is
362
+ driven by the audio element's currentTime, so no time range is needed here.
364
363
  type (LeapDataType): The data type, default is LeapDataType.Audio.
365
364
  """
366
365
  audio: npt.NDArray
367
366
  sample_rate: int
368
367
  visual: Union[LeapImage, LeapGraph]
369
- x_range: Optional[Tuple[float, float]] = None
370
368
  type: LeapDataType = LeapDataType.Audio
371
369
 
372
370
  def __post_init__(self) -> None:
@@ -377,11 +375,6 @@ class LeapAudio:
377
375
  'Audio visual must be a LeapImage (spectrogram) or LeapGraph (waveform)')
378
376
  if not isinstance(self.sample_rate, int) or self.sample_rate <= 0:
379
377
  raise LeapValidationError(f'sample_rate must be a positive int, got {self.sample_rate}')
380
- if self.x_range is not None:
381
- if len(self.x_range) != 2:
382
- raise LeapValidationError('x_range must be a tuple of length 2')
383
- validate_type(type(self.x_range[0]), [float, int], 'x_range must be a tuple of floats or integers')
384
- validate_type(type(self.x_range[1]), [float, int], 'x_range must be a tuple of floats or integers')
385
378
 
386
379
 
387
380
  map_leap_data_type_to_visualizer_class = {
@@ -31,7 +31,6 @@ def default_video_visualizer(data: npt.NDArray[np.float32]) -> LeapVideo:
31
31
 
32
32
 
33
33
  _MAX_WAVEFORM_POINTS = 2000
34
- _VISUAL_KINDS = ('waveform', 'spectrogram', 'image')
35
34
 
36
35
 
37
36
  def _to_mono(audio: npt.NDArray) -> npt.NDArray:
@@ -54,49 +53,43 @@ def _waveform_graph(series: npt.NDArray, duration: float) -> LeapGraph:
54
53
  def default_audio_visualizer(audio: npt.NDArray,
55
54
  sample_rate: int,
56
55
  visual: Optional[npt.NDArray] = None,
57
- visual_kind: Optional[str] = None,
58
56
  time_axis_index: int = -1) -> LeapAudio:
59
57
  """Package a playable audio sample plus the visual a playhead runs through.
60
58
 
61
59
  audio: waveform samples (mono [N], or multi-channel that is mixed down).
62
60
  sample_rate: samples per second.
63
- visual: the array to display. For 'waveform' a 1-D series; for 'spectrogram'
64
- a raw 2-D [freq, time] (or [time, freq]) array to be rendered grayscale;
65
- for 'image' an already-rendered [H, W, 1] or [H, W, 3] image (e.g. a
66
- spectrogram the caller already ran through their own colormap).
61
+ visual: the array to display; its kind is deduced from its shape.
62
+ 1-D [N] -> waveform graph of the samples.
63
+ 2-D [H, W] -> spectrogram, rendered grayscale.
64
+ 3-D [H, W, C] -> already-rendered image; C must be 3 (rgb) or 1 (grayscale).
67
65
  If omitted, a waveform graph is built from `audio` itself.
68
- visual_kind: 'waveform', 'spectrogram', or 'image'. The caller states this
69
- explicitly; the shape of `visual` is never inspected to guess it.
70
- Required when `visual` is given; ignored when `visual` is omitted.
71
- time_axis_index: for 'spectrogram', which axis of `visual` is time (moved to columns).
72
- Unused for 'waveform'/'image'.
66
+ time_axis_index: for a spectrogram, which axis of `visual` is time (moved to columns).
67
+ Unused otherwise.
73
68
  """
74
69
  mono = _to_mono(audio)
75
70
  duration = mono.shape[0] / float(sample_rate)
76
- x_range = (0.0, duration)
77
71
 
78
72
  if visual is None: # no visual given: show the raw signal as a waveform
79
- return LeapAudio(mono, sample_rate, _waveform_graph(mono, duration), x_range)
80
-
81
- if visual_kind not in _VISUAL_KINDS:
82
- raise ValueError(f"visual_kind must be one of {_VISUAL_KINDS}, got {visual_kind!r}")
73
+ return LeapAudio(mono, sample_rate, _waveform_graph(mono, duration))
83
74
 
84
75
  v = np.asarray(visual)
85
76
 
86
- if visual_kind == 'waveform':
87
- return LeapAudio(mono, sample_rate, _waveform_graph(v, duration), x_range)
77
+ if v.ndim == 1: # waveform
78
+ return LeapAudio(mono, sample_rate, _waveform_graph(v, duration))
79
+
80
+ if v.ndim == 3: # already-rendered image
81
+ if v.shape[-1] not in (1, 3):
82
+ raise ValueError(f'image visual must have 1 (grayscale) or 3 (rgb) channels, got shape {v.shape}')
83
+ return LeapAudio(mono, sample_rate, LeapImage(v))
88
84
 
89
- if visual_kind == 'image':
90
- return LeapAudio(mono, sample_rate, LeapImage(v), x_range)
85
+ if v.ndim == 2: # spectrogram
86
+ spec = v
87
+ if time_axis_index % 2 == 0: # move time onto the horizontal axis (columns)
88
+ spec = spec.T
89
+ img = rescale_min_max(spec.astype(np.float32))[..., None] # [freq, time, 1]
90
+ return LeapAudio(mono, sample_rate, LeapImage(img))
91
91
 
92
- # spectrogram
93
- spec = np.squeeze(v)
94
- if spec.ndim != 2:
95
- raise ValueError(f'spectrogram visual must be 2-D (freq x time), got shape {v.shape}')
96
- if time_axis_index % spec.ndim == 0: # move time onto the horizontal axis (columns)
97
- spec = spec.T
98
- img = rescale_min_max(spec.astype(np.float32))[..., None] # [freq, time, 1]
99
- return LeapAudio(mono, sample_rate, LeapImage(img), x_range)
92
+ raise ValueError(f'visual must be 1-D, 2-D, or 3-D, got shape {v.shape}')
100
93
 
101
94
 
102
95
  def default_graph_visualizer(data: npt.NDArray[np.float32]) -> LeapGraph:
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "code-loader"
3
- version = "1.0.199"
3
+ version = "1.0.201.dev0"
4
4
  description = ""
5
5
  authors = ["dorhar <doron.harnoy@tensorleap.ai>"]
6
6
  license = "MIT"