-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
27 lines (20 loc) · 889 Bytes
/
Copy pathutils.py
File metadata and controls
27 lines (20 loc) · 889 Bytes
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
import torch
import numpy as np
import random
import torch.backends.cudnn as cudnn
def set_all_seeds(seed):
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
cudnn.deterministic = True
cudnn.benchmark = False
def preprocess_tensor(tensor, target_channels=32, feature_length=600):
# Determine how many samples should remain (nearest multiple of target_channels)
n_samples = tensor.shape[0]
truncate_size = (n_samples // target_channels) * target_channels # Nearest multiple of target_channels
# Truncate the tensor to make the number of samples divisible by target_channels
tensor_truncated = tensor[:truncate_size]
# Reshape the tensor to (x, target_channels, feature_length)
reshaped_tensor = tensor_truncated.view(-1, target_channels, feature_length)
return reshaped_tensor