Horje
pickle.load from gpu device to cpu Code Example
pickle.load from gpu device to cpu
#if you are using pickle load on a cpu device, from a gpu device
#you will need to override the pickle load functionality like this:
#note: if loading directly in torch, just add map_location='cpu' in load()

class CPU_Unpickler(pickle.Unpickler):
    def find_class(self, module, name):
        if module == 'torch.storage' and name == '_load_from_bytes':
            return lambda b: torch.load(io.BytesIO(b), map_location='cpu')
        else: return super().find_class(module, name)

#contents = pickle.load(f) becomes...
contents = CPU_Unpickler(f).load()
Source: github.com




Python

Related
install open3d jetson nano aarch64 Code Example install open3d jetson nano aarch64 Code Example
‘A’, ‘Q’, ‘BM’, ‘BA’, ‘BQ’ meaning in resample Code Example ‘A’, ‘Q’, ‘BM’, ‘BA’, ‘BQ’ meaning in resample Code Example
python permission denied on mac Code Example python permission denied on mac Code Example
python function __name__ Code Example python function __name__ Code Example
maximum number of charectors allowed for a string variable in python Code Example maximum number of charectors allowed for a string variable in python Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8