nnet-nnet-test.cc
Go to the documentation of this file.
1 // nnet3/nnet-nnet-test.cc
2 
3 // Copyright 2015 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 #include "nnet3/nnet-nnet.h"
21 #include "nnet3/nnet-test-utils.h"
22 
23 namespace kaldi {
24 namespace nnet3 {
25 
26 
28  for (int32 n = 0; n < 100; n++) {
29  struct NnetGenerationOptions gen_config;
30 
31  bool binary = (Rand() % 2 == 0);
32  std::vector<std::string> configs;
33  GenerateConfigSequence(gen_config, &configs);
34  Nnet nnet;
35  std::istringstream is(configs[0]);
36  nnet.ReadConfig(is);
37 
38  std::ostringstream os;
39  nnet.Write(os, binary);
40  const std::string &original_output = os.str();
41  std::istringstream nnet_is(original_output);
42  nnet.Read(nnet_is, binary);
43  std::istringstream nnet_is2(original_output);
44  Nnet nnet2;
45  nnet2.Read(nnet_is2, binary);
46 
47  std::ostringstream os2, os3;
48  nnet.Write(os2, binary);
49 
50  nnet2.Write(os3, binary);
51  if (binary) {
52  KALDI_ASSERT(os2.str() == original_output);
53  KALDI_ASSERT(os3.str() == original_output);
54  }
55  }
56 }
57 
58 } // namespace nnet3
59 } // namespace kaldi
60 
61 int main() {
62  using namespace kaldi;
63  using namespace kaldi::nnet3;
64 
66 
67  KALDI_LOG << "Nnet tests succeeded.";
68 
69  return 0;
70 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void Write(std::ostream &ostream, bool binary) const
Definition: nnet-nnet.cc:630
void ReadConfig(std::istream &config_file)
Definition: nnet-nnet.cc:189
This file contains various routines that are useful in test code.
kaldi::int32 int32
void Read(std::istream &istream, bool binary)
Definition: nnet-nnet.cc:586
struct rnnlm::@11::@12 n
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
void GenerateConfigSequence(const NnetGenerationOptions &opts, std::vector< std::string > *configs)
Generates a sequence of at least one config files, output as strings, where the first in the sequence...
#define KALDI_LOG
Definition: kaldi-error.h:153
int main()
void UnitTestNnetIo()