Team Ai
Apppublic

Arulkumar03/Wheat_HEAD_Detection_Counting_ComputerVision_Model

sourceHugging Facemitupdated 3y agoView on Hugging Face
0likes
serialize.py33 linesDownload Raw Back to utils
1# Copyright (c) Facebook, Inc. and its affiliates.2import cloudpickle3 4 5class PicklableWrapper(object):6    """7    Wrap an object to make it more picklable, note that it uses8    heavy weight serialization libraries that are slower than pickle.9    It's best to use it only on closures (which are usually not picklable).10 11    This is a simplified version of12    https://github.com/joblib/joblib/blob/master/joblib/externals/loky/cloudpickle_wrapper.py13    """14 15    def __init__(self, obj):16        while isinstance(obj, PicklableWrapper):17            # Wrapping an object twice is no-op18            obj = obj._obj19        self._obj = obj20 21    def __reduce__(self):22        s = cloudpickle.dumps(self._obj)23        return cloudpickle.loads, (s,)24 25    def __call__(self, *args, **kwargs):26        return self._obj(*args, **kwargs)27 28    def __getattr__(self, attr):29        # Ensure that the wrapped object can be used seamlessly as the previous object.30        if attr not in ["_obj"]:31            return getattr(self._obj, attr)32        return getattr(self, attr)33