39 num_cols = ivector_mat.
NumCols();
46 sum.
Scale(1.0 / num_rows);
47 sumsq.
Scale(1.0 / num_rows);
55 if (num_rows > num_cols)
60 KALDI_WARN <<
"Unable to compute conversation dependent PCA for" 61 <<
" recording " << reco <<
".";
75 while (energy / total_energy <= target_energy) {
95 &transformed_ivector);
96 ivectors_out->
Row(
i).CopyFromVec(transformed_ivector);
104 transform_rows = pca_mat.
NumRows(),
105 feat_dim = ivectors_in.
NumCols();
114 int main(
int argc,
char *argv[]) {
115 using namespace kaldi;
119 "Perform PLDA scoring for speaker diarization. The input reco2utt\n" 120 "should be of the form <recording-id> <seg1> <seg2> ... <segN> and\n" 121 "there should be one iVector for each segment. PLDA scoring is\n" 122 "performed between all pairs of iVectors in a recording and outputs\n" 123 "an archive of score matrices, one for each recording-id. The rows\n" 124 "and columns of the the matrix correspond the sorted order of the\n" 126 "Usage: ivector-plda-scoring-dense [options] <plda> <reco2utt>" 127 " <ivectors-rspecifier> <scores-wspecifier>\n" 129 " ivector-plda-scoring-dense plda reco2utt scp:ivectors.scp" 130 " ark:scores.ark ark,t:ivectors.1.ark\n";
137 po.
Register(
"target-energy", &target_energy,
138 "Reduce dimensionality of i-vectors using a recording-dependent" 139 " PCA such that this fraction of the total energy remains.");
149 std::string plda_rxfilename = po.
GetArg(1),
150 reco2utt_rspecifier = po.
GetArg(2),
151 ivector_rspecifier = po.
GetArg(3),
152 scores_wspecifier = po.
GetArg(4);
160 int32 num_reco_err = 0,
162 for (; !reco2utt_reader.
Done(); reco2utt_reader.
Next()) {
163 Plda this_plda(plda);
164 std::string reco = reco2utt_reader.
Key();
166 std::vector<std::string> uttlist = reco2utt_reader.
Value();
167 std::vector<Vector<BaseFloat> > ivectors;
169 for (
size_t i = 0;
i < uttlist.size();
i++) {
170 std::string utt = uttlist[
i];
172 if (!ivector_reader.
HasKey(utt)) {
173 KALDI_ERR <<
"No iVector present in input for utterance " << utt;
177 ivectors.push_back(ivector);
179 if (ivectors.size() == 0) {
180 KALDI_WARN <<
"Not producing output for recording " << reco
181 <<
" since no segments had iVectors";
188 scores(ivectors.size(), ivectors.size());
190 for (
size_t i = 0;
i < ivectors.size();
i++) {
191 ivector_mat.
Row(
i).CopyFromVec(ivectors[
i]);
193 if (
EstPca(ivector_mat, target_energy, reco, &pca_transform)) {
195 ApplyPca(ivector_mat, pca_transform, &ivector_mat_pca);
208 for (int32
i = 0;
i < ivector_mat_plda.NumRows();
i++) {
209 for (int32
j = 0;
j < ivector_mat_plda.NumRows();
j++) {
211 ivector_mat_plda.Row(
i)), 1.0,
215 scores_writer.
Write(reco, scores);
219 KALDI_LOG <<
"Processed " << num_reco_done <<
" recordings, " 220 << num_reco_err <<
" had errors.";
221 return (num_reco_done != 0 ? 0 : 1 );
222 }
catch(
const std::exception &e) {
223 std::cerr << e.what();
void AddMat2(const Real alpha, const MatrixBase< Real > &M, MatrixTransposeType transM, const Real beta)
rank-N update: if (transM == kNoTrans) (*this) = beta*(*this) + alpha * M * M^T, or (if transM == kTr...
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Packed symetric matrix class.
void AddRowSumMat(Real alpha, const MatrixBase< Real > &M, Real beta=1.0)
Does *this = alpha * (sum of rows of M) + beta * *this.
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
double TransformIvector(const PldaConfig &config, const VectorBase< double > &ivector, int32 num_enroll_examples, VectorBase< double > *transformed_ivector) const
Transforms an iVector into a space where the within-class variance is unit and between-class variance...
A templated class for writing objects to an archive or script file; see The Table concept...
void Eig(VectorBase< Real > *s, MatrixBase< Real > *P=NULL) const
Solves the symmetric eigenvalue problem: at end we should have (*this) = P * diag(s) * P^T...
void Resize(MatrixIndexT length, MatrixResizeType resize_type=kSetZero)
Set vector to a specified size (can be zero).
void CopyFromMat(const MatrixBase< OtherReal > &M, MatrixTransposeType trans=kNoTrans)
Copy given matrix. (no resize is done).
void Write(const std::string &key, const T &value) const
void Register(const std::string &name, bool *ptr, const std::string &doc)
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
Allows random access to a collection of objects in an archive or script file; see The Table concept...
void AddVec2(const Real alpha, const VectorBase< OtherReal > &v)
rank-one update, this <– this + alpha v v'
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
int main(int argc, char *argv[])
const T & Value(const std::string &key)
bool EstPca(const Matrix< BaseFloat > &ivector_mat, BaseFloat target_energy, const std::string &reco, Matrix< BaseFloat > *mat)
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
void AddMatMat(const Real alpha, const MatrixBase< Real > &A, MatrixTransposeType transA, const MatrixBase< Real > &B, MatrixTransposeType transB, const Real beta)
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
double LogLikelihoodRatio(const VectorBase< double > &transformed_enroll_ivector, int32 num_enroll_utts, const VectorBase< double > &transformed_test_ivector) const
Returns the log-likelihood ratio log (p(test_ivector | same) / p(test_ivector | different)).
MatrixIndexT Dim() const
Returns the dimension of the vector.
void Scale(Real alpha)
Multiplies all elements by this constant.
void Register(OptionsItf *opts)
bool HasKey(const std::string &key)
Real Sum() const
Returns sum of the elements.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
void TransformIvectors(const Matrix< BaseFloat > &ivectors_in, const PldaConfig &plda_config, const Plda &plda, Matrix< BaseFloat > *ivectors_out)
A class representing a vector.
void ApplyTransform(const Matrix< double > &in_transform)
Apply a transform to the PLDA model.
#define KALDI_ASSERT(cond)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).
void ApplyPca(const Matrix< BaseFloat > &ivectors_in, const Matrix< BaseFloat > &pca_mat, Matrix< BaseFloat > *ivectors_out)
void Resize(MatrixIndexT nRows, MatrixResizeType resize_type=kSetZero)
static bool ApproxEqual(float a, float b, float relative_tolerance=0.001)
return abs(a - b) <= relative_tolerance * (abs(a)+abs(b)).
void SortSvd(VectorBase< Real > *s, MatrixBase< Real > *U, MatrixBase< Real > *Vt, bool sort_on_absolute_value)
Function to ensure that SVD is sorted.