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


Python serialization.load方法代码示例

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


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

示例1: load_to

# 需要导入模块: from blocks import serialization [as 别名]
# 或者: from blocks.serialization import load [as 别名]
def load_to(self, main_loop):
        with open(self.path, "rb") as source:
            main_loop.model.set_parameter_values(load_parameters(source))
            if self.load_iteration_state:
                main_loop.iteration_state = load(source, name='iteration_state')
            if self.load_log:
                main_loop.log = load(source, name='log') 
开发者ID:tombosc,项目名称:dict_based_learning,代码行数:9,代码来源:extensions.py

示例2: load_parameter_values

# 需要导入模块: from blocks import serialization [as 别名]
# 或者: from blocks.serialization import load [as 别名]
def load_parameter_values(self, path):
        with closing(numpy.load(path)) as source:
            param_values = {}
            for name, value in source.items():
                if name != 'pkl':
                    name_ = name.replace(BRICK_DELIMITER, '/')
                    if not name_.startswith('/'):
                        name_ = '/' + name_
                    param_values[name_] = value
        return param_values 
开发者ID:aeloyq,项目名称:MTBasedOnBlocks,代码行数:12,代码来源:checkpoint.py

示例3: before_training

# 需要导入模块: from blocks import serialization [as 别名]
# 或者: from blocks.serialization import load [as 别名]
def before_training(self):
        if not os.path.exists(self.path_to_folder):
            logger.info("No dump found")
            return
        logger.info("Loading the state from {} into the main loop"
                    .format(self.path_to_folder))
        try:
            self.load_to(self.main_loop)
            self.main_loop.log.current_row[LOADED_FROM] = self.path_to_folder
        except Exception:
            reraise_as("Failed to load the state") 
开发者ID:aeloyq,项目名称:MTBasedOnBlocks,代码行数:13,代码来源:checkpoint.py

示例4: load_iteration_state

# 需要导入模块: from blocks import serialization [as 别名]
# 或者: from blocks.serialization import load [as 别名]
def load_iteration_state(self):
        with open(self.path_to_iteration_state, "rb") as source:
            return load(source) 
开发者ID:aeloyq,项目名称:MTBasedOnBlocks,代码行数:5,代码来源:checkpoint.py

示例5: load_log

# 需要导入模块: from blocks import serialization [as 别名]
# 或者: from blocks.serialization import load [as 别名]
def load_log(self):
        with open(self.path_to_log, "rb") as source:
            return cPickle.load(source) 
开发者ID:aeloyq,项目名称:MTBasedOnBlocks,代码行数:5,代码来源:checkpoint.py

示例6: load_parameter_values

# 需要导入模块: from blocks import serialization [as 别名]
# 或者: from blocks.serialization import load [as 别名]
def load_parameter_values(path, brick_delimiter='|'):
        with closing(numpy.load(path)) as source:
            param_values = {}
            for name, value in source.items():
                if name != 'pkl':
                    brick_delimiter = '|'
                    # Chris: BRICK_DELIMITER is defined in blocks.serialization
                    if brick_delimiter is None:
                        name_ = name.replace(BRICK_DELIMITER, '/')
                    else:
                        name_ = name.replace(brick_delimiter, '/')
                    if not name_.startswith('/'):
                        name_ = '/' + name_
                    param_values[name_] = value
        return param_values 
开发者ID:chrishokamp,项目名称:neural_mt,代码行数:17,代码来源:__init__.py

示例7: load_parameter_values

# 需要导入模块: from blocks import serialization [as 别名]
# 或者: from blocks.serialization import load [as 别名]
def load_parameter_values(self, path):
        with closing(numpy.load(path)) as source:
            param_values = {}
            for name, value in source.items():
                if name != 'pkl':
                    # fs439: always use '-' to avoid issues with incompatible
                    # blocks versions
                    #name_ = name.replace(BRICK_DELIMITER, '/')
                    name_ = name.replace('-', '/')
                    if not name_.startswith('/'):
                        name_ = '/' + name_
                    param_values[name_] = value
        return param_values 
开发者ID:ucam-smt,项目名称:sgnmt,代码行数:15,代码来源:checkpoint.py

示例8: before_training

# 需要导入模块: from blocks import serialization [as 别名]
# 或者: from blocks.serialization import load [as 别名]
def before_training(self):
        if not os.path.exists(self.path_to_folder):
            logger.info("No dump found")
            return
        logger.info("Loading the state from {} into the main loop"
                    .format(self.path_to_folder))
        try:
            self.load_to(self.main_loop)
            self.main_loop.log.current_row[LOADED_FROM] = self.path_to_folder
            if self.reset_epoch:
                logger.info("Reset epoch...")
                self.main_loop.status['epoch_started'] = False
        except Exception:
            reraise_as("Failed to load the state") 
开发者ID:ucam-smt,项目名称:sgnmt,代码行数:16,代码来源:checkpoint.py

示例9: _load_model

# 需要导入模块: from blocks import serialization [as 别名]
# 或者: from blocks.serialization import load [as 别名]
def _load_model(self, main_loop_path):
        with open(main_loop_path, 'rb') as src:
            main_loop = load(src, use_cpickle=True)
        ali, = main_loop.model.top_bricks
        return ali 
开发者ID:MiriamHu,项目名称:ActiveBoundary,代码行数:7,代码来源:generative_model.py

示例10: load_iteration_state

# 需要导入模块: from blocks import serialization [as 别名]
# 或者: from blocks.serialization import load [as 别名]
def load_iteration_state(self):
        with open(self.path_to_iteration_state, "rb") as source:
            return load(source, use_cpickle=True) 
开发者ID:SwordYork,项目名称:DCNMT,代码行数:5,代码来源:checkpoint.py

示例11: load_to

# 需要导入模块: from blocks import serialization [as 别名]
# 或者: from blocks.serialization import load [as 别名]
def load_to(self, main_loop):
        """Loads the dump from the root folder into the main loop."""
        logger.info(" Reloading model")
        try:
            logger.debug(" ...loading model parameters")
            params_all = self.load_parameters()
            params_this = main_loop.model.get_parameter_dict()
            missing = set(params_this.keys()) - set(params_all.keys())
            for pname in params_this.keys():
                if pname in params_all:
                    val = params_all[pname]
                    if params_this[pname].get_value().shape != val.shape:
                        logger.warning(
                            " Dimension mismatch {}-{} for {}"
                            .format(params_this[pname].get_value().shape,
                                    val.shape, pname))

                    params_this[pname].set_value(val)
                    logger.debug(" Loaded to CG {:15}: {}"
                                .format(val.shape, pname))
                else:
                    logger.warning(
                        " Parameter does not exist: {}".format(pname))
            logger.info(
                "Number of parameters loaded for computation graph: {}"
                .format(len(params_this) - len(missing)))
        except Exception as e:
            logger.error(" Error {0}".format(str(e)))

        try:
            logger.info(" Loading iteration state...")
            iter_state = self.load_iteration_state()
            if self.slim_iteration_state:
                try:
                    main_loop.epoch_iterator = iter_state
                except:
                    logger.warn("Stored iteration state not slim. "
                                "Trying to load as full state")
                    main_loop.iteration_state = iter_state
            else:
                try:
                    main_loop.iteration_state = iter_state
                except:
                    logger.warn("Stored iteration state not full. "
                                "Trying to load as slim state")
                    main_loop.epoch_iterator = iter_state
        except Exception as e:
            logger.error(" Error {0}".format(str(e)))

        try:
            logger.info(" Loading log...")
            main_loop.log = self.load_log()
        except Exception as e:
            logger.error(" Error {0}".format(str(e))) 
开发者ID:ucam-smt,项目名称:sgnmt,代码行数:56,代码来源:checkpoint.py

示例12: add_command_line_args

# 需要导入模块: from blocks import serialization [as 别名]
# 或者: from blocks.serialization import load [as 别名]
def add_command_line_args(self, parser):
        """
        Add custom command-line parameters
        :param parser:
        :return:
        """

        super(TextComprehensionBase, self).add_command_line_args(parser)

        parser.add_argument('-bv', '--batch_size_valid', type=int, default="100",
                            help='size of a mini-batch in test and validation')

        parser.add_argument('-skba', '--sort_k_batches_ahead', type=int, default=10,
                            help='number of batches that will be read in advance and sorted according to context length, this usually speeds up training')

        parser.add_argument('-dt', '--dataset_type', default='cbt', choices=['cbt','cnn', 'babi'],
                            help='type of the dataset to load')

        parser.add_argument('-ehd', '--encoder_hidden_dims', type=int, default=100,
                            help='number of recurrent hidden dimensions (meta param suggested value: {4;32;128;256})')

        parser.add_argument('-sed','--source_embeddings_dim', type=int, default=200,
                            help='dimensions of embeddings for source words (meta param suggested value: {100;300;600})')

        parser.add_argument('-lr', '--learning_rate', type=float, default=0.001,
                            help='learning rate of the gradient update rule (meta param suggested value: {0.005;0.001;0.0005})')

        parser.add_argument('-qice', '--query_inited_context_encoder', type=str2bool, default=False,
                            help='when true uses the text of the question to initialize context encoder, so the network knows the question and it can look only for the relevant answer and not answers to all possible questions (meta param suggested value: {False;True})')

        parser.add_argument('--load_model', type=str, default=None,
                            help='model to be loaded')

        parser.add_argument('--output_dir', type=str, default='.',
                            help='output directory where, e.g., visualization will be stored')

        parser.add_argument('--own_eval', action='store_true', default=True,
                            help='whether to use our evaluation during training')

        parser.add_argument('--files_to_visualize', nargs="+", type=str,
                            help='list of files that will be visualized by the loaded model')

        parser.add_argument('--y_hat_out_file', type=str, default="",
                            help='dump file for y_hat generated by the loaded model')

        parser.add_argument('--no_html', dest='print_html', action='store_false',
                            help='disables html visualization printing')
        parser.set_defaults(print_html=True)

        parser.add_argument('--weighted_att', action='store_true',
                            help='Use weighted attention model instead of attention sum.') 
开发者ID:sohuren,项目名称:attention-sum-reader,代码行数:53,代码来源:text_comprehension_base.py


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