當前位置: 首頁>>代碼示例>>Python>>正文


Python cloudpickle.dump方法代碼示例

本文整理匯總了Python中cloudpickle.dump方法的典型用法代碼示例。如果您正苦於以下問題:Python cloudpickle.dump方法的具體用法?Python cloudpickle.dump怎麽用?Python cloudpickle.dump使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cloudpickle的用法示例。


在下文中一共展示了cloudpickle.dump方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: save

# 需要導入模塊: import cloudpickle [as 別名]
# 或者: from cloudpickle import dump [as 別名]
def save(self, path=None):
        """Save model to a pickle located at `path`"""
        if path is None:
            path = os.path.join(logger.get_dir(), "model.pkl")

        with tempfile.TemporaryDirectory() as td:
            save_state(os.path.join(td, "model"))
            arc_name = os.path.join(td, "packed.zip")
            with zipfile.ZipFile(arc_name, 'w') as zipf:
                for root, dirs, files in os.walk(td):
                    for fname in files:
                        file_path = os.path.join(root, fname)
                        if file_path != arc_name:
                            zipf.write(file_path, os.path.relpath(file_path, td))
            with open(arc_name, "rb") as f:
                model_data = f.read()
        with open(path, "wb") as f:
            cloudpickle.dump((model_data, self._act_params), f) 
開發者ID:Hwhitetooth,項目名稱:lirpg,代碼行數:20,代碼來源:simple.py

示例2: save_act

# 需要導入模塊: import cloudpickle [as 別名]
# 或者: from cloudpickle import dump [as 別名]
def save_act(self, path=None):
        """Save model to a pickle located at `path`"""
        if path is None:
            path = os.path.join(logger.get_dir(), "model.pkl")

        with tempfile.TemporaryDirectory() as td:
            save_state(os.path.join(td, "model"))
            arc_name = os.path.join(td, "packed.zip")
            with zipfile.ZipFile(arc_name, 'w') as zipf:
                for root, dirs, files in os.walk(td):
                    for fname in files:
                        file_path = os.path.join(root, fname)
                        if file_path != arc_name:
                            zipf.write(file_path, os.path.relpath(file_path, td))
            with open(arc_name, "rb") as f:
                model_data = f.read()
        with open(path, "wb") as f:
            cloudpickle.dump((model_data, self._act_params), f) 
開發者ID:MaxSobolMark,項目名稱:HardRLWithYoutube,代碼行數:20,代碼來源:deepq.py

示例3: dumps

# 需要導入模塊: import cloudpickle [as 別名]
# 或者: from cloudpickle import dump [as 別名]
def dumps(obj, protocol=None):
    """Serialize obj as a string of bytes allocated in memory

    protocol defaults to cloudpickle.DEFAULT_PROTOCOL which is an alias to
    pickle.HIGHEST_PROTOCOL. This setting favors maximum communication speed
    between processes running the same Python version.

    Set protocol=pickle.DEFAULT_PROTOCOL instead if you need to ensure
    compatibility with older versions of Python.
    """
    file = StringIO()
    try:
        cp = CloudPickler(file, protocol=protocol)
        cp.dump(obj)
        return file.getvalue()
    finally:
        file.close()


# including pickles unloading functions in this namespace 
開發者ID:pywren,項目名稱:pywren-ibm-cloud,代碼行數:22,代碼來源:cloudpickle.py

示例4: save

# 需要導入模塊: import cloudpickle [as 別名]
# 或者: from cloudpickle import dump [as 別名]
def save(self, directory: str):
        shutil.copyfile(self.model_file, os.path.join(directory, 'rnn.pt'))
        shell(f'rm -f {self.model_file}')
        with open(os.path.join(directory, 'rnn.pkl'), 'wb') as f:
            cloudpickle.dump({
                'page_field': self.page_field,
                'text_field': self.text_field,
                'qanta_id_field': self.qanta_id_field,
                'n_classes': self.n_classes,
                'gradient_clip': self.gradient_clip,
                'n_hidden_units': self.n_hidden_units,
                'n_hidden_layers': self.n_hidden_layers,
                'nn_dropout': self.nn_dropout,
                'batch_size': self.batch_size,
                'use_wiki': self.use_wiki,
                'n_wiki_sentences': self.n_wiki_sentences,
                'wiki_title_replace_token': self.wiki_title_replace_token,
                'lowercase': self.lowercase,
                'random_seed': self.random_seed,
                'config_num': self.config_num
            }, f) 
開發者ID:Pinafore,項目名稱:qb,代碼行數:23,代碼來源:rnn.py

示例5: save_policy

# 需要導入模塊: import cloudpickle [as 別名]
# 或者: from cloudpickle import dump [as 別名]
def save_policy(self, policy_path: str):
        """Save a policy to a pickle. Can be reloaded by `.reconstruct_policy()`.

        Args:
            policy_path: path to save policy to.
        """
        policy_params = self.sess.run(self.policy_variables)
        data = {
            "class": self.policy_class,
            "kwargs": self.policy_kwargs,
            "params": policy_params,
        }
        dirname = os.path.dirname(policy_path)
        if dirname:
            os.makedirs(dirname, exist_ok=True)
        with open(policy_path, "wb") as fp:
            cloudpickle.dump(data, fp) 
開發者ID:HumanCompatibleAI,項目名稱:imitation,代碼行數:19,代碼來源:bc.py

示例6: _save_to_file_cloudpickle

# 需要導入模塊: import cloudpickle [as 別名]
# 或者: from cloudpickle import dump [as 別名]
def _save_to_file_cloudpickle(save_path, data=None, params=None):
        """Legacy code for saving models with cloudpickle

        :param save_path: (str or file-like) Where to store the model
        :param data: (OrderedDict) Class parameters being stored
        :param params: (OrderedDict) Model parameters being stored
        """
        if isinstance(save_path, str):
            _, ext = os.path.splitext(save_path)
            if ext == "":
                save_path += ".pkl"

            with open(save_path, "wb") as file_:
                cloudpickle.dump((data, params), file_)
        else:
            # Here save_path is a file-like object, not a path
            cloudpickle.dump((data, params), save_path) 
開發者ID:Stable-Baselines-Team,項目名稱:stable-baselines,代碼行數:19,代碼來源:base_class.py

示例7: save_act

# 需要導入模塊: import cloudpickle [as 別名]
# 或者: from cloudpickle import dump [as 別名]
def save_act(self, path=None):
        """Save model to a pickle located at `path`"""
        if path is None:
            path = os.path.join(logger.get_dir(), "model.pkl")

        with tempfile.TemporaryDirectory() as td:
            save_variables(os.path.join(td, "model"))
            arc_name = os.path.join(td, "packed.zip")
            with zipfile.ZipFile(arc_name, 'w') as zipf:
                for root, dirs, files in os.walk(td):
                    for fname in files:
                        file_path = os.path.join(root, fname)
                        if file_path != arc_name:
                            zipf.write(file_path, os.path.relpath(file_path, td))
            with open(arc_name, "rb") as f:
                model_data = f.read()
        with open(path, "wb") as f:
            cloudpickle.dump((model_data, self._act_params), f) 
開發者ID:hiwonjoon,項目名稱:ICML2019-TREX,代碼行數:20,代碼來源:deepq.py

示例8: _save_candidate_classes

# 需要導入模塊: import cloudpickle [as 別名]
# 或者: from cloudpickle import dump [as 別名]
def _save_candidate_classes(candidate_classes: List[Candidate], path: str) -> None:
    pickle.dump(
        [
            {
                "class_name": candidate_class.__name__,
                "mention_class_names": [
                    candidate_class.__name__
                    for candidate_class in candidate_class.mentions
                ],
                "table_name": candidate_class.__tablename__,
                "cardinality": candidate_class.cardinality,
                "values": candidate_class.values,
            }
            for candidate_class in candidate_classes
        ],
        open(os.path.join(path, "candidate_classes.pkl"), "wb"),
    ) 
開發者ID:HazyResearch,項目名稱:fonduer,代碼行數:19,代碼來源:fonduer_model.py

示例9: dumps

# 需要導入模塊: import cloudpickle [as 別名]
# 或者: from cloudpickle import dump [as 別名]
def dumps(obj, protocol=None):
    """Serialize obj as a string of bytes allocated in memory

    protocol defaults to cloudpickle.DEFAULT_PROTOCOL which is an alias to
    pickle.HIGHEST_PROTOCOL. This setting favors maximum communication speed
    between processes running the same Python version.

    Set protocol=pickle.DEFAULT_PROTOCOL instead if you need to ensure
    compatibility with older versions of Python.
    """
    file = BytesIO()
    try:
        cp = CloudPickler(file, protocol=protocol)
        cp.dump(obj)
        return file.getvalue()
    finally:
        file.close()


# including pickles unloading functions in this namespace 
開發者ID:ray-project,項目名稱:ray,代碼行數:22,代碼來源:cloudpickle.py

示例10: save

# 需要導入模塊: import cloudpickle [as 別名]
# 或者: from cloudpickle import dump [as 別名]
def save(self, path=None):
    """Save model to a pickle located at `path`"""
    if path is None:
        path = os.path.join(logger.get_dir(), "model.pkl")

    with tempfile.TemporaryDirectory() as td:
        U.save_state(os.path.join(td, "model"))
        arc_name = os.path.join(td, "packed.zip")
        with zipfile.ZipFile(arc_name, 'w') as zipf:
            for root, dirs, files in os.walk(td):
                for fname in files:
                    file_path = os.path.join(root, fname)
                    if file_path != arc_name:
                        zipf.write(file_path, os.path.relpath(file_path, td))
        with open(arc_name, "rb") as f:
            model_data = f.read()
    with open(path, "wb") as f:
        cloudpickle.dump((model_data), f) 
開發者ID:alexsax,項目名稱:midlevel-reps,代碼行數:20,代碼來源:pposgd_simple.py

示例11: _save_custom_objects

# 需要導入模塊: import cloudpickle [as 別名]
# 或者: from cloudpickle import dump [as 別名]
def _save_custom_objects(path, custom_objects):
    """
    Save custom objects dictionary to a cloudpickle file so a model can be easily loaded later.

    :param path: An absolute path that points to the data directory within /path/to/model.
    :param custom_objects: Keras ``custom_objects`` is a dictionary mapping
                           names (strings) to custom classes or functions to be considered
                           during deserialization. MLflow saves these custom layers using
                           CloudPickle and restores them automatically when the model is
                           loaded with :py:func:`mlflow.keras.load_model` and
                           :py:func:`mlflow.pyfunc.load_model`.
    """
    import cloudpickle
    custom_objects_path = os.path.join(path, _CUSTOM_OBJECTS_SAVE_PATH)
    with open(custom_objects_path, "wb") as out_f:
        cloudpickle.dump(custom_objects, out_f) 
開發者ID:mlflow,項目名稱:mlflow,代碼行數:18,代碼來源:keras.py

示例12: _save_model

# 需要導入模塊: import cloudpickle [as 別名]
# 或者: from cloudpickle import dump [as 別名]
def _save_model(sk_model, output_path, serialization_format):
    """
    :param sk_model: The scikit-learn model to serialize.
    :param output_path: The file path to which to write the serialized model.
    :param serialization_format: The format in which to serialize the model. This should be one of
                                 the following: ``mlflow.sklearn.SERIALIZATION_FORMAT_PICKLE`` or
                                 ``mlflow.sklearn.SERIALIZATION_FORMAT_CLOUDPICKLE``.
    """
    with open(output_path, "wb") as out:
        if serialization_format == SERIALIZATION_FORMAT_PICKLE:
            pickle.dump(sk_model, out)
        elif serialization_format == SERIALIZATION_FORMAT_CLOUDPICKLE:
            import cloudpickle
            cloudpickle.dump(sk_model, out)
        else:
            raise MlflowException(
                    message="Unrecognized serialization format: {serialization_format}".format(
                        serialization_format=serialization_format),
                    error_code=INTERNAL_ERROR) 
開發者ID:mlflow,項目名稱:mlflow,代碼行數:21,代碼來源:sklearn.py

示例13: save

# 需要導入模塊: import cloudpickle [as 別名]
# 或者: from cloudpickle import dump [as 別名]
def save(self, path=None):
        """Save model to a pickle located at `path`"""
        if path is None:
            path = os.path.join(logger.get_dir(), "model.pkl")

        with tempfile.TemporaryDirectory() as td:
            U.save_state(os.path.join(td, "model"))
            arc_name = os.path.join(td, "packed.zip")
            with zipfile.ZipFile(arc_name, 'w') as zipf:
                for root, dirs, files in os.walk(td):
                    for fname in files:
                        file_path = os.path.join(root, fname)
                        if file_path != arc_name:
                            zipf.write(file_path, os.path.relpath(file_path, td))
            with open(arc_name, "rb") as f:
                model_data = f.read()
        with open(path, "wb") as f:
            cloudpickle.dump((model_data, self._act_params), f) 
開發者ID:cxxgtxy,項目名稱:deeprl-baselines,代碼行數:20,代碼來源:simple.py

示例14: dump

# 需要導入模塊: import cloudpickle [as 別名]
# 或者: from cloudpickle import dump [as 別名]
def dump(self, obj):
        self.inject_addons()
        try:
            return Pickler.dump(self, obj)
        except RuntimeError as e:
            if 'recursion' in e.args[0]:
                msg = """Could not pickle object as excessively deep recursion required."""
                raise pickle.PicklingError(msg)
            else:
                raise 
開發者ID:pywren,項目名稱:pywren-ibm-cloud,代碼行數:12,代碼來源:cloudpickle.py

示例15: save

# 需要導入模塊: import cloudpickle [as 別名]
# 或者: from cloudpickle import dump [as 別名]
def save(self, directory: str) -> None:
        shutil.copyfile(self.model_file, os.path.join(directory, 'elmo.pt'))
        shell(f'rm -f {self.model_file}')
        with open(os.path.join(directory, 'elmo.pkl'), 'wb') as f:
            cloudpickle.dump({
                'class_to_i': self.class_to_i,
                'i_to_class': self.i_to_class,
                'config_num': self.config_num,
                'random_seed': self.random_seed,
                'dropout': self.dropout
            }, f) 
開發者ID:Pinafore,項目名稱:qb,代碼行數:13,代碼來源:elmo.py


注:本文中的cloudpickle.dump方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。