import torch # removed: numpy, nn, FrozenBatchNorm2d, logging, random, json, os, pathlib, dataset_split # — all dead after removing training helpers; only do_mixup and interpolate used by htsat.py # removed: freeze_batch_norm_2d — no longer imported after removing ModifiedResNet/timm_model # removed: exist, get_tar_path_from_dataset_name, get_tar_path_from_txts, get_mix_lambda # — dataset/tar path helpers, training data utilities, not used in inference def do_mixup(x, mixup_lambda): """ Args: x: (batch_size , ...) mixup_lambda: (batch_size,) Returns: out: (batch_size, ...) """ out = ( x.transpose(0, -1) * mixup_lambda + torch.flip(x, dims=[0]).transpose(0, -1) * (1 - mixup_lambda) ).transpose(0, -1) return out def interpolate(x, ratio): """Interpolate data in time domain. This is used to compensate the resolution reduction in downsampling of a CNN. Args: x: (batch_size, time_steps, classes_num) ratio: int, ratio to interpolate Returns: upsampled: (batch_size, time_steps * ratio, classes_num) """ (batch_size, time_steps, classes_num) = x.shape upsampled = x[:, :, None, :].repeat(1, 1, ratio, 1) upsampled = upsampled.reshape(batch_size, time_steps * ratio, classes_num) return upsampled # removed: pad_framewise_output — only used by pann_model (deleted) # removed: process_ipc, save_to_dict, get_data_from_log, save_p, load_p, save_json, load_json, # load_class_label, get_optimizer — training/logging/IO helpers, not used in inference