Пример #1
0
    def test_benchmark_setting(self):
        defaults = dict(
            hooks=["LoggingMetricHook"],
            benchmark_log_dir="/tmp/12345",
            gcp_project="project_abc",
        )

        flags_core.set_defaults(**defaults)
        flags_core.parse_flags()

        for key, value in defaults.items():
            assert flags.FLAGS.get_flag_value(name=key, default=None) == value
Пример #2
0
def define_flags():
    flags_core.define_base()
    flags_core.define_performance(num_parallel_calls=False)
    flags_core.define_model_and_data(model='Simple', dataset='CIFAR10')
    flags.adopt_module_key_flags(flags_core)
    flags_core.set_defaults(
        data_dir='data/cifar10/',
        # default checkpoints are stored with time-based directory,
        # but if you want you could change directory naming rule
        # for your convenience for tracking experiments
        model_dir='checkpoints/%s/' %
        datetime.datetime.now().strftime(_DATE_TIME_FORMAT_PATTERN),
        batch_size=16,
        train_epochs=40)
Пример #3
0
    def test_default_setting(self):
        """Test to ensure fields exist and defaults can be set.
    """

        defaults = dict(data_dir="dfgasf",
                        model_dir="dfsdkjgbs",
                        train_epochs=534,
                        epochs_between_evals=15,
                        batch_size=256,
                        hooks=["LoggingTensorHook"],
                        num_parallel_calls=18,
                        inter_op_parallelism_threads=5,
                        intra_op_parallelism_threads=10,
                        data_format="channels_first")

        flags_core.set_defaults(**defaults)
        flags_core.parse_flags()

        for key, value in defaults.items():
            assert flags.FLAGS.get_flag_value(name=key, default=None) == value
Пример #4
0
def define_imagenet_flags():
    resnet_run_loop.define_resnet_flags(
        resnet_size_choices=['18', '34', '50', '101', '152', '200'])
    flags.adopt_module_key_flags(resnet_run_loop)
    flags_core.set_defaults(train_epochs=1)
Пример #5
0
def define_ncf_flags():
    """Add flags for running ncf_main."""
    # Add common flags
    flags_core.define_base(export_dir=False)

    flags_core.define_benchmark()

    flags.adopt_module_key_flags(flags_core)

    flags_core.set_defaults(model_dir="./ncf/",
                            data_dir="./movielens-data/",
                            train_epochs=2,
                            batch_size=1000)

    # Add ncf-specific flags
    flags.DEFINE_enum(
        name="dataset",
        default="ml-20m",
        enum_values=["ml-1m", "ml-20m"],
        case_sensitive=False,
        help=flags_core.help_wrap("Dataset to be trained and evaluated."))

    flags.DEFINE_boolean(
        name="download_if_missing",
        default=True,
        help=flags_core.help_wrap(
            "Download data to data_dir if it is not already present."))

    flags.DEFINE_integer(
        name="eval_batch_size",
        default=None,
        help=flags_core.help_wrap(
            "The batch size used for evaluation. This should generally be larger"
            "than the training batch size as the lack of back propagation during"
            "evaluation can allow for larger batch sizes to fit in memory. If not"
            "specified, the training batch size (--batch_size) will be used."))

    flags.DEFINE_integer(
        name="num_factors",
        default=8,
        help=flags_core.help_wrap("The Embedding size of MF model."))

    # Set the default as a list of strings to be consistent with input arguments
    flags.DEFINE_list(
        name="layers",
        default=["64", "32", "16", "8"],
        help=flags_core.help_wrap(
            "The sizes of hidden layers for MLP. Example "
            "to specify different sizes of MLP layers: --layers=32,16,8,4"))

    flags.DEFINE_float(
        name="mf_regularization",
        default=0.,
        help=flags_core.help_wrap(
            "The regularization factor for MF embeddings. The factor is used by "
            "regularizer which allows to apply penalties on layer parameters or "
            "layer activity during optimization."))

    flags.DEFINE_list(
        name="mlp_regularization",
        default=["0.", "0.", "0.", "0."],
        help=flags_core.help_wrap(
            "The regularization factor for each MLP layer. See mf_regularization "
            "help for more info about regularization factor."))

    flags.DEFINE_integer(
        name="num_neg",
        default=4,
        help=flags_core.help_wrap(
            "The Number of negative instances to pair with a positive instance."
        ))

    flags.DEFINE_float(name="learning_rate",
                       default=0.001,
                       help=flags_core.help_wrap("The learning rate."))

    flags.DEFINE_float(name="beta1",
                       default=0.9,
                       help=flags_core.help_wrap(
                           "beta1 hyperparameter for the Adam optimizer."))

    flags.DEFINE_float(name="beta2",
                       default=0.999,
                       help=flags_core.help_wrap(
                           "beta2 hyperparameter for the Adam optimizer."))

    flags.DEFINE_float(name="epsilon",
                       default=1e-8,
                       help=flags_core.help_wrap(
                           "epsilon hyperparameter for the Adam "
                           "optimizer."))

    flags.DEFINE_float(
        name="hr_threshold",
        default=None,
        help=flags_core.help_wrap(
            "If passed, training will stop when the evaluation metric HR is "
            "greater than or equal to hr_threshold. For dataset ml-1m, the "
            "desired hr_threshold is 0.68 which is the result from the paper; "
            "For dataset ml-20m, the threshold can be set as 0.95 which is "
            "achieved by MLPerf implementation."))

    flags.DEFINE_enum(
        name="constructor_type",
        default="bisection",
        enum_values=["bisection", "materialized"],
        case_sensitive=False,
        help=flags_core.help_wrap(
            "Strategy to use for generating false negatives. materialized has a"
            "precompute that scales badly, but a faster per-epoch construction"
            "time and can be faster on very large systems."))

    flags.DEFINE_integer(
        name="seed",
        default=None,
        help=flags_core.help_wrap(
            "This value will be used to seed both NumPy and TensorFlow."))

    @flags.validator("eval_batch_size",
                     "eval_batch_size must be at least {}".format(
                         rconst.NUM_EVAL_NEGATIVES + 1))
    def eval_size_check(eval_batch_size):
        return (eval_batch_size is None
                or int(eval_batch_size) > rconst.NUM_EVAL_NEGATIVES)