Пример #1
0
 def test_parse_cli_to_dictionary_two_key_tuple(self):
     input_list = [
         "--key1", "(0,", "1)", "--key2", "[True,", "False,", "'args']"
     ]
     expected = {"key1": (0, 1), "key2": [True, False, 'args']}
     actual = parse_cli_to_dictionary(input_list)
     self.assertDictEqual(actual, expected)
Пример #2
0
def _get_estimator(args: Dict[str, Any],
                   unknown: Optional[List[str]]) -> Estimator:
    """A helper method to invoke the get_estimator method from a file using provided command line arguments as input.

    Args:
        args: A dictionary containing location of the FE file under the 'entry_point' key, as well as an optional
            'hyperparameters_json' key if the user is storing their parameters in a file.
        unknown: The remainder of the command line arguments to be passed along to the get_estimator() method.

    Returns:
        The estimator generated by a file's get_estimator() function.
    """
    entry_point = args['entry_point']
    hyperparameters = {}
    if args['hyperparameters_json']:
        hyperparameters = os.path.abspath(args['hyperparameters_json'])
        with open(hyperparameters, 'r') as f:
            hyperparameters = json.load(f)
    hyperparameters.update(parse_cli_to_dictionary(unknown))
    module_name = os.path.splitext(os.path.basename(entry_point))[0]
    dir_name = os.path.abspath(os.path.dirname(entry_point))
    sys.path.insert(0, dir_name)
    spec_module = __import__(module_name, globals(), locals(),
                             ["get_estimator"])
    return spec_module.get_estimator(**hyperparameters)
Пример #3
0
def run(args: Dict[str, Any], unknown: Optional[List[str]]) -> None:
    """Invoke the fastestimator_run function from a file.

    Args:
        args: A dictionary containing location of the FE file under the 'entry_point' key, as well as an optional
            'hyperparameters_json' key if the user is storing their parameters in a file.
        unknown: The remainder of the command line arguments to be passed along to the fastestimator_run() method.
    """
    entry_point = args['entry_point']
    hyperparameters = {}
    if args['hyperparameters_json']:
        hyperparameters = os.path.abspath(args['hyperparameters_json'])
        with open(hyperparameters, 'r') as f:
            hyperparameters = json.load(f)
    hyperparameters.update(parse_cli_to_dictionary(unknown))
    module_name = os.path.splitext(os.path.basename(entry_point))[0]
    dir_name = os.path.abspath(os.path.dirname(entry_point))
    sys.path.insert(0, dir_name)
    spec_module = __import__(module_name, globals(), locals())
    if hasattr(spec_module, "fastestimator_run"):
        spec_module.fastestimator_run(**hyperparameters)
    elif hasattr(spec_module, "get_estimator"):
        est = spec_module.get_estimator(**hyperparameters)
        if "train" in est.pipeline.data:
            est.fit()
        if "test" in est.pipeline.data:
            est.test()
    else:
        raise ValueError(
            "The file {} does not contain 'fastestimator_run' or 'get_estimator'"
            .format(module_name))
Пример #4
0
def train(args, unknown):
    entry_point = args['entry_point']
    hyperparameters = {}
    if args['hyperparameters_json']:
        hyperparameters = os.path.abspath(args['hyperparameters_json'])
        hyperparameters = json.load(open(hyperparameters, 'r'))
    hyperparameters.update(parse_cli_to_dictionary(unknown))
    module_name = os.path.splitext(os.path.basename(entry_point))[0]
    dir_name = os.path.abspath(os.path.dirname(entry_point))
    sys.path.insert(0, dir_name)
    spec_module = __import__(module_name, globals(), locals(),
                             ["get_estimator"])
    estimator = spec_module.get_estimator(**hyperparameters)
    estimator.fit()
Пример #5
0
def umap(args, unknown):
    hyperparameters = parse_cli_to_dictionary(unknown)
    load_and_umap(args['model'],
                  args['input_dir'],
                  print_layers=args['print_layers'],
                  strip_alpha=args['strip_alpha'],
                  layers=args['layers'],
                  batch=args['batch'],
                  use_cache=args['cache'],
                  cache_dir=args['cache_dir'],
                  dictionary_path=args['dictionary'],
                  legend_mode=args['legend'],
                  save=args['save'],
                  save_dir=args['save_dir'],
                  umap_parameters=hyperparameters,
                  input_extension=args['extension'])
Пример #6
0
 def test_parse_cli_to_dictionary(self):
     a = parse_cli_to_dictionary(
         ["--epochs", "5", "--test", "this", "--lr", "0.74"])
     self.assertEqual(a, {'epochs': 5, 'test': 'this', 'lr': 0.74})
Пример #7
0
 def test_parse_cli_to_dictionary_consecutive_value(self):
     a = parse_cli_to_dictionary(["--abc", "hello", "world"])
     self.assertEqual(a, {"abc": "helloworld"})
Пример #8
0
 def test_parse_cli_to_dictionary_no_value(self):
     a = parse_cli_to_dictionary(["--abc", "--def"])
     self.assertEqual(a, {"abc": "", "def": ""})
Пример #9
0
 def test_parse_cli_to_dictionary_no_key(self):
     a = parse_cli_to_dictionary(["abc", "def"])
     self.assertEqual(a, {})
Пример #10
0
 def test_parse_cli_to_dictionary_one_key_tuple(self):
     input_list = ["thing1", "--key1", "(0,", "1)"]
     expected = {"key1": (0, 1)}
     actual = parse_cli_to_dictionary(input_list)
     self.assertDictEqual(actual, expected)
Пример #11
0
 def test_parse_cli_to_dictionary_one_key_string2(self):
     input_list = ["--key1", "True"]
     expected = {"key1": True}
     actual = parse_cli_to_dictionary(input_list)
     self.assertDictEqual(actual, expected)
Пример #12
0
 def test_parse_cli_to_dictionary_no_key(self):
     input_list = ["thing1", "thing2", "True", "(0,", "1)"]
     expected = {}
     actual = parse_cli_to_dictionary(input_list)
     self.assertDictEqual(actual, expected)
Пример #13
0
 def test_parse_cli_to_dictionary(self):
     input_list = []
     expected = {}
     actual = parse_cli_to_dictionary(input_list)
     self.assertDictEqual(actual, expected)