Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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()
Comment

PREVIOUS NEXT
Code Example
Python :: how to draw threshold line in bar graph python 
Python :: pd df replace 
Python :: python loop nest shorthand 
Python :: sqlalchemy create engine Oracle 
Python :: how to use ActionChains selenium python with WebDriverWait 
Python :: how to customize simplejwt error response message in django restframework 
Python :: how to get maximum value of number in python 
Python :: how to slice a set in python 
Python :: query set 
Python :: plotly ylog 
Python :: #Check if list1 contains all elements of list2 using all() 
Python :: pil saves blue images 
Python :: pymongo dynamic structure 
Python :: flask tutorial 
Python :: pandas array of dataframes 
Python :: pandas sequential numbering within group 
Python :: get the first element that is larger than 
Python :: python boucle for 
Python :: how to encrypt and decrypt strings python 
Python :: pyqt popup yes no 
Python :: printing coloured and bold text in python 
Python :: round to the nearest 0.5 
Python :: stripping whitespace in python 
Python :: print(f ) python 
Python :: noob python 
Python :: python remove table widget numbers 
Python :: remove items from list while iterating python 
Python :: django table view sort filter 
Python :: from future import division 
Python :: 2 functions at a time py 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =