File size: 1,592 Bytes
69c07f8
752f897
 
69c07f8
 
752f897
69c07f8
 
752f897
 
69c07f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
752f897
69c07f8
 
752f897
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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