作用:
对于大型计算,比如很复杂的申请网络,可以用dump保存中间过程,比如流程图。
代码:
import cv2
import pickle
image = cv2.imread("bb1.png")
# 将中间过程保存入磁盘
with open("pickled_list", "wb") as file:
pickle.dump(image, file)
# 从磁盘读入保存的对象
with open("pickled_list", "rb") as file:
new_image = pickle.load(file)
# 判定两个对象是否相等
assert new_image.all() == image.all()
# 对象内容相同,但其实是两个不同的对象
print(id(new_image)) # 37600336
print(id(image)) # 37600216
cv2.imshow("new_image", new_image)
cv2.waitKey()
cv2.destroyAllWindows()