espnet2.main_funcs package

espnet2.main_funcs.calculate_all_attentions

espnet2.main_funcs.calculate_all_attentions.calculate_all_attentions(model: espnet2.train.abs_espnet_model.AbsESPnetModel, batch: Dict[str, torch.Tensor]) → Dict[str, List[torch.Tensor]][source]

Derive the outputs from the all attention layers

Parameters
  • model

  • batch – same as forward

Returns

A dict of a list of tensor. key_names x batch x (D1, D2, …)

Return type

return_dict

espnet2.main_funcs.average_nbest_models

espnet2.main_funcs.average_nbest_models.average_nbest_models(output_dir: pathlib.Path, reporter: espnet2.train.reporter.Reporter, best_model_criterion: Sequence[Sequence[str]], nbest: Union[Collection[int], int]) → None[source]

Generate averaged model from n-best models

Parameters
  • output_dir – The directory contains the model file for each epoch

  • reporter – Reporter instance

  • best_model_criterion – Give criterions to decide the best model. e.g. [(“valid”, “loss”, “min”), (“train”, “acc”, “max”)]

  • nbest

espnet2.main_funcs.collect_stats

espnet2.main_funcs.collect_stats.collect_stats(model: espnet2.train.abs_espnet_model.AbsESPnetModel, train_iter: Iterable[Tuple[List[str], Dict[str, torch.Tensor]]], valid_iter: Iterable[Tuple[List[str], Dict[str, torch.Tensor]]], output_dir: pathlib.Path, ngpu: Optional[int], log_interval: Optional[int], write_collected_feats: bool) → None[source]

Perform on collect_stats mode.

Running for deriving the shape information from data and gathering statistics. This method is used before executing train().

espnet2.main_funcs.pack_funcs

class espnet2.main_funcs.pack_funcs.Archiver(file, mode='r')[source]

Bases: object

add(filename, arcname=None, recursive: bool = True)[source]
addfile(info, fileobj)[source]
close()[source]
extract(info, path=None)[source]
extractfile(info, mode='r')[source]
generate_info(name, size) → Union[tarfile.TarInfo, zipfile.ZipInfo][source]

Generate TarInfo using system information

get_name_from_info(info)[source]
espnet2.main_funcs.pack_funcs.find_path_and_change_it_recursive(value, src: str, tgt: str)[source]
espnet2.main_funcs.pack_funcs.get_dict_from_cache(meta: Union[pathlib.Path, str]) → Optional[Dict[str, str]][source]
espnet2.main_funcs.pack_funcs.pack(files: Dict[str, Union[str, pathlib.Path]], yaml_files: Dict[str, Union[str, pathlib.Path]], outpath: Union[str, pathlib.Path], option: Iterable[Union[str, pathlib.Path]] = ())[source]
espnet2.main_funcs.pack_funcs.unpack(input_archive: Union[pathlib.Path, str], outpath: Union[pathlib.Path, str], use_cache: bool = True) → Dict[str, str][source]

Scan all files in the archive file and return as a dict of files.

Examples

tarfile:

model.pth some1.file some2.file

>>> unpack("tarfile", "out")
{'asr_model_file': 'out/model.pth'}

espnet2.main_funcs.__init__