本文整理汇总了Python中cPickle.HIGHEST_PROTOCOL属性的典型用法代码示例。如果您正苦于以下问题:Python cPickle.HIGHEST_PROTOCOL属性的具体用法?Python cPickle.HIGHEST_PROTOCOL怎么用?Python cPickle.HIGHEST_PROTOCOL使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类cPickle
的用法示例。
在下文中一共展示了cPickle.HIGHEST_PROTOCOL属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set
# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import HIGHEST_PROTOCOL [as 别名]
def set(self, key, value, timeout=None):
if timeout is None:
timeout = self.default_timeout
filename = self._get_filename(key)
self._prune()
try:
fd, tmp = tempfile.mkstemp(suffix=self._fs_transaction_suffix,
dir=self._path)
f = os.fdopen(fd, 'wb')
try:
pickle.dump(int(time() + timeout), f, 1)
pickle.dump(value, f, pickle.HIGHEST_PROTOCOL)
finally:
f.close()
rename(tmp, filename)
os.chmod(filename, self._mode)
except (IOError, OSError):
pass
示例2: gt_segdb
# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import HIGHEST_PROTOCOL [as 别名]
def gt_segdb(self):
"""
return ground truth image regions database
:return: imdb[image_index]['', 'flipped']
"""
print("======== Starting to get gt_segdb ========")
cache_file = os.path.join(self.cache_path, self.name + '_gt_segdb.pkl')
if os.path.exists(cache_file):
with open(cache_file, 'rb') as fid:
segdb = cPickle.load(fid)
print '========= {} gt segdb loaded from {}'.format(self.name, cache_file)
return segdb
print("======== Starting to create gt_segdb ======")
gt_segdb = []
for index in tqdm(self.image_set_index):
gt_segdb.append(self.load_segdb_from_index(index))
# gt_segdb = [self.load_segdb_from_index(index) for index in self.image_set_index]
with open(cache_file, 'wb') as fid:
cPickle.dump(gt_segdb, fid, cPickle.HIGHEST_PROTOCOL)
print '========= Wrote gt segdb to {}'.format(cache_file)
return gt_segdb
示例3: gt_roidb
# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import HIGHEST_PROTOCOL [as 别名]
def gt_roidb(self):
"""
return ground truth image regions database
:return: imdb[image_index]['boxes', 'gt_classes', 'gt_overlaps', 'flipped']
"""
cache_file = os.path.join(self.cache_path, self.name + '_gt_roidb.pkl')
if os.path.exists(cache_file):
with open(cache_file, 'rb') as fid:
roidb = cPickle.load(fid)
print '{} gt roidb loaded from {}'.format(self.name, cache_file)
return roidb
gt_roidb = [self.load_pascal_annotation(index) for index in self.image_set_index]
with open(cache_file, 'wb') as fid:
cPickle.dump(gt_roidb, fid, cPickle.HIGHEST_PROTOCOL)
print 'wrote gt roidb to {}'.format(cache_file)
return gt_roidb
示例4: gt_segdb
# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import HIGHEST_PROTOCOL [as 别名]
def gt_segdb(self):
"""
return ground truth image regions database
:return: imdb[image_index]['boxes', 'gt_classes', 'gt_overlaps', 'flipped']
"""
cache_file = os.path.join(self.cache_path, self.name + '_gt_segdb.pkl')
if os.path.exists(cache_file):
with open(cache_file, 'rb') as fid:
segdb = cPickle.load(fid)
print '{} gt segdb loaded from {}'.format(self.name, cache_file)
return segdb
gt_segdb = [self.load_pascal_segmentation_annotation(index) for index in self.image_set_index]
with open(cache_file, 'wb') as fid:
cPickle.dump(gt_segdb, fid, cPickle.HIGHEST_PROTOCOL)
print 'wrote gt segdb to {}'.format(cache_file)
return gt_segdb
示例5: selective_search_roidb
# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import HIGHEST_PROTOCOL [as 别名]
def selective_search_roidb(self, gt_roidb, append_gt=False):
"""
get selective search roidb and ground truth roidb
:param gt_roidb: ground truth roidb
:param append_gt: append ground truth
:return: roidb of selective search
"""
cache_file = os.path.join(self.cache_path, self.name + '_ss_roidb.pkl')
if os.path.exists(cache_file):
with open(cache_file, 'rb') as fid:
roidb = cPickle.load(fid)
print '{} ss roidb loaded from {}'.format(self.name, cache_file)
return roidb
if append_gt:
print 'appending ground truth annotations'
ss_roidb = self.load_selective_search_roidb(gt_roidb)
roidb = IMDB.merge_roidbs(gt_roidb, ss_roidb)
else:
roidb = self.load_selective_search_roidb(gt_roidb)
with open(cache_file, 'wb') as fid:
cPickle.dump(roidb, fid, cPickle.HIGHEST_PROTOCOL)
print 'wrote ss roidb to {}'.format(cache_file)
return roidb
示例6: gt_segdb
# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import HIGHEST_PROTOCOL [as 别名]
def gt_segdb(self):
"""
return ground truth image regions database
:return: imdb[image_index]['', 'flipped']
"""
cache_file = os.path.join(self.cache_path, self.name + '_gt_segdb.pkl')
if os.path.exists(cache_file):
with open(cache_file, 'rb') as fid:
segdb = cPickle.load(fid)
print '{} gt segdb loaded from {}'.format(self.name, cache_file)
return segdb
# gt_segdb = [self.load_segdb_from_index(index) for index in self.image_set_index]
print("======== Load segmentation ground truth data =======")
gt_segdb = []
for index in tqdm(self.image_set_index):
gt_segdb.append(self.load_segdb_from_index(index))
with open(cache_file, 'wb') as fid:
cPickle.dump(gt_segdb, fid, cPickle.HIGHEST_PROTOCOL)
print 'wrote gt segdb to {}'.format(cache_file)
return gt_segdb
示例7: gt_roidb
# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import HIGHEST_PROTOCOL [as 别名]
def gt_roidb(self):
"""
Return the database of ground-truth regions of interest.
This function loads/saves from/to a cache file to speed up future calls.
"""
cache_file = os.path.join(self.cache_path, self.name + '_gt_roidb.pkl')
if os.path.exists(cache_file):
with open(cache_file, 'rb') as fid:
roidb = cPickle.load(fid)
print '{} gt roidb loaded from {}'.format(self.name, cache_file)
return roidb
gt_roidb = [self._load_pascal_annotation(index)
for index in self.image_index]
with open(cache_file, 'wb') as fid:
cPickle.dump(gt_roidb, fid, cPickle.HIGHEST_PROTOCOL)
print 'wrote gt roidb to {}'.format(cache_file)
return gt_roidb
示例8: gt_roidb
# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import HIGHEST_PROTOCOL [as 别名]
def gt_roidb(self):
"""
Return the database of ground-truth regions of interest.
This function loads/saves from/to a cache file to speed up future calls.
"""
cache_file = osp.join(self.cache_path, self.name + '_gt_roidb.pkl')
if osp.exists(cache_file):
with open(cache_file, 'rb') as fid:
roidb = cPickle.load(fid)
print '{} gt roidb loaded from {}'.format(self.name, cache_file)
return roidb
gt_roidb = [self._load_coco_annotation(index)
for index in self._image_index]
with open(cache_file, 'wb') as fid:
cPickle.dump(gt_roidb, fid, cPickle.HIGHEST_PROTOCOL)
print 'wrote gt roidb to {}'.format(cache_file)
return gt_roidb
示例9: gt_roidb
# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import HIGHEST_PROTOCOL [as 别名]
def gt_roidb(self):
"""
Return the database of ground-truth regions of interest, aka, the annotations.
This function loads/saves from/to a cache file to speed up future calls.
"""
cache_file = os.path.join(self.cache_path, self.name + '_gt_roidb.pkl')
if os.path.exists(cache_file):
with open(cache_file, 'rb') as fid:
roidb = cPickle.load(fid)
print '{} gt roidb loaded from {}'.format(self.name, cache_file)
return roidb
gt_roidb = [self._load_pascal_annotation(index)
for index in self.image_index]
with open(cache_file, 'wb') as fid:
cPickle.dump(gt_roidb, fid, cPickle.HIGHEST_PROTOCOL)
print 'wrote gt roidb to {}'.format(cache_file)
return gt_roidb
示例10: process
# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import HIGHEST_PROTOCOL [as 别名]
def process(options, workingCollection, annotationName, outputpkl):
rootpath = options.rootpath
overwrite = options.overwrite
resultfile = os.path.join(outputpkl)
if checkToSkip(resultfile, overwrite):
return 0
concepts = readConcepts(workingCollection, annotationName, rootpath)
id_images = readImageSet(workingCollection, workingCollection, rootpath)
tagmatrix = np.random.rand(len(id_images), len(concepts))
# save results in pkl format
printStatus(INFO, "Dump results in pkl format at %s" % resultfile)
makedirsforfile(resultfile)
with open(resultfile, 'w') as f:
pickle.dump({'concepts':concepts, 'id_images':map(int, id_images), 'scores':tagmatrix}, f, pickle.HIGHEST_PROTOCOL)
示例11: set
# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import HIGHEST_PROTOCOL [as 别名]
def set(self, key, value, timeout=None):
if timeout is None:
timeout = int(time() + self.default_timeout)
elif timeout != 0:
timeout = int(time() + timeout)
filename = self._get_filename(key)
self._prune()
try:
fd, tmp = tempfile.mkstemp(suffix=self._fs_transaction_suffix,
dir=self._path)
with os.fdopen(fd, 'wb') as f:
pickle.dump(timeout, f, 1)
pickle.dump(value, f, pickle.HIGHEST_PROTOCOL)
rename(tmp, filename)
os.chmod(filename, self._mode)
except (IOError, OSError):
return False
else:
return True
示例12: flush
# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import HIGHEST_PROTOCOL [as 别名]
def flush():
prints = []
for name, vals in _since_last_flush.items():
prints.append("{}\t{}".format(name, np.mean(vals.values())))
_since_beginning[name].update(vals)
x_vals = np.sort(_since_beginning[name].keys())
y_vals = [_since_beginning[name][x] for x in x_vals]
plt.clf()
plt.plot(x_vals, y_vals)
plt.xlabel('iteration')
plt.ylabel(name)
plt.savefig(name.replace(' ', '_')+'.jpg')
print "iter {}\t{}".format(_iter[0], "\t".join(prints))
_since_last_flush.clear()
with open('log.pkl', 'wb') as f:
pickle.dump(dict(_since_beginning), f, pickle.HIGHEST_PROTOCOL)
示例13: test_pickleing
# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import HIGHEST_PROTOCOL [as 别名]
def test_pickleing(self):
"""
Test pickling for example save vm env.
"""
m = factory(AA, system_version=0, qemu_version=0)()
mm = factory(BB, qemu_version=3)()
f = open("/tmp/pick", "w+")
cPickle.dump(m, f, cPickle.HIGHEST_PROTOCOL)
cPickle.dump(mm, f, cPickle.HIGHEST_PROTOCOL)
f.close()
# Delete classes for ensure that pickel works correctly.
name = m.__class__.__name__
del m
del globals()[name]
name = mm.__class__.__name__
del mm
del globals()[name]
f = open("/tmp/pick", "r+")
c = cPickle.load(f)
cc = cPickle.load(f)
f.close()
示例14: snapshot
# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import HIGHEST_PROTOCOL [as 别名]
def snapshot(self, iter):
net = self.net
if not os.path.exists(self.output_dir):
os.makedirs(self.output_dir)
# Store the model snapshot
filename = cfg.TRAIN.SNAPSHOT_PREFIX + '_iter_{:d}'.format(iter) + '.pth'
filename = os.path.join(self.output_dir, filename)
torch.save(self.net.state_dict(), filename)
print('Wrote snapshot to: {:s}'.format(filename))
if iter % 10000 == 0:
shutil.copyfile(filename, filename + '.{:d}_cache'.format(iter))
# Also store some meta information, random state, etc.
nfilename = cfg.TRAIN.SNAPSHOT_PREFIX + '_iter_{:d}'.format(iter) + '.pkl'
nfilename = os.path.join(self.output_dir, nfilename)
# current state of numpy random
st0 = np.random.get_state()
# current position in the database
cur = self.data_layer._cur
# current shuffled indexes of the database
perm = self.data_layer._perm
# current position in the validation database
cur_val = self.data_layer_val._cur
# current shuffled indexes of the validation database
perm_val = self.data_layer_val._perm
# Dump the meta info
with open(nfilename, 'wb') as fid:
pickle.dump(st0, fid, pickle.HIGHEST_PROTOCOL)
pickle.dump(cur, fid, pickle.HIGHEST_PROTOCOL)
pickle.dump(perm, fid, pickle.HIGHEST_PROTOCOL)
pickle.dump(cur_val, fid, pickle.HIGHEST_PROTOCOL)
pickle.dump(perm_val, fid, pickle.HIGHEST_PROTOCOL)
pickle.dump(iter, fid, pickle.HIGHEST_PROTOCOL)
return filename, nfilename
开发者ID:Sunarker,项目名称:Collaborative-Learning-for-Weakly-Supervised-Object-Detection,代码行数:42,代码来源:train_val.py
示例15: evaluate_detections
# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import HIGHEST_PROTOCOL [as 别名]
def evaluate_detections(self, detections, **kwargs):
cache_path = os.path.join(self._root_path, 'cache', '{}_{}.pkl'.format(self._name, 'detections'))
logger.info('saving cache {}'.format(cache_path))
with open(cache_path, 'wb') as fid:
pickle.dump(detections, fid, pickle.HIGHEST_PROTOCOL)
self._evaluate_detections(detections, **kwargs)