.pth文件怎么轉換為.ckpt文件


import tensorflow.compat.v1 as tf
import torch

def convert(bin_path, ckptpath):
    with  tf.Session() as sess:
        for var_name, value in torch.load(bin_path, map_location='cpu').items():
            print(var_name)  # 輸出權重文件中的變量名
            tf.Variable(initial_value=value, name=var_name)
        saver = tf.train.Saver()
        sess.run(tf.global_variables_initializer())
        saver.save(sess, ckpt_path)

bin_path = '/content//attn/DAMSMencoders/bird/t200.pth'
ckpt_path = '/content/attn/models/new_model.ckpt'
convert(bin_path, ckpt_path)
 
 
原文鏈接:https://segmentfault.com/a/1190000040566987


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM