Python chainer.serializers() Examples
The following are 5
code examples of chainer.serializers().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
chainer
, or try the search function
.
Example #1
Source File: model.py From chainer-gqn with MIT License | 5 votes |
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
Example #2
Source File: char_encdec.py From knmt with GNU General Public License v3.0 | 5 votes |
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
Example #3
Source File: test_hdf5.py From chainer with MIT License | 5 votes |
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)
Example #4
Source File: builder.py From lencon with MIT License | 5 votes |
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
Example #5
Source File: train.py From lencon with MIT License | 5 votes |
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)