Пример #1
0
def load_h5(file_name="pyfeat_aus_to_landmarks.h5"):
    """Load the h5 PLS model for plotting.

    Args:
        file_name (str, optional): Specify model to load.. Defaults to 'blue.h5'.

    Returns:
        model: PLS model
    """
    try:
        hf = h5py.File(os.path.join(get_resource_path(), file_name), "r")
        d1 = hf.get("coef")
        d2 = hf.get("x_mean")
        d3 = hf.get("y_mean")
        d4 = hf.get("x_std")
        model = PLSRegression(len(d1))
        model.coef_ = np.array(d1)
        if int(__version__.split(".")[1]) < 24:
            model.x_mean_ = np.array(d2)
            model.y_mean_ = np.array(d3)
            model.x_std_ = np.array(d4)
        else:
            model._x_mean = np.array(d2)
            model._y_mean = np.array(d3)
            model._x_std = np.array(d4)
        hf.close()
    except Exception as e:
        print("Unable to load data ", file_name, ":", e)
    return model
Пример #2
0
 def _load_model(cls, fh):
     params = _parse_literal(fh)
     coef_shape = _parse_literal(fh)
     pls = PLSRegression().set_params(**params)
     pls.x_mean_ = np.fromstring(fh.read(coef_shape[0] * 8))
     pls.y_mean_ = np.fromstring(fh.read(coef_shape[1] * 8))
     pls.x_std_ = np.ones(coef_shape[0])
     pls.y_std_ = np.ones(coef_shape[1])
     n = coef_shape[0] * coef_shape[1] * 8
     pls.coef_ = np.fromstring(fh.read(n)).reshape(coef_shape)
     return pls
Пример #3
0
def load_h5(file_name='blue.h5'):
    """Load the h5 PLS model for plotting.

    Args:
        file_name (str, optional): Specify model to load.. Defaults to 'blue.h5'.

    Returns:
        model: PLS model
    """
    try:
        hf = h5py.File(os.path.join(get_resource_path(), file_name), 'r')
        d1 = hf.get('coef')
        d2 = hf.get('x_mean')
        d3 = hf.get('y_mean')
        d4 = hf.get('x_std')
        model = PLSRegression(len(d1))
        model.coef_ = np.array(d1)
        model.x_mean_ = np.array(d2)
        model.y_mean_ = np.array(d3)
        model.x_std_ = np.array(d4)
        hf.close()
    except Exception as e:
        print('Unable to load data ', file_name, ':', e)
    return model