tensor flow 模型保存与加载

保存:

def save(self,time):
        current_path = os.path.dirname(os.path.abspath(__file__))
        model_path='model/***_model_'+time+'_'+self.name+'/weights_'+self.name
        save_path = os.path.join(current_path,model_path)
        if not os.path.exists(save_path):os.makedirs(save_path)
        self.saver.save(self.sess,save_path)

生成文件

tensor flow 模型保存与加载_第1张图片

checkpoint 正确路径:

加载:

    def load(self,model_path):

        check_path= os.path.join(model_path, 'weights_intersection_1_1')

        meta_path = 'weights_'+self.name+'.meta'

        mata_path_dir = os.path.join(model_path,meta_path)

        self.saver = tf.compat.v1.train.import_meta_graph(mata_path_dir)
        
        a=model_path+'/'
        
        self.saver.restore(self.sess, tf.train.latest_checkpoint(a))

你可能感兴趣的:(代码,python,前端,开发语言)