Python basic syntax-pickle save and load dictionaries

Python basic syntax-pickle save and load dictionaries

pickle save and load dictionaries

import pickle as pkl

d = {
    
    
    'conv_channels': [6, 16],
    'conv_kernel_size': [3, 3],
    'pool_kernel_size': 2,
    'pool_stride': 2,
    'fc_features': [120, 84],
}

# save
with open('best.pkl', 'wb') as f:
    pkl.dump(d, f, pkl.HIGHEST_PROTOCOL)

# load
with open('best.pkl', 'rb') as f:
    red = pkl.load(f)

print(d)
print(red)

Insert picture description here

Reference article

pickle save and load dictionaries

Guess you like

Origin blog.csdn.net/qq_44783177/article/details/114206875