nnet-nnet-test.cc
Go to the documentation of this file.
1 // nnet2/nnet-nnet-test.cc
2 
3 // Copyright 2014 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 "nnet2/nnet-nnet.h"
21 
22 namespace kaldi {
23 namespace nnet2 {
24 
25 
26 void UnitTestNnet() {
27  int32 input_dim = 40, output_dim = 500;
28  Nnet *nnet = GenRandomNnet(input_dim, output_dim);
29 
30  bool binary = (rand() % 2 == 0);
31  std::ostringstream os;
32  nnet->Write(os, binary);
33  Nnet nnet2;
34  std::istringstream is(os.str());
35  nnet2.Read(is, binary);
36 
37  std::ostringstream os2;
38  nnet2.Write(os2, binary);
39 
40  KALDI_ASSERT(os2.str() == os.str());
41  delete nnet;
42 }
43 
44 } // namespace nnet2
45 } // namespace kaldi
46 
48 
49 
50 int main() {
51  using namespace kaldi;
52  using namespace kaldi::nnet2;
53 
54  UnitTestNnet();
55  return 0;
56 }
57 
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void Read(std::istream &is, bool binary)
Definition: nnet-nnet.cc:175
Nnet * GenRandomNnet(int32 input_dim, int32 output_dim)
This function generates a random neural net, for testing purposes.
Definition: nnet-nnet.cc:772
kaldi::int32 int32
void Write(std::ostream &os, bool binary) const
Definition: nnet-nnet.cc:160
void UnitTestNnet()
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
int main()