pytorch中.pth文件转成.bin的二进制文件


                model_dict = torch.load(save_path)
                fp = open('model_parameter.bin', 'wb')
                weight_count = 0
                num=1
                for k, v in model_dict.items():
                    print(k,num)
                    num=num+1
                    if 'num_batches_tracked' in k:
                        continue
                    v = v.cpu().numpy().flatten()
                    for d in v:
                        fp.write(d)
                        weight_count+=1
                print('model_weight has Convert Completely!',weight_count)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM