當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。