当前位置: 首页>>代码示例>>Python>>正文


Python cPickle.load方法代码示例

本文整理汇总了Python中cPickle.load方法的典型用法代码示例。如果您正苦于以下问题:Python cPickle.load方法的具体用法?Python cPickle.load怎么用?Python cPickle.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块cPickle的用法示例。

在下文中一共展示了cPickle.load方法的25个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _augment_images_worker

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import load [as 别名]
def _augment_images_worker(self, augseq, queue_source, queue_result):
        """Worker function that endlessly queries the source queue (input
        batches), augments batches in it and sends the result to the output
        queue."""
        while True:
            # wait for a new batch in the source queue and load it
            batch_str = queue_source.get()
            batch = pickle.loads(batch_str)

            # augment the batch
            if batch.images is not None and batch.keypoints is not None:
                augseq_det = augseq.to_deterministic()
                batch.images_aug = augseq_det.augment_images(batch.images)
                batch.keypoints_aug = augseq_det.augment_keypoints(batch.keypoints)
            elif batch.images is not None:
                batch.images_aug = augseq.augment_images(batch.images)
            elif batch.keypoints is not None:
                batch.keypoints_aug = augseq.augment_keypoints(batch.keypoints)

            # send augmented batch to output queue
            queue_result.put(pickle.dumps(batch, protocol=-1)) 
开发者ID:aleju,项目名称:cat-bbs,代码行数:23,代码来源:train.py


示例2: register

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import load [as 别名]
def register(self, name, serializer):
        """Register ``serializer`` object under ``name``.

        Raises :class:`AttributeError` if ``serializer`` in invalid.

        .. note::

            ``name`` will be used as the file extension of the saved files.

        :param name: Name to register ``serializer`` under
        :type name: ``unicode`` or ``str``
        :param serializer: object with ``load()`` and ``dump()``
            methods

        """
        # Basic validation
        getattr(serializer, 'load')
        getattr(serializer, 'dump')

        self._serializers[name] = serializer 
开发者ID:TKkk-iOSer,项目名称:wechat-alfred-workflow,代码行数:22,代码来源:workflow.py


示例3: from_snapshot

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import load [as 别名]
def from_snapshot(self, sfile, nfile):
    print('Restoring model snapshots from {:s}'.format(sfile))
    self.net.load_state_dict(torch.load(str(sfile)))
    print('Restored.')
    # Needs to restore the other hyper-parameters/states for training, (TODO xinlei) I have
    # tried my best to find the random states so that it can be recovered exactly
    # However the Tensorflow state is currently not available
    with open(nfile, 'rb') as fid:
      st0 = pickle.load(fid)
      cur = pickle.load(fid)
      perm = pickle.load(fid)
      cur_val = pickle.load(fid)
      perm_val = pickle.load(fid)
      last_snapshot_iter = pickle.load(fid)

      np.random.set_state(st0)
      self.data_layer._cur = cur
      self.data_layer._perm = perm
      self.data_layer_val._cur = cur_val
      self.data_layer_val._perm = perm_val

    return last_snapshot_iter 
开发者ID:Sunarker,项目名称:Collaborative-Learning-for-Weakly-Supervised-Object-Detection,代码行数:24,代码来源:train_val.py


示例4: preprocess_omniglot

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import load [as 别名]
def preprocess_omniglot():
  """Download and prepare raw Omniglot data.

  Downloads the data from GitHub if it does not exist.
  Then load the images, augment with rotations if desired.
  Resize the images and write them to a pickle file.
  """

  maybe_download_data()

  directory = TRAIN_DIR
  write_file = DATA_FILE_FORMAT % 'train'
  num_labels = write_datafiles(
      directory, write_file, resize=True, rotate=TRAIN_ROTATIONS,
      new_width=IMAGE_NEW_SIZE, new_height=IMAGE_NEW_SIZE)

  directory = TEST_DIR
  write_file = DATA_FILE_FORMAT % 'test'
  write_datafiles(directory, write_file, resize=True, rotate=TEST_ROTATIONS,
                  new_width=IMAGE_NEW_SIZE, new_height=IMAGE_NEW_SIZE,
                  first_label=num_labels) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:23,代码来源:data_utils.py


示例5: extract_mnist_data

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import load [as 别名]
def extract_mnist_data(filename, num_images, image_size, pixel_depth):
  """
  Extract the images into a 4D tensor [image index, y, x, channels].

  Values are rescaled from [0, 255] down to [-0.5, 0.5].
  """
  # if not os.path.exists(file):
  if not tf.gfile.Exists(filename+".npy"):
    with gzip.open(filename) as bytestream:
      bytestream.read(16)
      buf = bytestream.read(image_size * image_size * num_images)
      data = np.frombuffer(buf, dtype=np.uint8).astype(np.float32)
      data = (data - (pixel_depth / 2.0)) / pixel_depth
      data = data.reshape(num_images, image_size, image_size, 1)
      np.save(filename, data)
      return data
  else:
    with tf.gfile.Open(filename+".npy", mode='r') as file_obj:
      return np.load(file_obj) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:21,代码来源:input.py


示例6: _load_data

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import load [as 别名]
def _load_data(self):
        """
        Load data only if the present data is not checkpointed, else, just load the checkpointed data

        :return: None
        """
        self.mapper = Mapper()
        self.mapper.generate_vocabulary(self.review_summary_file)
        self.X_fwd, self.X_bwd, self.Y = self.mapper.get_tensor(reverseflag=True)
        # Store all the mapper values in a dict for later recovery
        self.mapper_dict = dict()
        self.mapper_dict['seq_length'] = self.mapper.get_seq_length()
        self.mapper_dict['vocab_size'] = self.mapper.get_vocabulary_size()
        self.mapper_dict['rev_map'] = self.mapper.get_reverse_map()
        # Split into test and train data
        self._split_train_tst() 
开发者ID:harpribot,项目名称:deep-summarization,代码行数:18,代码来源:bidirectional.py


示例7: _load_data

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import load [as 别名]
def _load_data(self):
        """
        Load data only if the present data is not checkpointed, else, just load the checkpointed data

        :return: None
        """
        self.mapper = Mapper()
        self.mapper.generate_vocabulary(self.review_summary_file)
        self.X, self.Y = self.mapper.get_tensor()
        # Store all the mapper values in a dict for later recovery
        self.mapper_dict = dict()
        self.mapper_dict['seq_length'] = self.mapper.get_seq_length()
        self.mapper_dict['vocab_size'] = self.mapper.get_vocabulary_size()
        self.mapper_dict['rev_map'] = self.mapper.get_reverse_map()
        # Split into test and train data
        self._split_train_tst() 
开发者ID:harpribot,项目名称:deep-summarization,代码行数:18,代码来源:simple.py


示例8: from_saved

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import load [as 别名]
def from_saved(cls, file_name, change_params={}):
        """
        Initializes a new network from saved data.
        file_name (str): model is loaded from tf_save/file_name.ckpt
        """
        with open(io.tf_save_path + file_name + '.pkl', 'rb') as f:
            params = pickle.load(f)
        params['load_file'] = file_name
        for p in change_params:
            params[p] = change_params[p]
        print params
        return cls(**params)

    #########################################
    #        Private helper functions       #
    ######################################### 
开发者ID:eth-nn-physics,项目名称:nn_physical_concepts,代码行数:18,代码来源:model.py


示例9: load

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import load [as 别名]
def load(validation_size_p, file_name):
    """
    Params:
    validation_size_p: percentage of data to be used for validation
    file_name (str): File containing the data
    """
    f = gzip.open(io.data_path + file_name + ".plk.gz", 'rb')
    data, states, projectors = cPickle.load(f)
    data = np.array(data)
    states = np.array(states)
    train_val_separation = int(len(data) * (1 - validation_size_p / 100.))
    training_data = data[:train_val_separation]
    training_states = states[:train_val_separation]
    validation_data = data[train_val_separation:]
    validation_states = states[train_val_separation:]
    f.close()
    return (training_data, validation_data, training_states, validation_states, projectors) 
开发者ID:eth-nn-physics,项目名称:nn_physical_concepts,代码行数:19,代码来源:data_loader.py


示例10: read_pickle

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import load [as 别名]
def read_pickle(self,filename):
        try:
            import cPickle as pickle
        except ImportError:
            import pickle

        in_f = open(filename,"rb")

        tabversion = pickle.load(in_f)
        if tabversion != __tabversion__:
            raise VersionError("yacc table file version is out of date")
        self.lr_method = pickle.load(in_f)
        signature      = pickle.load(in_f)
        self.lr_action = pickle.load(in_f)
        self.lr_goto   = pickle.load(in_f)
        productions    = pickle.load(in_f)

        self.lr_productions = []
        for p in productions:
            self.lr_productions.append(MiniProduction(*p))

        in_f.close()
        return signature

    # Bind all production function names to callable objects in pdict 
开发者ID:nojanath,项目名称:SublimeKSP,代码行数:27,代码来源:yacc.py


示例11: _prune

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import load [as 别名]
def _prune(self):
        entries = self._list_dir()
        if len(entries) > self._threshold:
            now = time()
            for idx, fname in enumerate(entries):
                remove = False
                f = None
                try:
                    try:
                        f = open(fname, 'rb')
                        expires = pickle.load(f)
                        remove = expires <= now or idx % 3 == 0
                    finally:
                        if f is not None:
                            f.close()
                except Exception:
                    pass
                if remove:
                    try:
                        os.remove(fname)
                    except (IOError, OSError):
                        pass 
开发者ID:jojoin,项目名称:cutout,代码行数:24,代码来源:filecache.py


示例12: loadFiles

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import load [as 别名]
def loadFiles(self,pklfile,outspecfile):
        """ loads pkl and outspec files
        Args:
            pklfile (string) - full filepath to pkl file to load
            outspecfile (string) - fille filepath to outspec.json file
        Return:
            DRM (dict) - a dict containing seed, DRM, system
            outspec (dict) - a dict containing input instructions
        """
        try:
            with open(pklfile, 'rb') as f:#load from cache
                DRM = pickle.load(f)
        except:
            print('Failed to open pklfile %s'%pklfile)
            pass
        try:
            with open(outspecfile, 'rb') as g:
                outspec = json.load(g)
        except:
            print('Failed to open outspecfile %s'%outspecfile)
            pass
        return DRM, outspec 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:24,代码来源:plotTimeline.py


示例13: read_all

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import load [as 别名]
def read_all(run_dir):
    """
    Helper function that reads in all pkl files from an nsemble directory
    generated by run_ipcluster_ensemble
    
    Args:
        run_dir (string):
            Absolute path to run directory 
    
    Returns:
        allres (list):
            List of all pkl file contents in run_dir
    """
    
    pklfiles = glob.glob(os.path.join(run_dir,'*.pkl'))

    allres = []

    for counter,f in enumerate(pklfiles):
        print("%d/%d"%(counter,len(pklfiles)))
        with open(f, 'rb') as g:
            res = pickle.load(g, encoding='latin1')
        allres.append(res)
        del res # this avoids memory leaks when loading many pickle files
    return allres 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:27,代码来源:read_ipcluster_ensemble.py


示例14: read_json_lines

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import load [as 别名]
def read_json_lines(file_path):
    print("reading data...")
    with open(file_path, "r") as f:
        lines = []
        value_err_cnt = 0
        for l in tqdm(f.readlines()):
            try:
                loaded_l = json.loads(l.strip("\n"))
                lines.append(loaded_l)
            except ValueError as e:
                value_err_cnt += 1
                continue
    return lines


# def load_pickle(file_path):
#     with open(file_path, "r") as f:
#         return pickle.load(f) 
开发者ID:jayleicn,项目名称:TVQAplus,代码行数:20,代码来源:utils.py


示例15: load_dynamic_contour

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import load [as 别名]
def load_dynamic_contour(template_flame_path='None', contour_embeddings_path='None', static_embedding_path='None', angle=0):
    template_mesh = Mesh(filename=template_flame_path)
    contour_embeddings_path = contour_embeddings_path
    dynamic_lmks_embeddings = np.load(contour_embeddings_path, allow_pickle=True).item()
    lmk_face_idx_static, lmk_b_coords_static = load_static_embedding(static_embedding_path)
    lmk_face_idx_dynamic = dynamic_lmks_embeddings['lmk_face_idx'][angle]
    lmk_b_coords_dynamic = dynamic_lmks_embeddings['lmk_b_coords'][angle]
    dynamic_lmks = mesh_points_by_barycentric_coordinates(template_mesh.v, template_mesh.f, lmk_face_idx_dynamic, lmk_b_coords_dynamic)
    static_lmks = mesh_points_by_barycentric_coordinates(template_mesh.v, template_mesh.f, lmk_face_idx_static, lmk_b_coords_static)
    total_lmks = np.vstack([dynamic_lmks, static_lmks])

    # Visualization of the pose dependent contour on the template mesh
    vertex_colors = np.ones([template_mesh.v.shape[0], 4]) * [0.3, 0.3, 0.3, 0.8]
    tri_mesh = trimesh.Trimesh(template_mesh.v, template_mesh.f,
                               vertex_colors=vertex_colors)
    mesh = pyrender.Mesh.from_trimesh(tri_mesh)
    scene = pyrender.Scene()
    scene.add(mesh)
    sm = trimesh.creation.uv_sphere(radius=0.005)
    sm.visual.vertex_colors = [0.9, 0.1, 0.1, 1.0]
    tfs = np.tile(np.eye(4), (len(total_lmks), 1, 1))
    tfs[:, :3, 3] = total_lmks
    joints_pcl = pyrender.Mesh.from_trimesh(sm, poses=tfs)
    scene.add(joints_pcl)
    pyrender.Viewer(scene, use_raymond_lighting=True) 
开发者ID:soubhiksanyal,项目名称:RingNet,代码行数:27,代码来源:dynamic_contour_embedding.py


示例16: load_checkpoint

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import load [as 别名]
def load_checkpoint(self, filename="vs_ckpt", keys=None, num_extra_vars=0, skip_saved_unsavables=False):
        if skip_saved_unsavables:
            keys = self.vars
        else:
            if not keys:
                keys = self.savable_vars
        save_file = open(filename)
        for key in keys:
            if skip_saved_unsavables and key not in self.savable_vars:
                if self.logger:
                    full_name = "%s/%s" % (self.prefix, key)
                    self.logger.Log(
                        "Not restoring variable " + full_name, level=self.logger.DEBUG)
                _ = cPickle.load(save_file) # Discard
            else:
                if self.logger:
                    full_name = "%s/%s" % (self.prefix, key)
                    self.logger.Log(
                        "Restoring variable " + full_name, level=self.logger.DEBUG)
            self.vars[key].set_value(cPickle.load(save_file), borrow=True)

        extra_vars = []
        for _ in range(num_extra_vars):
            extra_vars.append(cPickle.load(save_file))
        return extra_vars 
开发者ID:stanfordnlp,项目名称:spinn,代码行数:27,代码来源:variable_store.py


示例17: show_cfg

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import load [as 别名]
def show_cfg(resource_url, escape='##'):
    """
    Write out a grammar file, ignoring escaped and empty lines.

    :type resource_url: str
    :param resource_url: A URL specifying where the resource should be
        loaded from.  The default protocol is "nltk:", which searches
        for the file in the the NLTK data package.
    :type escape: str
    :param escape: Prepended string that signals lines to be ignored
    """
    resource_url = normalize_resource_url(resource_url)
    resource_val = load(resource_url, format='text', cache=False)
    lines = resource_val.splitlines()
    for l in lines:
        if l.startswith(escape):
            continue
        if re.match('^$', l):
            continue
        print(l) 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:22,代码来源:data.py


示例18: load_from_filepath

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import load [as 别名]
def load_from_filepath(fp):
        #return json.loads(open(, "r").read())
        with open(fp, "r") as f:
            history = pickle.load(f)
        return history 
开发者ID:aleju,项目名称:cat-bbs,代码行数:7,代码来源:plotting.py


示例19: reload_mappings

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import load [as 别名]
def reload_mappings(self):
#{{{
        """
        Load mappings from disk.
        """
        with open(self.mappings_path, 'rb') as f:
            mappings = cPickle.load(f)
        self.id_to_word = mappings['id_to_word']
        self.id_to_char = mappings['id_to_char']
        self.id_to_tag = mappings['id_to_tag']
#}}} 
开发者ID:lingluodlut,项目名称:Att-ChemdNER,代码行数:13,代码来源:model.py


示例20: load

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import load [as 别名]
def load(cls, file_obj):
        """Load serialized object from open JSON file.

        .. versionadded:: 1.8

        :param file_obj: file handle
        :type file_obj: ``file`` object
        :returns: object loaded from JSON file
        :rtype: object

        """
        return json.load(file_obj) 
开发者ID:TKkk-iOSer,项目名称:wechat-alfred-workflow,代码行数:14,代码来源:workflow.py


示例21: _load

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import load [as 别名]
def _load(self):
        """Load cached settings from JSON file `self._filepath`."""
        data = {}
        with LockFile(self._filepath, 0.5):
            with open(self._filepath, 'rb') as fp:
                data.update(json.load(fp))

        self._original = deepcopy(data)

        self._nosave = True
        self.update(data)
        self._nosave = False 
开发者ID:TKkk-iOSer,项目名称:wechat-alfred-workflow,代码行数:14,代码来源:workflow.py


示例22: cached_data

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import load [as 别名]
def cached_data(self, name, data_func=None, max_age=60):
        """Return cached data if younger than ``max_age`` seconds.

        Retrieve data from cache or re-generate and re-cache data if
        stale/non-existant. If ``max_age`` is 0, return cached data no
        matter how old.

        :param name: name of datastore
        :param data_func: function to (re-)generate data.
        :type data_func: ``callable``
        :param max_age: maximum age of cached data in seconds
        :type max_age: ``int``
        :returns: cached data, return value of ``data_func`` or ``None``
            if ``data_func`` is not set

        """
        serializer = manager.serializer(self.cache_serializer)

        cache_path = self.cachefile('%s.%s' % (name, self.cache_serializer))
        age = self.cached_data_age(name)

        if (age < max_age or max_age == 0) and os.path.exists(cache_path):

            with open(cache_path, 'rb') as file_obj:
                self.logger.debug('loading cached data: %s', cache_path)
                return serializer.load(file_obj)

        if not data_func:
            return None

        data = data_func()
        self.cache_data(name, data)

        return data 
开发者ID:TKkk-iOSer,项目名称:wechat-alfred-workflow,代码行数:36,代码来源:workflow.py


示例23: initialize

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import load [as 别名]
def initialize(self):
    # Initial file lists are empty
    np_paths = []
    ss_paths = []
    # Fresh train directly from ImageNet weights
    print('Loading initial model weights from {:s}'.format(self.pretrained_model))
    self.net.load_pretrained_cnn(torch.load(self.pretrained_model))
    print('Loaded.')
    
#    pretrained_model = torch.load('/DATA3_DB7/data/jjwang/workspace/two_stage/output/vgg16/voc_2007_trainval/default/vgg16_faster_rcnn_iter_50001.pth')    
    if self.wsddn_premodel is not None: # Load the pretrained WSDDN model
      wsddn_pre = torch.load(self.wsddn_premodel)
      model_dict = self.net.state_dict()
      model_dict.update(wsddn_pre)
      self.net.load_state_dict(model_dict)
      print('Loading pretrained WSDDN model weights from {:s}'.format(self.wsddn_premodel))
      print('Loaded.')
    
    
    # Need to fix the variables before loading, so that the RGB weights are changed to BGR
    # For VGG16 it also changes the convolutional weights fc6 and fc7 to
    # fully connected weights
    last_snapshot_iter = 0
    lr = cfg.TRAIN.LEARNING_RATE
    stepsizes = list(cfg.TRAIN.STEPSIZE)

    return lr, last_snapshot_iter, stepsizes, np_paths, ss_paths 
开发者ID:Sunarker,项目名称:Collaborative-Learning-for-Weakly-Supervised-Object-Detection,代码行数:29,代码来源:train_val.py


示例24: load_model

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import load [as 别名]
def load_model(self, model_dir):
        mappings_path = os.path.join(model_dir, 'mappings.pkl')
        parameters_path = os.path.join(model_dir, 'parameters.pkl')
        item2id, id2item, tag2id, id2tag, word2id, id2word = \
            pickle.load(open(mappings_path, 'r'))
        parameters = pickle.load(open(parameters_path))

        self.item2id = item2id
        self.id2item = id2item
        self.tag2id = tag2id
        self.id2tag = id2tag
        self.word2id = word2id
        self.id2word = id2word
        self.parameters = parameters

        print(parameters)
        print('Building input graph...', end='')
        self.build_graph()
        print('Finished.')
        print('Initializing variables...', end='')
        init_op = tf.initialize_all_variables()
        self.sess.run(init_op)
        print('Finished.')
        print('Reloading parameters...', end='')
        saver = tf.train.Saver(tf.global_variables())
        checkpoint = tf.train.latest_checkpoint(model_dir)
        saver.restore(self.sess, checkpoint)
        print('Finished.') 
开发者ID:chqiwang,项目名称:convseg,代码行数:30,代码来源:tagger.py


示例25: unpickle

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import load [as 别名]
def unpickle(file):
    fo = open(file, 'rb')
    dict = pkl.load(fo)
    fo.close()
    return dict 
开发者ID:StephanZheng,项目名称:neural-fingerprinting,代码行数:7,代码来源:utils_cifar.py



注:本文中的cPickle.load方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。