Kaldi
post-to-smat.cc
Go to the documentation of this file.
1
// bin/post-to-smat.cc
2
3
// Copyright 2017 Johns Hopkins University (Author: Daniel Povey)
4
5
// See ../../COPYING for clarification regarding multiple authors
6
//
7
// Licensed under the Apache License, Version 2.0 (the "License");
8
// you may not use this file except in compliance with the License.
9
// You may obtain a copy of the License at
10
//
11
// http://www.apache.org/licenses/LICENSE-2.0
12
//
13
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15
// WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16
// MERCHANTABLITY OR NON-INFRINGEMENT.
17
// See the Apache 2 License for the specific language governing permissions and
18
// limitations under the License.
19
20
21
#include "
base/kaldi-common.h
"
22
#include "
util/common-utils.h
"
23
#include "
hmm/posterior.h
"
24
25
int
main
(
int
argc,
char
*argv[]) {
26
using namespace
kaldi
;
27
typedef
kaldi::int32
int32
;
28
try
{
29
const
char
*usage =
30
"This program turns an archive of per-frame posteriors, e.g. from\n"
31
"ali-to-post | post-to-pdf-post,\n"
32
"into an archive of SparseMatrix. This is just a format transformation.\n"
33
"This may not make sense if the indexes in question are one-based (at least,\n"
34
"you'd have to increase the dimension by one.\n"
35
"\n"
36
"See also: post-to-phone-post, ali-to-post, post-to-pdf-post\n"
37
"\n"
38
"Usage: post-to-smat [options] <posteriors-rspecifier> <sparse-matrix-wspecifier>\n"
39
"e.g.: post-to-smat --dim=1038 ark:- ark:-\n"
;
40
41
ParseOptions
po(usage);
42
43
int32 dim = -1;
44
45
po.
Register
(
"dim"
, &dim,
"The num-cols in each output SparseMatrix. All "
46
"the integers in the input posteriors are expected to be \n"
47
">= 0 and < dim. This must be specified."
);
48
49
po.
Read
(argc, argv);
50
51
if
(po.
NumArgs
() != 2) {
52
po.
PrintUsage
();
53
exit(1);
54
}
55
56
if
(dim <= 0) {
57
KALDI_ERR
<<
"The --dim option must be specified."
;
58
}
59
60
61
std::string posteriors_rspecifier = po.
GetArg
(1),
62
sparse_matrix_wspecifier = po.
GetArg
(2);
63
64
65
SequentialPosteriorReader
posterior_reader(posteriors_rspecifier);
66
67
TableWriter<KaldiObjectHolder<SparseMatrix<BaseFloat>
> > sparse_matrix_writer(
68
sparse_matrix_wspecifier);
69
70
int32 num_done = 0;
71
for
(; !posterior_reader.
Done
(); posterior_reader.
Next
()) {
72
const
kaldi::Posterior
&posterior = posterior_reader.
Value
();
73
// The following constructor will throw an error if there is some kind of
74
// dimension mismatch.
75
SparseMatrix<BaseFloat>
smat(dim, posterior);
76
sparse_matrix_writer.
Write
(posterior_reader.
Key
(), smat);
77
num_done++;
78
}
79
KALDI_LOG
<<
"Done converting "
<< num_done
80
<<
" posteriors into sparse matrices."
;
81
}
catch
(
const
std::exception &e) {
82
std::cerr << e.what();
83
return
-1;
84
}
85
}
kaldi
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition:
chain.dox:20
kaldi::ParseOptions::PrintUsage
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
Definition:
parse-options.cc:393
kaldi::SequentialTableReader::Key
std::string Key()
Definition:
kaldi-table-inl.h:918
kaldi::TableWriter
A templated class for writing objects to an archive or script file; see The Table concept...
Definition:
kaldi-table.h:368
kaldi::int32
kaldi::int32 int32
Definition:
online-tcp-source.cc:27
common-utils.h
posterior.h
kaldi::TableWriter::Write
void Write(const std::string &key, const T &value) const
Definition:
kaldi-table-inl.h:1511
kaldi::ParseOptions::Register
void Register(const std::string &name, bool *ptr, const std::string &doc)
Definition:
parse-options.cc:56
kaldi::Posterior
std::vector< std::vector< std::pair< int32, BaseFloat > > > Posterior
Posterior is a typedef for storing acoustic-state (actually, transition-id) posteriors over an uttera...
Definition:
posterior.h:42
kaldi::ParseOptions
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition:
parse-options.h:36
main
int main(int argc, char *argv[])
Definition:
post-to-smat.cc:25
kaldi::SequentialTableReader
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition:
kaldi-table.h:287
kaldi::ParseOptions::Read
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
Definition:
parse-options.cc:311
kaldi::SequentialTableReader::Done
bool Done()
Definition:
kaldi-table-inl.h:948
KALDI_ERR
#define KALDI_ERR
Definition:
kaldi-error.h:147
kaldi::ParseOptions::GetArg
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
Definition:
parse-options.cc:202
kaldi::SequentialTableReader::Next
void Next()
Definition:
kaldi-table-inl.h:942
kaldi::SparseMatrix
Definition:
matrix-common.h:65
kaldi::ParseOptions::NumArgs
int NumArgs() const
Number of positional parameters (c.f. argc-1).
Definition:
parse-options.cc:198
kaldi::SequentialTableReader::Value
T & Value()
Definition:
kaldi-table-inl.h:934
KALDI_LOG
#define KALDI_LOG
Definition:
kaldi-error.h:153
kaldi-common.h
bin
post-to-smat.cc
Generated by
1.8.13