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


Python chainer.serializers方法代碼示例

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


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

示例1: load

# 需要導入模塊: import chainer [as 別名]
# 或者: from chainer import serializers [as 別名]
def load(self, snapshot_root_directory, epoch):
        model_path = os.path.join(snapshot_root_directory,
                                  self.snapshot_filename)
        try:
            if os.path.exists(model_path):
                print("loading {}".format(model_path))
                chainer.serializers.load_hdf5(model_path, self.parameters)
            return True
        except Exception as error:
            print(error)
        return False 
開發者ID:musyoku,項目名稱:chainer-gqn,代碼行數:13,代碼來源:model.py

示例2: load_encdec_from_config

# 需要導入模塊: import chainer [as 別名]
# 或者: from chainer import serializers [as 別名]
def load_encdec_from_config(config_fn, model_fn):
    config=json.load(open(config_fn))
    ced = create_model(config)
    charlist = json.load(open(config["indexer"], "r"))
    chardict = dict((c,i) for i,c in enumerate(charlist))
    serializers.load_npz(model_fn, ced)
    return ced, charlist, chardict 
開發者ID:fabiencro,項目名稱:knmt,代碼行數:9,代碼來源:char_encdec.py

示例3: test_raise

# 需要導入模塊: import chainer [as 別名]
# 或者: from chainer import serializers [as 別名]
def test_raise(self):
        del sys.modules['chainer.serializers.hdf5']
        del sys.modules['chainer.serializers.npz']
        del sys.modules['chainer.serializers']

        import chainer.serializers
        self.assertFalse(chainer.serializers.hdf5._available)
        with self.assertRaises(RuntimeError):
            chainer.serializers.save_hdf5(None, None, None)
        with self.assertRaises(RuntimeError):
            chainer.serializers.load_hdf5(None, None)
        with self.assertRaises(RuntimeError):
            chainer.serializers.HDF5Serializer(None)
        with self.assertRaises(RuntimeError):
            chainer.serializers.HDF5Deserializer(None) 
開發者ID:chainer,項目名稱:chainer,代碼行數:17,代碼來源:test_hdf5.py

示例4: _build_model

# 需要導入模塊: import chainer [as 別名]
# 或者: from chainer import serializers [as 別名]
def _build_model(self, config, src_vocab, trg_vocab):

        def convert(val):
            if val.isdigit():
                return int(val)
            try:
                return float(val)
            except:
                return val
        model_config = config['Model']

        kwargs = {k: convert(v) for k, v in model_config.items() if k != 'name'}
        m = getattr(models, model_config['name'])(**kwargs)

        model_path = os.path.join(self.save_dir, 'model.hdf')
        # load
        if os.path.exists(model_path):
            chainer.serializers.load_hdf5(model_path, m)

        xstoi = src_vocab.stoi
        ystoi = trg_vocab.stoi
        xbos = xstoi('<s>')
        xeos = xstoi('</s>')
        ybos = ystoi('<s>')
        yeos = ystoi('</s>')
        m.set_symbols(xbos, xeos, ybos, yeos)

        m.name = model_config['name']
        m.byte = self._load_binary_config(config['Training'], 'byte')
        m.reverse_output = self._load_binary_config(
            config['Training'], 'reverse_output')
        if m.byte:
            m.vocab = trg_vocab
        return m 
開發者ID:kiyukuta,項目名稱:lencon,代碼行數:36,代碼來源:builder.py

示例5: save

# 需要導入模塊: import chainer [as 別名]
# 或者: from chainer import serializers [as 別名]
def save(self):
        save_dir = self.save_dir
        m = self.model.copy()
        m.name = self.model.name
        m.to_cpu()

        model_path = os.path.join(save_dir, 'model.hdf')
        chainer.serializers.save_hdf5(model_path, m)
        with open(os.path.join(save_dir, "vocab.pkl"), "wb") as f:
            pickle.dump((self.src_vcb, self.trg_vcb), f) 
開發者ID:kiyukuta,項目名稱:lencon,代碼行數:12,代碼來源:train.py


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