()
Parses flags and returns the appropriate MelodyRnnConfig.

  If `--config` is supplied, returns the matching default MelodyRnnConfig after
  updating the hyperparameters based on `--hparams`.

  If `--melody_encoder_decoder` is supplied, returns a new MelodyRnnConfig using
  the matching EventSequenceEncoderDecoder, generator details supplied by
  `--generator_id` and `--generator_description`, and hyperparameters based on
  `--hparams`.

  Returns:
    The appropriate MelodyRnnConfig based on the supplied flags.

  Raises:
     MelodyRnnConfigError: When not exactly one of `--config` or
         `melody_encoder_decoder` is supplied.
Parses flags and returns the appropriate MelodyRnnConfig.
Parses flags and returns the appropriate MelodyRnnConfig .
def config_from_flags():
  """Parses flags and returns the appropriate MelodyRnnConfig.

  If `--config` is supplied, returns the matching default MelodyRnnConfig after
  updating the hyperparameters based on `--hparams`.

  If `--melody_encoder_decoder` is supplied, returns a new MelodyRnnConfig using
  the matching EventSequenceEncoderDecoder, generator details supplied by
  `--generator_id` and `--generator_description`, and hyperparameters based on
  `--hparams`.

  Returns:
    The appropriate MelodyRnnConfig based on the supplied flags.

  Raises:
     MelodyRnnConfigError: When not exactly one of `--config` or
         `melody_encoder_decoder` is supplied.
  """
  if (FLAGS.melody_encoder_decoder, FLAGS.config).count(None) != 1:
    raise MelodyRnnConfigError(
        'Exactly one of `--config` or `--melody_encoder_decoder` must be '
        'supplied.')

  if FLAGS.melody_encoder_decoder is not None:
    if FLAGS.melody_encoder_decoder not in melody_encoder_decoders:
      raise MelodyRnnConfigError(
          '`--melody_encoder_decoder` must be one of %s. Got %s.' % (
              melody_encoder_decoders.keys(), FLAGS.melody_encoder_decoder))
    if FLAGS.generator_id is not None:
      generator_details = note_seq.protobuf.generator_pb2.GeneratorDetails(
          id=FLAGS.generator_id)
      if FLAGS.generator_description is not None:
        generator_details.description = FLAGS.generator_description
    else:
      generator_details = None
    encoder_decoder = melody_encoder_decoders[FLAGS.melody_encoder_decoder](
        melody_rnn_model.DEFAULT_MIN_NOTE, melody_rnn_model.DEFAULT_MAX_NOTE)
    hparams = contrib_training.HParams()
    hparams.parse(FLAGS.hparams)
    return melody_rnn_model.MelodyRnnConfig(
        generator_details, encoder_decoder, hparams)
  else:
    if FLAGS.config not in melody_rnn_model.default_configs:
      raise MelodyRnnConfigError(
          '`--config` must be one of %s. Got %s.' % (
              melody_rnn_model.default_configs.keys(), FLAGS.config))
    config = melody_rnn_model.default_configs[FLAGS.config]
    config.hparams.parse(FLAGS.hparams)
    if FLAGS.generator_id is not None:
      config.details.id = FLAGS.generator_id
    if FLAGS.generator_description is not None:
      config.details.description = FLAGS.generator_description
    return config
def config_from_flags ( ) : if ( FLAGS . melody_encoder_decoder , FLAGS . config ) . count ( None ) != 1 : raise MelodyRnnConfigError ( 'Exactly one of `--config` or `--melody_encoder_decoder` must be ' 'supplied.' ) if FLAGS . melody_encoder_decoder is not None : if FLAGS . melody_encoder_decoder not in melody_encoder_decoders : raise MelodyRnnConfigError ( '`--melody_encoder_decoder` must be one of %s. Got %s.' % ( melody_encoder_decoders . keys ( ) , FLAGS . melody_encoder_decoder ) ) if FLAGS . generator_id is not None : generator_details = note_seq . protobuf . generator_pb2 . GeneratorDetails ( id = FLAGS . generator_id ) if FLAGS . generator_description is not None : generator_details . description = FLAGS . generator_description else : generator_details = None encoder_decoder = melody_encoder_decoders [ FLAGS . melody_encoder_decoder ] ( melody_rnn_model . DEFAULT_MIN_NOTE , melody_rnn_model . DEFAULT_MAX_NOTE ) hparams = contrib_training . HParams ( ) hparams . parse ( FLAGS . hparams ) return melody_rnn_model . MelodyRnnConfig ( generator_details , encoder_decoder , hparams ) else : if FLAGS . config not in melody_rnn_model . default_configs : raise MelodyRnnConfigError ( '`--config` must be one of %s. Got %s.' % ( melody_rnn_model . default_configs . keys ( ) , FLAGS . config ) ) config = melody_rnn_model . default_configs [ FLAGS . config ] config . hparams . parse ( FLAGS . hparams ) if FLAGS . generator_id is not None : config . details . id = FLAGS . generator_id if FLAGS . generator_description is not None : config . details . description = FLAGS . generator_description return config