本文整理匯總了Python中chainer.serializers.save_hdf5方法的典型用法代碼示例。如果您正苦於以下問題:Python serializers.save_hdf5方法的具體用法?Python serializers.save_hdf5怎麽用?Python serializers.save_hdf5使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類chainer.serializers
的用法示例。
在下文中一共展示了serializers.save_hdf5方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: save_model
# 需要導入模塊: from chainer import serializers [as 別名]
# 或者: from chainer.serializers import save_hdf5 [as 別名]
def save_model(self, model_filename):
"""Save a network model to a file
"""
serializers.save_hdf5(model_filename, self.model)
serializers.save_hdf5(model_filename + '.opt', self.optimizer)
示例2: save_and_load_hdf5
# 需要導入模塊: from chainer import serializers [as 別名]
# 或者: from chainer.serializers import save_hdf5 [as 別名]
def save_and_load_hdf5(src, dst):
"""Saves ``src`` to an HDF5 file and loads it to ``dst``.
This is a short cut of :func:`save_and_load` using HDF5 de/serializers.
Args:
src: An object to save.
dst: An object to load to.
"""
save_and_load(src, dst, 'tmp.h5',
serializers.save_hdf5, serializers.load_hdf5)
示例3: save
# 需要導入模塊: from chainer import serializers [as 別名]
# 或者: from chainer.serializers import save_hdf5 [as 別名]
def save(self):
serializers.save_hdf5("conv.model", self.conv)
if self.fcl_eliminated is False:
serializers.save_hdf5("fc.model", self.fc)
示例4: save
# 需要導入模塊: from chainer import serializers [as 別名]
# 或者: from chainer.serializers import save_hdf5 [as 別名]
def save(self,filename):
cs.save_hdf5(filename,self.func.copy().to_cpu())
示例5: save
# 需要導入模塊: from chainer import serializers [as 別名]
# 或者: from chainer.serializers import save_hdf5 [as 別名]
def save(self,filename):
cs.save_hdf5(filename,self.model.copy().to_cpu())
示例6: save
# 需要導入模塊: from chainer import serializers [as 別名]
# 或者: from chainer.serializers import save_hdf5 [as 別名]
def save(self,filename):
#cs.save_hdf5(filename,self.func.copy().to_cpu())
cs.save_hdf5(filename,self.func.copy())
示例7: save
# 需要導入模塊: from chainer import serializers [as 別名]
# 或者: from chainer.serializers import save_hdf5 [as 別名]
def save(self,filename):
cs.save_hdf5(filename,self.func.to_cpu())
示例8: train
# 需要導入模塊: from chainer import serializers [as 別名]
# 或者: from chainer.serializers import save_hdf5 [as 別名]
def train(epoch_num):
image_groups, sentence_groups = make_groups(train_image_ids, train_sentences)
test_image_groups, test_sentence_groups = make_groups(test_image_ids, test_sentences, train=False)
for epoch in range(epoch_num):
batches = random_batches(image_groups, sentence_groups)
sum_loss = 0
sum_acc = 0
sum_size = 0
batch_num = len(batches)
for i, (image_id_batch, sentence_batch) in enumerate(batches):
loss, acc, size = forward(caption_net, images[image_id_batch], sentence_batch)
caption_net.cleargrads()
loss.backward()
loss.unchain_backward()
optimizer.update()
sentence_length = sentence_batch.shape[1]
sum_loss += float(loss.data) * size
sum_acc += acc * size
sum_size += size
if (i + 1) % 500 == 0:
print '{} / {} loss: {} accuracy: {}'.format(i + 1, batch_num, sum_loss / sum_size, sum_acc / sum_size)
print 'epoch: {} done'.format(epoch + 1)
print 'train loss: {} accuracy: {}'.format(sum_loss / sum_size, sum_acc / sum_size)
sum_loss = 0
sum_acc = 0
sum_size = 0
for image_ids, sentences in zip(test_image_groups, test_sentence_groups):
if len(sentences) == 0:
continue
size = len(sentences)
for i in range(0, size, batch_size):
image_id_batch = image_ids[i:i + batch_size]
sentence_batch = sentences[i:i + batch_size]
loss, acc, size = forward(caption_net, images[image_id_batch], sentence_batch, train=False)
sentence_length = sentence_batch.shape[1]
sum_loss += float(loss.data) * size
sum_acc += acc * size
sum_size += size
print 'test loss: {} accuracy: {}'.format(sum_loss / sum_size, sum_acc / sum_size)
serializers.save_hdf5(args.output + '_{0:04d}.model'.format(epoch), caption_net)
serializers.save_hdf5(args.output + '_{0:04d}.state'.format(epoch), optimizer)