Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update speaker_id.py #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update speaker_id.py
better regularization / generalization, and avoid nan value (for audio file with all zero samples)
  • Loading branch information
rickychanhoyin authored Jul 4, 2019
commit 0c44a7f5192ffb454128a6f1a3d1c10d8238e90d
7 changes: 5 additions & 2 deletions speaker_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ def create_batches_rnd(batch_size,data_folder,wav_lst,N_snt,wlen,lab_dict,fact_a
if channels == 2:
print('WARNING: stereo to mono: '+data_folder+wav_lst[snt_id_arr[i]])
signal = signal[:,0]

rand_noise_arr = np.random.normal(0, 1e-20, len(signal))

sig_batch[i,:]=signal[snt_beg:snt_end]*rand_amp_arr[i]
sig_batch[i,:]=signal[snt_beg:snt_end]*rand_amp_arr[i]+rand_noise_arr[snt_beg:snt_end]
lab_batch[i]=lab_dict[wav_lst[snt_id_arr[i]]]

inp=Variable(torch.from_numpy(sig_batch).float().cuda().contiguous())
Expand Down Expand Up @@ -291,8 +293,9 @@ def create_batches_rnd(batch_size,data_folder,wav_lst,N_snt,wlen,lab_dict,fact_a
pout=Variable(torch.zeros(N_fr+1,class_lay[-1]).float().cuda().contiguous())
count_fr=0
count_fr_tot=0
rand_noise_arr = np.random.normal(0, 1e-20, len(signal))
while end_samp<signal.shape[0]:
sig_arr[count_fr,:]=signal[beg_samp:end_samp]
sig_arr[count_fr,:]=signal[beg_samp:end_samp]+rand_noise_arr[beg_samp:end_samp]
beg_samp=beg_samp+wshift
end_samp=beg_samp+wlen
count_fr=count_fr+1
Expand Down