當前位置: 首頁>>代碼示例>>Python>>正文


Python kaldiio.load_mat方法代碼示例

本文整理匯總了Python中kaldiio.load_mat方法的典型用法代碼示例。如果您正苦於以下問題:Python kaldiio.load_mat方法的具體用法?Python kaldiio.load_mat怎麽用?Python kaldiio.load_mat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在kaldiio的用法示例。


在下文中一共展示了kaldiio.load_mat方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_dvector_dict_from_meetings

# 需要導入模塊: import kaldiio [as 別名]
# 或者: from kaldiio import load_mat [as 別名]
def get_dvector_dict_from_meetings(dvectors, args, meetings):
    """
        create two-level dictonary dict[meeting_name][speaker_id]
        value is list of numpy matrices
        the matrices are the dvectors of the segments
    """
    for meeting_name, seg_list in meetings.items():
        if args.filtEncomp is True:
            seg_list = filter_encompassed_segments(seg_list)
        for segment in seg_list:
            curspeaker = segment[2]
            cur_mat = kaldiio.load_mat(segment[0])
            if curspeaker not in dvectors[meeting_name]:
                dvectors[meeting_name][curspeaker] = []
            dvectors[meeting_name][curspeaker].append(cur_mat) 
開發者ID:FlorianKrey,項目名稱:DNC,代碼行數:17,代碼來源:gen_dvecdict.py

示例2: evaluate_spectralclustering

# 需要導入模塊: import kaldiio [as 別名]
# 或者: from kaldiio import load_mat [as 別名]
def evaluate_spectralclustering(args):
    """Loops through all meetings to call spectral clustering function"""
    total_correct = 0
    total_length = 0
    with open(args.injson) as _json_file:
        json_file = json.load(_json_file)
    results_dict = {}
    for midx, meeting in tqdm(list(json_file["utts"].items())):
        meeting_input = meeting["input"]
        meeting_output = meeting["output"]
        assert len(meeting_input) == 1
        assert len(meeting_output) == 1
        meeting_input = meeting_input[0]
        meeting_output = meeting_output[0]
        cur_mat = kaldiio.load_mat(meeting_input["feat"])#(samples,features)
        reference = meeting_output["tokenid"].split()
        reference = [int(ref) for ref in reference]
        assert len(reference) == cur_mat.shape[0]
        if len(reference) == 1:
            results_dict[midx] = [0]
            continue
        try:
            hypothesis = do_spectral_clustering(cur_mat,
                                                gauss_blur=args.gauss_blur,
                                                p_percentile=args.p_percentile,
                                                minclusters=int(args.minMaxK[0]),
                                                maxclusters=int(args.minMaxK[1]),
                                                truek=len(set(reference)),
                                                custom_dist=args.custom_dist)
        except:
            print("ERROR:: %s %s" % (str(reference), str(cur_mat)))
            raise
        results_dict[midx] = hypothesis
        _correct = permutation_invariant_seqmatch(hypothesis, reference)
        total_length += len(reference)
        total_correct += _correct
    print("Total Correct: %s, Total Length: %s, Percentage Correct: %s" %
          (str(total_correct), str(total_length), str(total_correct * 100 / total_length)))
    return results_dict 
開發者ID:FlorianKrey,項目名稱:DNC,代碼行數:41,代碼來源:run_spectralclustering.py

示例3: load_scp

# 需要導入模塊: import kaldiio [as 別名]
# 或者: from kaldiio import load_mat [as 別名]
def load_scp(scp_file):
    """load scp file to get meetingnames and their length"""
    meetings = {}
    with open(scp_file, 'r') as _scp_file:
        for line in _scp_file:
            segment_name, ark_pointer = line.split()
            meeting_name = 'AMI-' + segment_name.split('-')[2]
            start_time = int(segment_name.split('_')[2])
            end_time = int(segment_name.split('_')[3])
            num_frames = kaldiio.load_mat(ark_pointer).shape[0]
            meetings.setdefault(meeting_name, []).append((start_time, end_time, num_frames))
    return meetings 
開發者ID:FlorianKrey,項目名稱:DNC,代碼行數:14,代碼來源:gen_rttm.py

示例4: collect_meta

# 需要導入模塊: import kaldiio [as 別名]
# 或者: from kaldiio import load_mat [as 別名]
def collect_meta(self):
    data_paths = self.dataconf[self.mode]['paths']
    logging.info('Loading mode: [%s] dirs: %s ...' % (self.mode, data_paths))
    if len(data_paths) != 1:
      raise ValueError('More than 1 data dirs is not supported by now.')

    for data_path in data_paths:
      logging.info('Loading dir %s ...' % (data_path))
      if self.data_type == 'KaldiDataDirectory':
        self.kaldi_meta = KaldiDir(data_path)

        self.feats_scp_items = list(self.kaldi_meta.feats_scp.items())
        self.num_utts = self.kaldi_meta.num_utts
        self.class_nums = self.kaldi_meta.num_spks
        assert self.class_nums == self.taskconf['classes']['num']
        logging.info('The dataset have {} utts and {} speakers'.format(
            self.num_utts, self.class_nums))

        for _, (utt, feat_path) in enumerate(self.kaldi_meta.feats_scp.items()):
          self.feat_size = kaldiio.load_mat(feat_path).shape[1]
          break
        logging.info('feat_size {}'.format(self.feat_size))
        if self.feat_size < 0:
          raise Exception('Wrong feat_size {}'.format(self.feat_size))
      else:
        raise ValueError('Unsupported data type: %s' % (self.data_type))

    self._classes = self.kaldi_meta.spk2id 
開發者ID:didi,項目名稱:delta,代碼行數:30,代碼來源:speaker_cls_task.py

示例5: __getitem__

# 需要導入模塊: import kaldiio [as 別名]
# 或者: from kaldiio import load_mat [as 別名]
def __getitem__(self, batch_index, return_format=True):
    ''' get batch_index's batch data '''
    indexs = self.indexs[batch_index * self.batch_size:(batch_index + 1) *
                         self.batch_size]
    # key, feat_path
    batch_meta = [self.feats_scp_items[i] for i in indexs]

    batches = []
    for _, (utt_id, utt_path) in enumerate(batch_meta):
      spk_id = self.kaldi_meta.utt2spkid[utt_id]
      in_feat = kaldiio.load_mat(utt_path)
      in_feat = np.expand_dims(in_feat, axis=-1)
      batches.append((utt_id, spk_id, in_feat))

    uttids, segids, feats, spkids = self.collate_fn(batches)

    if not return_format:
      return uttids, segids, feats, spkids

    labels = np.array(spkids, dtype=np.int32)
    features = {
        'inputs': np.array(feats, dtype=np.float64),
        'labels': labels,
        'filepath': np.array(uttids),
        'clipid': np.array(segids, dtype=np.int32),
    }
    one_hot_labels = tf.keras.utils.to_categorical(
        labels, num_classes=self.class_nums)
    return features, one_hot_labels 
開發者ID:didi,項目名稱:delta,代碼行數:31,代碼來源:speaker_cls_task.py

示例6: apply_cmvn

# 需要導入模塊: import kaldiio [as 別名]
# 或者: from kaldiio import load_mat [as 別名]
def apply_cmvn():
  args = get_parser().parse_args()

  if ':' in args.stats_rspecifier_or_rxfilename:
    is_rspcifier = True
    stats_filetype = 'ark'
    stats_dict = dict(KaldiReader(args.stats_rspecifier_or_rxfilename))
  else:
    is_rspcifier = False
    stats_filetype = 'mat'
    stats = kaldiio.load_mat(args.stats_rspecifier_or_rxfilename)
    stats_dict = {None: stats}

  config = {}
  config['norm_means'] = args.norm_means
  config['norm_vars'] = args.norm_vars
  config['utt2spk'] = args.utt2spk
  config['spk2utt'] = args.spk2utt
  config['reverse'] = args.reverse
  config['std_floor'] = args.std_floor
  config['filetype'] = stats_filetype

  cmvn = CMVN.params(config).instantiate()
  cmvn.call(stats_dict)

  with KaldiWriter(args.wspecifier, write_num_frames=args.write_num_frames,
                compress=args.compress, compression_method=args.compression_method) as writer, \
    kaldiio.ReadHelper(args.rspecifier) as reader:
    for utt, mat in reader:
      mat_new = cmvn.apply_cmvn(mat, utt)
      writer[utt] = mat_new 
開發者ID:didi,項目名稱:delta,代碼行數:33,代碼來源:apply_cmvn.py

示例7: __getitem__

# 需要導入模塊: import kaldiio [as 別名]
# 或者: from kaldiio import load_mat [as 別名]
def __getitem__(self, index):
        utt_id, path = self.file_list[index]

        if self.from_kaldi:
            feature = kio.load_mat(path)
        else:
            wavform, sample_frequency = ta.load_wav(path)
            feature = compute_fbank(wavform, num_mel_bins=self.params['num_mel_bins'], sample_frequency=sample_frequency)

        if self.params['apply_cmvn']:
            spk_id = self.utt2spk[utt_id]
            stats = kio.load_mat(self.cmvns[spk_id])
            feature = apply_cmvn(feature, stats)

        if self.params['normalization']:
            feature = normalization(feature)
            
        if self.params['spec_augment']:
            feature = spec_augment(feature)

        if self.left_frames > 0 or self.right_frames > 0:
            feature = concat_and_subsample(feature, left_frames=self.left_frames,
                                           right_frames=self.right_frames, skip_frames=self.skip_frames)

        feature_length = feature.shape[0]
        targets = self.targets_dict[utt_id]
        targets_length = len(targets)

        return utt_id, feature, feature_length, targets, targets_length 
開發者ID:ZhengkunTian,項目名稱:OpenTransformer,代碼行數:31,代碼來源:data.py

示例8: make_mini_batch

# 需要導入模塊: import kaldiio [as 別名]
# 或者: from kaldiio import load_mat [as 別名]
def make_mini_batch(self, df_indices_mb):
        """Create mini-batch per step.

        Args:
            df_indices_mb (np.ndarray): indices of dataframe in the current mini-batch
        Returns:
            mini_batch_dict (dict):
                xs (list): input data of size `[T, input_dim]`
                xlens (list): lengths of xs
                ys (list): reference labels in the main task of size `[L]`
                ys_sub1 (list): reference labels in the 1st auxiliary task of size `[L_sub1]`
                ys_sub2 (list): reference labels in the 2nd auxiliary task of size `[L_sub2]`
                utt_ids (list): name of each utterance
                speakers (list): name of each speaker
                sessions (list): name of each session

        """
        # inputs
        xs = [kaldiio.load_mat(self.df['feat_path'][i]) for i in df_indices_mb]

        # outputs
        if self.is_test:
            ys = [self.token2idx[0](self.df['text'][i]) for i in df_indices_mb]
        else:
            ys = [list(map(int, str(self.df['token_id'][i]).split())) for i in df_indices_mb]

        ys_sub1 = []
        if self.df_sub1 is not None:
            ys_sub1 = [list(map(int, str(self.df_sub1['token_id'][i]).split())) for i in df_indices_mb]
        elif self.vocab_sub1 > 0 and not self.is_test:
            ys_sub1 = [self.token2idx[1](self.df['text'][i]) for i in df_indices_mb]

        ys_sub2 = []
        if self.df_sub2 is not None:
            ys_sub2 = [list(map(int, str(self.df_sub2['token_id'][i]).split())) for i in df_indices_mb]
        elif self.vocab_sub2 > 0 and not self.is_test:
            ys_sub2 = [self.token2idx[2](self.df['text'][i]) for i in df_indices_mb]

        mini_batch_dict = {
            'xs': xs,
            'xlens': [self.df['xlen'][i] for i in df_indices_mb],
            'ys': ys,
            'ys_sub1': ys_sub1,
            'ys_sub2': ys_sub2,
            'utt_ids': [self.df['utt_id'][i] for i in df_indices_mb],
            'speakers': [self.df['speaker'][i] for i in df_indices_mb],
            'sessions': [self.df['session'][i] for i in df_indices_mb],
            'text': [self.df['text'][i] for i in df_indices_mb],
            'feat_path': [self.df['feat_path'][i] for i in df_indices_mb],  # for plot
        }
        return mini_batch_dict 
開發者ID:hirofumi0810,項目名稱:neural_sp,代碼行數:53,代碼來源:asr.py

示例9: main

# 需要導入模塊: import kaldiio [as 別名]
# 或者: from kaldiio import load_mat [as 別名]
def main():
    args = get_parser().parse_args()

    # logging info
    logfmt = "%(asctime)s (%(module)s:%(lineno)d) %(levelname)s: %(message)s"
    if args.verbose > 0:
        logging.basicConfig(level=logging.INFO, format=logfmt)
    else:
        logging.basicConfig(level=logging.WARN, format=logfmt)
    logging.info(get_commandline_args())

    if ":" in args.stats_rspecifier_or_rxfilename:
        is_rspcifier = True
        if args.stats_filetype == "npy":
            stats_filetype = "hdf5"
        else:
            stats_filetype = args.stats_filetype

        stats_dict = dict(
            file_reader_helper(args.stats_rspecifier_or_rxfilename, stats_filetype)
        )
    else:
        is_rspcifier = False
        if args.stats_filetype == "mat":
            stats = kaldiio.load_mat(args.stats_rspecifier_or_rxfilename)
        else:
            stats = numpy.load(args.stats_rspecifier_or_rxfilename)
        stats_dict = {None: stats}

    cmvn = CMVN(
        stats=stats_dict,
        norm_means=args.norm_means,
        norm_vars=args.norm_vars,
        utt2spk=args.utt2spk,
        spk2utt=args.spk2utt,
        reverse=args.reverse,
    )

    with file_writer_helper(
        args.wspecifier,
        filetype=args.out_filetype,
        write_num_frames=args.write_num_frames,
        compress=args.compress,
        compression_method=args.compression_method,
    ) as writer:
        for utt, mat in file_reader_helper(args.rspecifier, args.in_filetype):
            if is_scipy_wav_style(mat):
                # If data is sound file, then got as Tuple[int, ndarray]
                rate, mat = mat
            mat = cmvn(mat, utt if is_rspcifier else None)
            writer[utt] = mat 
開發者ID:espnet,項目名稱:espnet,代碼行數:53,代碼來源:apply-cmvn.py

示例10: call

# 需要導入模塊: import kaldiio [as 別名]
# 或者: from kaldiio import load_mat [as 別名]
def call(self, stats):
    """
    Do CMVN.
    :param stats: Statistics of features.
    :return: Mean and std of features.
    """
    p = self.config

    if isinstance(stats, dict):
      stats_dict = dict(stats)
    else:
      if p.filetype == 'mat':
        stats_dict = {None: kaldiio.load_mat(stats)}
      elif p.filetype == 'ark':
        stats_dict = dict(kaldiio.load_ark(stats))
      else:
        raise ValueError('Not supporting filetype={}'.format(p.filetype))

    if p.utt2spk is not None:
      self.utt2spk = {}
      with io.open(p.utt2spk, 'r', encoding='utf-8') as f:
        for line in f:
          utt, spk = line.rstrip().split(None, 1)
          self.utt2spk[utt] = spk

    elif p.spk2utt is not None:
      self.utt2spk = {}
      with io.open(p.spk2utt, 'r', encoding='utf-8') as f:
        for line in f:
          spk, utts = line.rstrip().split(None, 1)
          for utt in utts.split():
            self.utt2spk[utt] = spk
    else:
      self.utt2spk = None

    self.bias = {}
    self.scale = {}
    for spk, stats in stats_dict.items():
      assert len(stats) == 2, stats.shape

      count = stats[0, -1]

      if not (np.isscalar(count) or isinstance(count, (int, float))):
        count = count.flatten()[0]

      mean = stats[0, :-1] / count
      var = stats[1, :-1] / count - mean * mean
      std = np.maximum(np.sqrt(var), p.std_floor)
      self.bias[spk] = -mean
      self.scale[spk] = 1 / std 
開發者ID:didi,項目名稱:delta,代碼行數:52,代碼來源:cmvn.py


注:本文中的kaldiio.load_mat方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。