def images( self, columns=1, font_scale=1.0, line_width=3, figure_size=(8.0, 6.0), ): from paderbox.visualization import axes_context from paderbox.visualization.context_manager import _AxesHandler with axes_context( columns=columns, font_scale=font_scale, line_width=line_width, figure_size=figure_size, ) as axes: axes: _AxesHandler for k in self.review['images']: axes.new.grid(False) # set gca self.image(k)
def calculate_mapping(self, mask, plot=False): """Returns just the mapping based on permuted mask input. Args: mask: Permuted mask with shape (K, F, T). Returns: Reverse mapping with shape (K, F). """ K, F, _ = mask.shape assert F % 2 == 1, (F, 'Sure? Usually F is odd.') # (K, F, T) # features = mask / np.linalg.norm(mask, axis=-1, keepdims=True) if self.similarity_metric in ['cos']: features = _parameterized_vector_norm(mask, axis=-1) else: features = mask.copy() mapping = np.repeat(np.arange(K)[:, None], F, axis=1) if plot: from paderbox import visualization as vis # visualization import plot, axes_context tmp_mask = apply_mapping(features, mapping) with vis.axes_context(K + 1) as axes: for tmp_mask_k in tmp_mask: vis.plot.mask( tmp_mask_k.T, ax=axes.new, title=f'start', ) vis.plot.mask(mapping, limits=None, ax=axes.new) for iterations, start, end in self.alignment_plan: for iteration in range(iterations): # (K, T) time_centroid = np.mean(features[:, start:end, :], axis=1) if self.similarity_metric in ['cos']: time_centroid = _parameterized_vector_norm( time_centroid, axis=-1, ) nothing_changed = True for f in range(start, end): reverse_permutation = self._align_segment( features[:, f, :], time_centroid, ) if not (reverse_permutation == list(range(K))).all(): nothing_changed = False features[:, f, :] = features[reverse_permutation, f, :] mapping[:, f] = mapping[reverse_permutation, f] if nothing_changed: break return mapping