(state_dict, prefix)
return {f(key): value for key, value in state_dict.items()}
Old style model is stored with all names of parameters sharing common prefix 'module.'
Old style model is stored with all names of parameters sharing common prefix 'module.'
Old style model is stored with all names of parameters sharing common prefix module .
def remove_prefix(state_dict, prefix):
    ''' Old style model is stored with all names of parameters sharing common prefix 'module.' '''
    # print('remove prefix \'{}\''.format(prefix))
    f = lambda x: x.split(prefix, 1)[-1] if x.startswith(prefix) else x
    return {f(key): value for key, value in state_dict.items()}
def remove_prefix ( state_dict , prefix ) : # print('remove prefix \'{}\''.format(prefix)) f = lambda x : x . split ( prefix , 1 ) [ - 1 ] if x . startswith ( prefix ) else x return { f ( key ) : value for key , value in state_dict . items ( ) }