Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dataset.py « fargan « torch « dnn - gitlab.xiph.org/xiph/opus.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1454d05e63b1015ab5181ae750a2e0ba80a5e79b (plain)
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
50
51
52
53
54
55
56
57
58
59
60
import torch
import numpy as np
import fargan

class FARGANDataset(torch.utils.data.Dataset):
    def __init__(self,
                feature_file,
                signal_file,
                frame_size=160,
                sequence_length=15,
                lookahead=1,
                nb_used_features=20,
                nb_features=36):

        self.frame_size = frame_size
        self.sequence_length = sequence_length
        self.lookahead = lookahead
        self.nb_features = nb_features
        self.nb_used_features = nb_used_features
        pcm_chunk_size = self.frame_size*self.sequence_length

        self.data = np.memmap(signal_file, dtype='int16', mode='r')
        #self.data = self.data[1::2]
        self.nb_sequences = len(self.data)//(pcm_chunk_size)-4
        self.data = self.data[(4-self.lookahead)*self.frame_size:]
        self.data = self.data[:self.nb_sequences*pcm_chunk_size]


        #self.data = np.reshape(self.data, (self.nb_sequences, pcm_chunk_size))
        sizeof = self.data.strides[-1]
        self.data = np.lib.stride_tricks.as_strided(self.data, shape=(self.nb_sequences, pcm_chunk_size*2),
                                           strides=(pcm_chunk_size*sizeof, sizeof))

        self.features = np.reshape(np.memmap(feature_file, dtype='float32', mode='r'), (-1, nb_features))
        sizeof = self.features.strides[-1]
        self.features = np.lib.stride_tricks.as_strided(self.features, shape=(self.nb_sequences, self.sequence_length*2+4, nb_features),
                                           strides=(self.sequence_length*self.nb_features*sizeof, self.nb_features*sizeof, sizeof))
        self.periods = np.round(50*self.features[:,:,self.nb_used_features-2]+100).astype('int')

        self.lpc = self.features[:, :, self.nb_used_features:]
        self.features = self.features[:, :, :self.nb_used_features]
        print("lpc_size:", self.lpc.shape)

    def __len__(self):
        return self.nb_sequences

    def __getitem__(self, index):
        features = self.features[index, :, :].copy()
        if self.lookahead != 0:
            lpc = self.lpc[index, 4-self.lookahead:-self.lookahead, :].copy()
        else:
            lpc = self.lpc[index, 4:, :].copy()
        data = self.data[index, :].copy().astype(np.float32) / 2**15
        periods = self.periods[index, :].copy()
        lpc = lpc*(.92**np.arange(1,17))
        #lpc=lpc[None,:,:]
        #lpc = fargan.interp_lpc(lpc, 4)
        #lpc=lpc[0,:,:]

        return features, periods, data, lpc