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


Python pickle.Unpickler方法代碼示例

本文整理匯總了Python中pickle.Unpickler方法的典型用法代碼示例。如果您正苦於以下問題:Python pickle.Unpickler方法的具體用法?Python pickle.Unpickler怎麽用?Python pickle.Unpickler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pickle的用法示例。


在下文中一共展示了pickle.Unpickler方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: inflate

# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import Unpickler [as 別名]
def inflate(opt = None):
	if opt is not None:
		model3d = HourglassNet3D(opt.nChannels, opt.nStack, opt.nModules, opt.numReductions, ref.nJoints)
		Inflate.nChannels = opt.nChannels
		Inflate.nStack = opt.nStack
		Inflate.nModules = opt.nModules
		Inflate.nRegFrames = opt.nRegFrames
		Inflate.nJoints = ref.nJoints
	else :
		model3d = HourglassNet3D()
	pickle.Unpickler = partial(pickle.Unpickler, encoding="latin1")
	pickle.load = partial(pickle.load, encoding="latin1")
	if opt is not None:
		model = torch.load(opt.Model2D)
	else:
		model = torch.load('models/hgreg-3d.pth') #, map_location=lambda storage, loc: storage)

	Inflate.inflateHourglassNet(model3d, model)

	torch.save(model3d,open('inflatedModel.pth','wb'))

	return model3d 
開發者ID:Naman-ntc,項目名稱:3D-HourGlass-Network,代碼行數:24,代碼來源:inflateScript.py

示例2: meta_validate

# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import Unpickler [as 別名]
def meta_validate(shacl_graph, inference='rdfs', **kwargs):
    shacl_shacl_graph = meta_validate.shacl_shacl_graph
    if shacl_shacl_graph is None:
        from os import path
        import pickle
        import sys
        if getattr( sys, 'frozen', False ) :
                # runs in a pyinstaller bundle
                here_dir = sys._MEIPASS
                pickle_file = path.join(here_dir, "shacl-shacl.pickle")
        else :
                here_dir = path.dirname(__file__)
                pickle_file = path.join(here_dir, "shacl-shacl.pickle")
        with open(pickle_file, 'rb') as shacl_pickle:
            u = pickle.Unpickler(shacl_pickle, fix_imports=False)
            shacl_shacl_store = u.load()
        shacl_shacl_graph = rdflib.Graph(store=shacl_shacl_store, identifier="http://www.w3.org/ns/shacl-shacl")
        meta_validate.shacl_shacl_graph = shacl_shacl_graph
    shacl_graph = load_from_source(shacl_graph, rdf_format=kwargs.pop('shacl_graph_format', None),
                                   multigraph=True)
    _ = kwargs.pop('meta_shacl', None)
    return validate(shacl_graph, shacl_graph=shacl_shacl_graph, inference=inference, **kwargs) 
開發者ID:RDFLib,項目名稱:pySHACL,代碼行數:24,代碼來源:validate.py

示例3: load

# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import Unpickler [as 別名]
def load(f, persistent_load=PersistentNdarrayLoad):
    """Load a file that was dumped to a zip file.

    :param f: The file handle to the zip file to load the object from.
    :type f: file

    :param persistent_load: The persistent loading function to use for
        unpickling. This must be compatible with the `persisten_id` function
        used when pickling.
    :type persistent_load: callable, optional

    .. versionadded:: 0.8
    """
    with closing(zipfile.ZipFile(f, 'r')) as zip_file:
        p = pickle.Unpickler(BytesIO(zip_file.open('pkl').read()))
        p.persistent_load = persistent_load(zip_file)
        return p.load() 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:19,代碼來源:pkl_utils.py

示例4: __init__

# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import Unpickler [as 別名]
def __init__(self, file: BinaryIO, stop: int=-1, start: int =0, ids: Iterable = None):
        """

        :param file:
        :param start: unpickle objects starting from index start
        :param stop: unpickle objects ending with index stop
        :param ids: unpickle objects with indexes in ids
        """
        if ids is None:
            ids = []
        self.file = file
        self.p = pickle.Unpickler(file)
        self.c = 0
        self.stop = stop
        self.start = start
        self.ids = set(ids) 
開發者ID:kwrobel-nlp,項目名稱:krnnt,代碼行數:18,代碼來源:serial_pickle.py

示例5: getClient

# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import Unpickler [as 別名]
def getClient(
        cls, servers, debug=0, pickleProtocol=0,
        pickler=pickle.Pickler, unpickler=pickle.Unpickler,
        pload=None, pid=None
    ):

        if cls.allowTestCache:
            return TestClient(
                servers, debug=debug,
                pickleProtocol=pickleProtocol, pickler=pickler,
                unpickler=unpickler, pload=pload, pid=pid)
        elif config.Memcached.Pools.Default.ClientEnabled:
            return Client(
                servers, debug=debug, pickleProtocol=pickleProtocol,
                pickler=pickler, unpickler=unpickler, pload=pload, pid=pid)
        else:
            return None 
開發者ID:apple,項目名稱:ccs-calendarserver,代碼行數:19,代碼來源:memcacheclient.py

示例6: loads

# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import Unpickler [as 別名]
def loads(data, from_module=None):
    up = pickle.Unpickler(StringIO(data))
    def find_global(module, cls):
        if module == "copy_reg" and cls == "_reconstructor":
            return copy_reg._reconstructor
        if module == "__builtin__":
            return getattr(__builtins__, cls)
        if from_module is not None:
            return getattr(from_module, cls)
        return globals()[cls]
    up.find_global = find_global
    return up.load() 
開發者ID:blackberry,項目名稱:ALF,代碼行數:14,代碼來源:_qemu.py

示例7: inflate

# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import Unpickler [as 別名]
def inflate(opt = None):
	if opt is not None:
		model3d = Pose3D(opt.nChannels, opt.nStack, opt.nModules, opt.numReductions, opt.nRegModules, opt.nRegFrames, ref.nJoints, ref.temporal)
		Inflate.nChannels = opt.nChannels
		Inflate.nStack = opt.nStack
		Inflate.nModules = opt.nModules
		Inflate.nRegFrames = opt.nRegFrames
		Inflate.nJoints = ref.nJoints
		Inflate.scheme = opt.scheme
		Inflate.mult = opt.mult
	else :
		opt = opts().parse()
		Inflate.nChannels = opt.nChannels
		Inflate.nStack = opt.nStack
		Inflate.nModules = opt.nModules
		Inflate.nRegFrames = opt.nRegFrames
		Inflate.nJoints = ref.nJoints
		Inflate.scheme = opt.scheme
		model3d = Pose3D(opt.nChannels, opt.nStack, opt.nModules, opt.numReductions, opt.nRegModules, opt.nRegFrames, ref.nJoints, ref.temporal)
	pickle.Unpickler = partial(pickle.Unpickler, encoding="latin1")
	pickle.load = partial(pickle.load, encoding="latin1")
	if opt is not None:
		model = torch.load(opt.Model2D)
	else:
		model = torch.load('models/xingy.pth') #, map_location=lambda storage, loc: storage)

	Inflate.inflatePose3D(model3d, model)

	torch.save(model3d,open('inflatedModel.pth','wb'))

	return model3d


#inflate() 
開發者ID:Naman-ntc,項目名稱:3D-HourGlass-Network,代碼行數:36,代碼來源:inflateScript.py

示例8: find_class

# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import Unpickler [as 別名]
def find_class(self, module, name):
            # override superclass
            key = (module, name)
            module, name = _class_locations_map.get(key, key)
            return super(Unpickler, self).find_class(module, name) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:7,代碼來源:pickle_compat.py

示例9: load

# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import Unpickler [as 別名]
def load(fh, encoding=None, compat=False, is_verbose=False):
    """load a pickle, with a provided encoding

    if compat is True:
       fake the old class hierarchy
       if it works, then return the new type objects

    Parameters
    ----------
    fh : a filelike object
    encoding : an optional encoding
    compat : provide Series compatibility mode, boolean, default False
    is_verbose : show exception output
    """

    try:
        fh.seek(0)
        if encoding is not None:
            up = Unpickler(fh, encoding=encoding)
        else:
            up = Unpickler(fh)
        up.is_verbose = is_verbose

        return up.load()
    except (ValueError, TypeError):
        raise 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:28,代碼來源:pickle_compat.py

示例10: RMUserData_convertFromSQLite

# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import Unpickler [as 別名]
def RMUserData_convertFromSQLite(data):
    if data == None:
        return None

    inputStream = StringIO(data)
    unpickler = pickle.Unpickler(inputStream)
    return unpickler.load() 
開發者ID:sprinkler,項目名稱:rainmachine-developer-resources,代碼行數:9,代碼來源:rmParserUserData.py

示例11: RMParserParams_convertFromSQLite

# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import Unpickler [as 別名]
def RMParserParams_convertFromSQLite(data):
    if data == None:
        return None

    inputStream = StringIO(data)
    unpickler = pickle.Unpickler(inputStream)
    return unpickler.load() 
開發者ID:sprinkler,項目名稱:rainmachine-developer-resources,代碼行數:9,代碼來源:rmParserParams.py

示例12: SafeUnpickler

# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import Unpickler [as 別名]
def SafeUnpickler(data):
    """An unpickler for serialized tuple/lists/strings etc.

    Does not support recovering instances.
    """
    unpickler = pickle.Unpickler(io.StringIO(data))
    unpickler.find_global = None

    return unpickler.load() 
開發者ID:google,項目名稱:rekall,代碼行數:11,代碼來源:utils.py

示例13: RestrictedPickler

# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import Unpickler [as 別名]
def RestrictedPickler(raw):
    if six.PY3:
        return RestrictedUnpickler(io.BytesIO(utils.SmartStr(raw)))

    unpickler = pickle.Unpickler(io.BytesIO(utils.SmartStr(raw)))
    unpickler.find_global = None
    return unpickler 
開發者ID:google,項目名稱:rekall,代碼行數:9,代碼來源:cache.py

示例14: __getitem__

# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import Unpickler [as 別名]
def __getitem__(self, key):
        try:
            value = self.cache[key]
        except KeyError:
            f = StringIO(self.dict[key])
            value = Unpickler(f).load()
            if self.writeback:
                self.cache[key] = value
        return value 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:11,代碼來源:shelve.py

示例15: set_location

# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import Unpickler [as 別名]
def set_location(self, key):
        (key, value) = self.dict.set_location(key)
        f = StringIO(value)
        return (key, Unpickler(f).load()) 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:6,代碼來源:shelve.py


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