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


Python cPickle.HIGHEST_PROTOCOL屬性代碼示例

本文整理匯總了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 
開發者ID:jojoin,項目名稱:cutout,代碼行數:20,代碼來源:filecache.py

示例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 
開發者ID:tonysy,項目名稱:Deep-Feature-Flow-Segmentation,代碼行數:25,代碼來源:cityscape_video.py

示例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 
開發者ID:tonysy,項目名稱:Deep-Feature-Flow-Segmentation,代碼行數:20,代碼來源:pascal_voc.py

示例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 
開發者ID:tonysy,項目名稱:Deep-Feature-Flow-Segmentation,代碼行數:20,代碼來源:pascal_voc.py

示例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 
開發者ID:tonysy,項目名稱:Deep-Feature-Flow-Segmentation,代碼行數:27,代碼來源:pascal_voc.py

示例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 
開發者ID:tonysy,項目名稱:Deep-Feature-Flow-Segmentation,代碼行數:25,代碼來源:cityscape.py

示例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 
開發者ID:CharlesShang,項目名稱:TFFRCNN,代碼行數:22,代碼來源:pascal_voc.py

示例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 
開發者ID:CharlesShang,項目名稱:TFFRCNN,代碼行數:21,代碼來源:coco.py

示例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 
開發者ID:CharlesShang,項目名稱:TFFRCNN,代碼行數:22,代碼來源:kittivoc.py

示例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) 
開發者ID:li-xirong,項目名稱:jingwei,代碼行數:19,代碼來源:randomtags.py

示例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 
開發者ID:jpush,項目名稱:jbox,代碼行數:21,代碼來源:cache.py

示例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) 
開發者ID:igul222,項目名稱:improved_wgan_training,代碼行數:23,代碼來源:plot.py

示例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() 
開發者ID:avocado-framework,項目名稱:avocado-vt,代碼行數:27,代碼來源:test_versionable_class.py

示例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) 
開發者ID:awslabs,項目名稱:dynamic-training-with-apache-mxnet-on-aws,代碼行數:8,代碼來源:imdb.py


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