Walleclipse / Deep_Speaker-speaker_recognition_system

Keras implementation of ‘’Deep Speaker: an End-to-End Neural Speaker Embedding System‘’ (speaker recognition)
245 stars 81 forks source link

batchTrainingImageLoader in pretraining.py #49

Closed jayxio closed 3 years ago

jayxio commented 4 years ago

The implementation is impressive.

However, I wonder the following code's necessity:

def batchTrainingImageLoader(train_data, labels_to_id, no_of_speakers, batch_size=c.BATCH_SIZE * c.TRIPLET_PER_BATCH):
    paths = train_data
    L = len(paths)
    while True:
        np.random.shuffle(paths)
        batch_start = 0
        batch_end = batch_size

        while batch_end < L:
            x_train_t, y_train_t = loadFromList(paths, batch_start, batch_end, labels_to_id, no_of_speakers)
            randnum = random.randint(0, 100)
            random.seed(randnum)
            random.shuffle(x_train_t)
            random.seed(randnum)
            random.shuffle(y_train_t)
            yield (x_train_t, y_train_t)
            batch_start += batch_size
            batch_end += batch_size

So the purpose of

            random.seed(randnum)
            random.shuffle(x_train_t)
            random.seed(randnum)
            random.shuffle(y_train_t)

is to randomize yield batch (x_train_t, y_train_t). But, from my opinion, the order of samples within a batch does not affect any training?

Looking forward for your reply!

jayxio commented 4 years ago

And actually, random.shuffle(y_train_t) ruins the y_train_t(if you check it out), so if we use this code, the model cannot learn anything...

Walleclipse commented 4 years ago
  1. I didn't think about it before. But now, I think you are right "the order of samples within a batch does not affect any training."
  2. I don't think random.shuffle(y_train_t) ruins the y_train_t. I don't quite understand this point. y_train_tis labels of speakers, which still corresponds to x_train_t