当前位置: 首页>>代码示例>>Python>>正文


Python mlflow.log_param方法代码示例

本文整理汇总了Python中mlflow.log_param方法的典型用法代码示例。如果您正苦于以下问题:Python mlflow.log_param方法的具体用法?Python mlflow.log_param怎么用?Python mlflow.log_param使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mlflow的用法示例。


在下文中一共展示了mlflow.log_param方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: log_param

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_param [as 别名]
def log_param(self, key, value):
        """
        Logs a key-value pair for the experiment.

        Args:
            key: parameter name
            value: parameter value
        """
        key = _sanitize(key)
        value = _sanitize(value)
        self.params[key] = value

        if self.with_mlflow:
            import mlflow
            from mlflow.exceptions import MlflowException

            key_mlflow = _sanitize_mlflow_param(key, MLFLOW_KEY_LENGTH_LIMIT)
            value_mlflow = _sanitize_mlflow_param(value, MLFLOW_VALUE_LENGTH_LIMIT)

            try:
                mlflow.log_param(key_mlflow, value_mlflow)
            except MlflowException as e:
                warnings.warn('Error in logging parameter {} to mlflow. Skipped. {}'.format(key, e)) 
开发者ID:nyanp,项目名称:nyaggle,代码行数:25,代码来源:experiment.py

示例2: test_inherit_outer_scope_run

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_param [as 别名]
def test_inherit_outer_scope_run(tmpdir_name):
    mlflow.start_run()
    mlflow.log_param('foo', 1)

    params = {
        'objective': 'binary',
        'max_depth': 8
    }
    X, y = make_classification_df()

    run_experiment(params, X, y, with_mlflow=True, logging_directory=tmpdir_name)

    assert mlflow.active_run() is not None  # still valid

    client = mlflow.tracking.MlflowClient()
    data = client.get_run(mlflow.active_run().info.run_id).data

    assert data.metrics['Overall'] > 0  # recorded

    mlflow.end_run() 
开发者ID:nyanp,项目名称:nyaggle,代码行数:22,代码来源:test_run.py

示例3: test_ignore_errors_in_mlflow_params

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_param [as 别名]
def test_ignore_errors_in_mlflow_params(tmpdir_name):
    mlflow.start_run()
    mlflow.log_param('features', 'ABC')
    mlflow.log_metric('Overall', -99)

    params = {
        'objective': 'binary',
        'max_depth': 8
    }
    X, y = make_classification_df()

    result = run_experiment(params, X, y, with_mlflow=True, logging_directory=tmpdir_name, feature_list=[])

    client = mlflow.tracking.MlflowClient()
    data = client.get_run(mlflow.active_run().info.run_id).data

    assert data.metrics['Overall'] == result.metrics[-1]
    assert data.params['features'] == 'ABC'  # params cannot be overwritten

    mlflow.end_run() 
开发者ID:nyanp,项目名称:nyaggle,代码行数:22,代码来源:test_run.py

示例4: on_train_begin

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_param [as 别名]
def on_train_begin(self, logs=None):  # pylint: disable=unused-argument
        config = self.model.optimizer.get_config()
        for attribute in config:
            try_mlflow_log(mlflow.log_param, "opt_" + attribute, config[attribute])

        sum_list = []
        self.model.summary(print_fn=sum_list.append)
        summary = '\n'.join(sum_list)
        tempdir = tempfile.mkdtemp()
        try:
            summary_file = os.path.join(tempdir, "model_summary.txt")
            with open(summary_file, 'w') as f:
                f.write(summary)
            try_mlflow_log(mlflow.log_artifact, local_path=summary_file)
        finally:
            shutil.rmtree(tempdir) 
开发者ID:mlflow,项目名称:mlflow,代码行数:18,代码来源:tensorflow.py

示例5: log_param

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_param [as 别名]
def log_param(key: str, value: Any):
    mlflow.log_param(key, value) 
开发者ID:criteo,项目名称:tf-yarn,代码行数:4,代码来源:mlflow.py

示例6: log_config_parameter_to_mlflow

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_param [as 别名]
def log_config_parameter_to_mlflow(param_name: str, param_value: Any):
    """
    Log the parameter with its value to mlflow.

    If value is malformed, it will be ignored and logging notification will
    be added

    Parameters
    ----------
    param_name
        parameter name to log
    param_value
        value to log
    """
    logger = logging.getLogger(__name__)
    param_name = _replace_not_allowed_symbols(param_name)
    if isinstance(param_value, str) and os.path.exists(param_value):
        param_value = os.path.realpath(param_value)
    if mlflow.active_run() is None:
        _warn_about_no_run()
        return
    try:
        mlflow.log_param(param_name, param_value)
    # pylint: disable=invalid-name
    # is common practice to call exceptions as e
    # pylint: disable=broad-except
    # this is due to the mlflow itself, they raise this Exception
    except Exception as e:
        logger.warning("Parameter %s has malformed value %s and so will not "
                       "be logged to mlflow!", param_name, param_value)
        logger.warning("Original exception: %s", e) 
开发者ID:audi,项目名称:nucleus7,代码行数:33,代码来源:mlflow_utils.py

示例7: log_param

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_param [as 别名]
def log_param(key, value):
        pass 
开发者ID:Unbabel,项目名称:OpenKiwi,代码行数:4,代码来源:loggers.py

示例8: log_params

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_param [as 别名]
def log_params(self, params: Dict):
        """
        Logs a batch of params for the experiments.

        Args:
            params: dictionary of parameters
        """
        for k, v in params.items():
            self.log_param(k, v) 
开发者ID:nyanp,项目名称:nyaggle,代码行数:11,代码来源:experiment.py

示例9: log_dict

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_param [as 别名]
def log_dict(self, name: str, value: Dict, separator: str = '.'):
        """
        Logs a dictionary as parameter with flatten format.

        Args:
            name: Parameter name
            value: Parameter value
            separator: Separating character used to concatanate keys
        Examples:
            >>> with Experiment('./') as e:
            >>>     e.log_dict('a', {'b': 1, 'c': 'd'})
            >>>     print(e.params)
            { 'a.b': 1, 'a.c': 'd' }
        """

        if value is None:
            self.log_param(name, value)
            return

        def _flatten(d: Dict, prefix: str, separator: str) -> Dict:
            items = []
            for k, v in d.items():
                child_key = prefix + separator + str(k) if prefix else str(k)
                if isinstance(v, Dict) and v:
                    items.extend(_flatten(v, child_key, separator).items())
                else:
                    items.append((child_key, v))
            return dict(items)

        value = _flatten(value, name, separator)
        self.log_params(value) 
开发者ID:nyanp,项目名称:nyaggle,代码行数:33,代码来源:experiment.py

示例10: start

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_param [as 别名]
def start(self):
        """Start the whole thing"""

        self._setup_logging()

        if self.generate_config:
            self.write_config()

        #
        # Setup mlflow
        #
        import mlflow
        mlflow.set_tracking_uri(self.mlflow_server)
        experiment_id = mlflow.set_experiment(self.name)

        #
        # Run the script under mlflow
        #
        with mlflow.start_run(experiment_id=experiment_id):
            #
            # Log the run parametres to mlflow.
            #
            mlflow.log_param("results_path", self.results_path)

            cls = self.__class__
            for k, trait in sorted(cls.class_own_traits(config=True).items()):
                mlflow.log_param(trait.name, repr(trait.get(self)))

            self.run() 
开发者ID:leokarlin,项目名称:LaSO,代码行数:31,代码来源:experiment.py

示例11: log_fn_args_as_params

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_param [as 别名]
def log_fn_args_as_params(fn, args, kwargs, unlogged=[]):  # pylint: disable=W0102
    """
    Log parameters explicitly passed to a function.
    :param fn: function whose parameters are to be logged
    :param args: arguments explicitly passed into fn
    :param kwargs: kwargs explicitly passed into fn
    :param unlogged: parameters not to be logged
    :return: None
    """
    # all_default_values has length n, corresponding to values of the
    # last n elements in all_param_names
    pos_params, _, _, pos_defaults, kw_params, kw_defaults, _ = inspect.getfullargspec(fn)

    kw_params = list(kw_params) if kw_params else []
    pos_defaults = list(pos_defaults) if pos_defaults else []
    all_param_names = pos_params + kw_params
    all_default_values = pos_defaults + [kw_defaults[param] for param in kw_params]

    # Checking if default values are present for logging. Known bug that getargspec will return an
    # empty argspec for certain functions, despite the functions having an argspec.
    if all_default_values is not None and len(all_default_values) > 0:
        # Logging the default arguments not passed by the user
        defaults = get_unspecified_default_args(args, kwargs, all_param_names, all_default_values)

        for name in [name for name in defaults.keys() if name in unlogged]:
            del defaults[name]
        try_mlflow_log(mlflow.log_params, defaults)

    # Logging the arguments passed by the user
    args_dict = dict((param_name, param_val) for param_name, param_val
                     in zip(all_param_names, args)
                     if param_name not in unlogged)

    if args_dict:
        try_mlflow_log(mlflow.log_params, args_dict)

    # Logging the kwargs passed by the user
    for param_name in kwargs:
        if param_name not in unlogged:
            try_mlflow_log(mlflow.log_param, param_name, kwargs[param_name]) 
开发者ID:mlflow,项目名称:mlflow,代码行数:42,代码来源:autologging_utils.py

示例12: train_random_forest

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_param [as 别名]
def train_random_forest(ntrees):
    with mlflow.start_run():
        rf = H2ORandomForestEstimator(ntrees=ntrees)
        train_cols = [n for n in wine.col_names if n != "quality"]
        rf.train(train_cols, "quality", training_frame=train, validation_frame=test)

        mlflow.log_param("ntrees", ntrees)

        mlflow.log_metric("rmse", rf.rmse())
        mlflow.log_metric("r2", rf.r2())
        mlflow.log_metric("mae", rf.mae())

        mlflow.h2o.log_model(rf, "model") 
开发者ID:mlflow,项目名称:mlflow,代码行数:15,代码来源:random_forest.py

示例13: log_params

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_param [as 别名]
def log_params(parameters):
    for k, v in parameters.items():
        mlflow.log_param(k, v) 
开发者ID:mlflow,项目名称:mlflow,代码行数:5,代码来源:generate_ui_test_data.py

示例14: process_image

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_param [as 别名]
def process_image(keras_model_path, size,dataset = "coco", photo_name = "data/horses.jpg"):
    dataset = "data/{}.data".format(dataset)
    if not os.path.exists("outputs"): os.mkdir("outputs")
    
    warnings.filterwarnings("ignore")
    np.random.seed(40)
    model = load_model(keras_model_path)
    # define the expected input shape for the model
    input_w, input_h = size, size
    output_photo_name = 'outputs/objects_' + os.path.basename(photo_name)
    # load and prepare image
    image, image_w, image_h = load_image_pixels(photo_name, (input_w, input_h))
    # make prediction
    yhat = model.predict(image)
    # summarize the shape of the list of arrays
    print("Bounding box coordinates")
    print([a.shape for a in yhat])
    # define the anchors
    anchors = [[116,90, 156,198, 373,326], [30,61, 62,45, 59,119], [10,13, 16,30, 33,23]]
    # define the probability threshold for detected objects
    class_threshold = 0.5
    boxes = list()
    for i in range(len(yhat)):
        # decode the output of the network
        boxes += decode_netout(yhat[i][0], anchors[i], class_threshold, input_h, input_w)
    # correct the sizes of the bounding boxes for the shape of the image
    correct_yolo_boxes(boxes, image_h, image_w, input_h, input_w)
    # suppress non-maximal boxes
    do_nms(boxes, 0.4)
    # define the labels
    _,labels = dataset_process(dataset) 
    with mlflow.start_run(nested = True):
        mlflow.log_param("keras_model_path", keras_model_path)
        mlflow.log_param("photo_name", photo_name)
    
        # get the details of the detected objects
        v_boxes, v_labels, v_scores = get_boxes(boxes, labels, class_threshold)
        # summarize what we found
        for i in range(len(v_boxes)):
            print(v_labels[i], v_scores[i])
            mlflow.set_tag(str(i) + '_' + v_labels[i], v_scores[i])
        # draw what we found
        draw_boxes(photo_name, v_boxes, v_labels, v_scores, output_photo_name)
        print("Image created after object detection task and saved as:", output_photo_name)
    
        mlflow.log_artifact(output_photo_name, "output_photo_name") 
开发者ID:produvia,项目名称:ai-platform,代码行数:48,代码来源:yolo_image.py

示例15: log_experiment

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_param [as 别名]
def log_experiment(
    params={},
    metrics={},
    artifacts={},
    experiment_name="my_experiment",
    mlflow_tracking_uri="./experiments",
    mlflow_artifact_location=None,
):
    """
    Evaluate the model and log it with mlflow

    Args:
        params (dict): dictionary of parameters to log
        metrics (dict): dictionary of metrics to log
        artifacts (dict): dictionary of artifacts (path) to log
        experiment_name (str): experiment name
        mlflow_tracking_uri (str): path or sql url for mlflow logging
        mlflow_artifact_location (str): path or s3bucket url for artifact
            logging. If none, it will default to a standard.

    Returns:
        None
    """
    # Try to create an experiment if it doesn't exist
    try:
        exp_0 = mlflow.create_experiment(
            experiment_name, artifact_location=mlflow_artifact_location
        )
        # set uri
        mlflow.set_tracking_uri(mlflow_tracking_uri)
        logger.info(f"Created new experiment id: {exp_0}")
    except Exception as E:
        logger.info(f"{E}. Writing to same URI/artifact store")
    # Always set the experiment
    mlflow.set_experiment(experiment_name)
    logger.info(f"Running experiment {experiment_name}")
    with mlflow.start_run():
        # param logging
        for key, val in params.items():
            logger.info(f"Logging param {key}")
            mlflow.log_param(key, val)
        # metric logging
        for key, val in metrics.items():
            logger.info(f"Logging metric {key}")
            mlflow.log_metric(key, val)
        # artifact logging
        for key, val in artifacts.items():
            logger.info(f"Logging artifact {key}")
            mlflow.log_artifact(val) 
开发者ID:manifoldai,项目名称:orbyter-cookiecutter,代码行数:51,代码来源:{{ cookiecutter.repo_name.replace(


注:本文中的mlflow.log_param方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。