-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiy_dataset.py
40 lines (31 loc) · 1.08 KB
/
diy_dataset.py
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
# from cProfile import label
import os
import torch
import torchvision.transforms as transforms
from torch.utils.data import Dataset
import pandas as pd
import numpy as np
# import matplotlib.pyplot as plt
class VADdataset(Dataset):
def __init__(self, voice_path: list , voice_label: list, transform= None):
self.voice_path = voice_path
self.voice_label = voice_label
self.transform = transform
def __len__(self):
return len(self.voice_path)
def __getitem__(self, index):
# 这一部分去用pd解析csv即可
voice = pd.read_csv(self.voice_path[index], header=None)
voice = np.array(voice)
voice = torch.tensor(voice)
voice = torch.unsqueeze(voice,0)
label = self.voice_label[index]
if self.transform is not None:
voice = self.transform(voice)
return voice, label
@staticmethod
def collate_fn(batch):
voice, label = tuple(zip(*batch))
images = torch.stack(images, dim=0)
labels = torch.as_tensor(label)
return voice, label