@@ -523,16 +523,6 @@ std::string NnetInfo(const Nnet &nnet) {
523523 return ostr.str ();
524524}
525525
526- void SetDropoutProportion (BaseFloat dropout_proportion,
527- Nnet *nnet) {
528- for (int32 c = 0 ; c < nnet->NumComponents (); c++) {
529- Component *comp = nnet->GetComponent (c);
530- DropoutComponent *dc = dynamic_cast <DropoutComponent*>(comp);
531- if (dc != NULL )
532- dc->SetDropoutProportion (dropout_proportion);
533- }
534- }
535-
536526void FindOrphanComponents (const Nnet &nnet, std::vector<int32> *components) {
537527 int32 num_components = nnet.NumComponents (), num_nodes = nnet.NumNodes ();
538528 std::vector<bool > is_used (num_components, false );
@@ -688,6 +678,29 @@ void ReadEditConfig(std::istream &edit_config_is, Nnet *nnet) {
688678 if (outputs_remaining == 0 )
689679 KALDI_ERR << " All outputs were removed." ;
690680 nnet->RemoveSomeNodes (nodes_to_remove);
681+ } else if (directive == " set-dropout-proportion" ) {
682+ std::string name_pattern = " *" ;
683+ // name_pattern defaults to '*' if none is given. This pattern
684+ // matches names of components, not nodes.
685+ config_line.GetValue (" name" , &name_pattern);
686+ BaseFloat proportion = -1 ;
687+ if (!config_line.GetValue (" proportion" , &proportion)) {
688+ KALDI_ERR << " In edits-config, expected proportion to be set in line: "
689+ << config_line.WholeLine ();
690+ }
691+ DropoutComponent *component = NULL ;
692+ int32 num_dropout_proportions_set = 0 ;
693+ for (int32 c = 0 ; c < nnet->NumComponents (); c++) {
694+ if (NameMatchesPattern (nnet->GetComponentName (c).c_str (),
695+ name_pattern.c_str ()) &&
696+ (component =
697+ dynamic_cast <DropoutComponent*>(nnet->GetComponent (c)))) {
698+ component->SetDropoutProportion (proportion);
699+ num_dropout_proportions_set++;
700+ }
701+ }
702+ KALDI_LOG << " Set dropout proportions for "
703+ << num_dropout_proportions_set << " nodes." ;
691704 } else {
692705 KALDI_ERR << " Directive '" << directive << " ' is not currently "
693706 " supported (reading edit-config)." ;
0 commit comments