def LoadBatch(self):
     while True:
         if 'cnn' in self.criterion:
             if 'whole' in self.criterion or 'ctc' in self.criterion:
                 feat,label,length,lattice = self.CnnLoadNextNstreams()
             else:
                 feat,label,length,lattice = self.CnnSliceLoadNextNstreams()
         elif 'tdnn' in self.criterion:
             feat,label,length,lattice = self.TdnnLoadNextNstreams()
         elif 'chain' in self.criterion:
             feat,label,length,lattice = self.ChainLoadNextNstreams()
         else:
             if 'whole' in self.criterion or 'ctc' in self.criterion:
                 feat,label,length,lattice = self.WholeLoadNextNstreams()
             else:
                 feat,label,length,lattice = self.SliceLoadNextNstreams()
         if label is not None:
             if 'ctc' in self.criterion:
                 label = sparse_tuple_from(label)
         self.input_queue.put((feat,label,length,lattice))
         
         if feat is not None:
             print(numpy.shape(feat))
         else:
             print(feat)
         if feat is None:
             break
     print('end LoadBatch')
Пример #2
0
 def input_feat_and_label(self):
     feat, label, length = self.kaldi_io_nstream.LoadNextNstreams()
     if length is None:
         return False
     if len(label) != self.nnet_conf.batch_size:
         return False
     sparse_label = sparse_tuple_from(label)
     self.input_queue.put((feat, sparse_label, length))
     self.num_batch_total += 1
     for i in length:
         self.num_frames_total += i
     print('total_batch_num**********', self.num_batch_total, '***********')
     return True
 def input_feat_and_label(self):
     strat_io_time = time.time()
     feat, label, length = self.kaldi_io_nstream.LoadNextNstreams()
     end_io_time = time.time()
     #        print('*************io time**********************',end_io_time-strat_io_time)
     if length is None:
         return False
     if len(label) != self.nnet_conf.batch_size:
         return False
     sparse_label = sparse_tuple_from(label)
     self.input_queue.put((feat, sparse_label, length))
     self.num_batch_total += 1
     print('total_batch_num**********', self.num_batch_total, '***********')
     return True
Пример #4
0
    def InputFeat(self, input_lock):
        while True:
            input_lock.acquire()
            '''
            if 'ctc' in self.criterion_cf or 'whole' in self.criterion_cf:
                if 'cnn' in self.criterion_cf:
                    feat,label,length = self.kaldi_io_nstream.CnnLoadNextNstreams()
                else:
                    feat,label,length = self.kaldi_io_nstream.WholeLoadNextNstreams()
                if length is None:
                    break
                print(np.shape(feat),np.shape(label), np.shape(length))
                if len(label) != self.batch_size_cf:
                    break
                if 'ctc' in self.criterion_cf:
                    sparse_label = sparse_tuple_from(label)
                    self.input_queue.put((feat,sparse_label,length))
                else:
                    self.input_queue.put((feat,label,length))

            elif 'ce' in self.criterion_cf:
                if 'cnn' in self.criterion_cf:
                    feat_array, label_array, length_array = self.kaldi_io_nstream.CnnSliceLoadNextNstreams()
                else:
                    feat_array, label_array, length_array = self.kaldi_io_nstream.SliceLoadNextNstreams()
                if length_array is None:
                    break
                print(np.shape(feat_array),np.shape(label_array), np.shape(length_array))
                if len(label_array[0]) != self.batch_size_cf:
                    break
                self.input_queue.put((feat_array, label_array, length_array))
            '''
            feat,label,length = self.kaldi_io_nstream.LoadBatch()
            if length is None:
                break
            print(np.shape(feat),np.shape(label), np.shape(length))
            sys.stdout.flush()
            if 'ctc' in self.criterion_cf:
                sparse_label = sparse_tuple_from(label)
                self.input_queue.put((feat,sparse_label,length))
            else:
                self.input_queue.put((feat,label,length))
            self.num_batch_total += 1
#            if self.num_batch_total % 3000 == 0:
#                self.SaveModel()
#                self.AdjustLearnRate()
            print('total_batch_num**********',self.num_batch_total,'***********')
            input_lock.release()
        self.input_queue.put((None, None, None))
Пример #5
0
 def InputFeat(self, input_lock):
     while True:
         input_lock.acquire()
         feat,label,length = self.kaldi_io_nstream.LoadNextNstreams()
         if length is None:
             break
         if len(label) != self.batch_size_cf:
             break
         sparse_label = sparse_tuple_from(label)
         self.input_queue.put((feat,sparse_label,length))
         self.num_batch_total += 1
         if self.num_batch_total % 3000 == 0:
             self.SaveModel()
             self.AdjustLearnRate()
         print('total_batch_num**********',self.num_batch_total,'***********')
         input_lock.release()
     self.input_queue.put((None, None, None))