一个新的计算机视觉图书馆
pytorch-fanatics的Python项目详细描述
皮托奇狂热分子
Pythorch iu Fanatics是一个便于计算机视觉的Python库任务。这个包含一堆不同的工具,将有助于创建自定义代码来训练CV模型。在
此库包括:
- 数据集类
- 激光测距仪
- 早起
- 培训师
- 记录器
安装
使用包管理器pip安装Pythorch\u狂热者。在
pip install pytorch_fanatics
使用
1)数据集类
^{pr2}$2)测距仪
frompytorch_fanatics.utilsimportLRFinderlr_finder=LRFinder(model,train_dataloader,optimizer,device,initial_lr,final_lr,beta)#Create a objectlr_finder.find()#To find the lrlr_finder.plot()#To plot the graph (Loss V/S lr)#NOTE:#Use this only after training the model with all layers (except the last) freezed.
3)早顶
frompytorch_fanatics.utilsimportEarlyStopes=EarlyStop(patience=7,mode="max",delta=0.0001)#Create a objectes(epoch_score,model,path)ifes.early_stop=True:breakes.reset()# to reset
4)培训师
frompytorch_fanatics.trainerimportTrainerTrainer.train(model,data_loader,optimizer,device)# trains the modelscore=Trainer.evaluate(model,data_loader,device,scheduler=None,metric=metrics.accuracy_score,plot=True)#Use the score to feed for earlystop if used#plot=True specifies live plot b/w (training and validation) vs num_epochsTrainer.predict(model,data_loader,device)# returns probability of classesTrainer.get_log()#returns a DataFrame object of logs #Currently the metrics supported are f1_score,accuracy,precision,recall,roc_auc_score and log_loss#We are working on other too ..
5)记录器
frompytorch_fanatics.loggerimportLoggerLogger.save(model,optimizer,scheduler,path)# saves model,optimizer and schedulers#To load:checkpoint=Logger.load(path)#returns a dictionarymodel,optimizer,scheduler=checkpoint['model'],checkpoint['optimizer'],checkpoint['scheduler']#Helps keep track of training.It will restart from where it had stopped.
NOTE(关于型号)
classResnet18(nn.Module):def__init__(self):super(Resnet18,self).__init__()self.base_model=timm.create_model('resnet18',pretrained=True,num_classes=1)defforward(self,image,targets):batch_size,_,_,_=image.shapeout=self.base_model(image)loss=nn.BCEWithLogitsLoss()(out.view(batch_size,),targets.type_as(out))returnout,loss#Since every loss function has its own format of inputs,To generalise I have created this model.Use this model(edit if required) if you are #using Trainer/LRFinder.For others your simple model will also work fine..
贡献
欢迎拉取请求。对于重大变化,请先打开一个问题,讨论您希望更改的内容。在
请确保根据需要更新测试。在
许可证
参考文献
- LRFinder的FastAi文档。在
- Pythorch文件。在
- 阿披实克塔库先生的Github项目wtfml(很棒的工作也可以看看)。在
- 项目
标签: