python读写pkl文件

1、读取pkl文件

  方法1: 使用pickle文件

import pickle
plan = pickle.load(open("./nnUNetPlansv2.1_plans_3D.pkl"))

  如果加载中出现报错:  

   UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte

  需要修改为:

import pickle
plan = pickle.load(open("./nnUNetPlansv2.1_plans_3D.pkl", "rb"))

 方法2:使用 from batchgenerators.utilities.file_and_folder_operations import *

from batchgenerators.utilities.file_and_folder_operations import *

plans_files = "./nnUNetPlansv2.1_plans_3D.pkl"
plan = load_pickle(plans_file)

 

2、读取key值

plan.keys()

 

3、修改并保存

# 如我们要修改bs,找到bs对应的key值
plan["plans_per_stage"][0]["batch_size"]=4
pickle.dump(plan, open("./nnUNetPlansv2.1_plans_3D_new.pkl", "wb"))  # 此处wb对应读时候的rb

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值