python 常规class类写法及应用

# 载入训练好的模型
import re
import time

import jieba
import jieba.analyse
import jieba.posseg as pseg
import torch
from transformers import BertTokenizer, BertForSequenceClassification, AutoConfig

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")  # 调用GPU


"""
your model
"""
class YourModel(object):
    def __init__(self,model_path=your_model_path): #此项为初始化项,可有可没有
        self.model_path= model_path
        print("init model")
        self.model=self.init_model()
        print("init model done")
    def init_model(self):
		'''your code, allow return'''

if __name__ == "__main__": #主函数
        model=YourModel()
        starttime = time.time()
        res=model.init_model()
        print(res)
        endtime = time.time()
        print ("times:"+str((endtime - starttime)))

你可能感兴趣的:(python实战,计算机基础知识,开发语言,后端)