Spaces:
Sleeping
Sleeping
| import torch | |
| 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 | |