Exemple #1
0
def preprocess_data_1(_X, _X_test, _seq_len, _nb_ch):
    # 把数据_seq_len毎に切开
    # split into sequences
    _X = utils.split_in_seqs(_X, _seq_len)
    _X_test = utils.split_in_seqs(_X_test, _seq_len)
    _X = utils.split_multi_channels(_X, _nb_ch)
    _X_test = utils.split_multi_channels(_X_test, _nb_ch)
    return _X, _X_test
def preprocess_data(_X, _Y, _X_test, _Y_test, _seq_len, _nb_ch):
    # split into sequences
    _X = utils.split_in_seqs(_X, _seq_len)
    _Y = utils.split_in_seqs(_Y, _seq_len)

    _X_test = utils.split_in_seqs(_X_test, _seq_len)
    _Y_test = utils.split_in_seqs(_Y_test, _seq_len)

    _X = utils.split_multi_channels(_X, _nb_ch)
    _X_test = utils.split_multi_channels(_X_test, _nb_ch)
    return _X, _Y, _X_test, _Y_test
def preprocess_data(_X, _Y, _X_test, _Y_test, _seq_len, _nb_ch):
    # split into sequences

    print "before split multi channel: ", _X.shape
    _X = split_in_seqs(_X, 1)
    #_Y = split_in_seqs(_Y, 1)

    _X_test = split_in_seqs(_X_test, 1)
    # _Y_test = split_in_seqs(_Y_test, 1)

    print "split multi channel: ", _X.shape
    _X = split_multi_channels(_X, _nb_ch)
    _X_test = split_multi_channels(_X_test, _nb_ch)
    # _X = _X.reshape(-1, 1, 40, 2).astype('float32')
    # _X_test = _X_test.reshape(-1, 1, 40, 2).astype('float32')

    # add extra label

    _Y_extra = np.zeros((_Y.shape[0],7))
    _Y_extra[:,:-1] = _Y
    for i in range( _Y.shape[0] ):
        if sum(_Y[i]) > 0:
            _Y_extra[i][6] = 0
        else:
            _Y_extra[i][6] = 1

    _Y_test_extra = np.zeros((_Y_test.shape[0],7))
    _Y_test_extra[:,:-1] = _Y_test
    for i in range( _Y_test.shape[0] ):
        if sum(_Y_test[i]) > 0:
            _Y_test_extra[i][6] = 0
        else:
            _Y_test_extra[i][6] = 1

    # np.apply_along_axis( addLabel, axis=1, arr=b )
    return _X, _Y_extra, _X_test, _Y_test_extra
for file in filename:
    print('count = ', count)
    mix = utils.get_input(dir_mix + file)
    s1 = utils.get_input(dir_s1 + file)
    s2 = utils.get_input(dir_s2 + file)

    spec0, spec_mix, VAD = utils.get_features(mix)

    norm_spec_mix = norm_fea(spec_mix)
    _, spec_s1, _ = utils.get_features(s1)
    _, spec_s2, _ = utils.get_features(s2)

    mask_1 = spec_s1 > spec_s2
    mask_2 = spec_s1 <= spec_s2

    splitted_spec_mix = utils.split_in_seqs(norm_spec_mix.T,
                                            norm_spec_mix.shape[1])
    splitted_VAD = utils.split_in_seqs(VAD.T,
                                       spec_mix.shape[1]).astype('float32')
    #splitted_spec_mix = utils.split_in_seqs(norm_spec_mix.T,200)
    splitted_spec_mix_tensor = torch.from_numpy(splitted_spec_mix)

    model = DC_net(glob_constant.input_dim, glob_constant.hidden_dim,
                   splitted_spec_mix_tensor.size(0), glob_constant.Embedding,
                   4, glob_constant.dropout)

    model.load_state_dict(torch.load(model_path, map_location=device))
    model.eval()
    with torch.no_grad():
        hidden = model.init_hidden()
        embedding = model(splitted_spec_mix_tensor, hidden)
        embeddings = embedding.numpy()