Package: opennn-pytorch
Open Neural Networks library for image classification.Table of contentQuick startWarningsEncodersDecodersPretrainedPretrained old configs fixesDatasetsLossesMetricsOptimizersSchedulersExamplesWandbQuick start1. Straight install.1.1 Install torch with cuda.pipinstall-Utorch--extra-index-urlhttps://download.pytorch.org/whl/cu1131.2 Install opennn_pytorch.pipinstall-Uopennn_pytorch2. Dockerfile.cddocker/
dockerbuild-topennn:latest.WarningsCuda is only supported for nvidia graphics cards.Alexnet decoder doesn't support bce losses family.Sometimes combination of dataset/encoder/decoder/loss will give bad results, try to combine others.Custom cross-entropy support only mode when preds have (n, c) shape and labels have (n) shape.Not all options in transform.yaml and config.yaml are required.Mean and std in datasets section must be used in transform.yaml, for example [mean=[0.2859], std=[0.3530]] -> normalize: [[0.2859], [0.3530]]EncodersLeNet [paper] [code]AlexNet [paper] [code]GoogleNet [paper] [code]ResNet18 [paper] [code]ResNet34 [paper] [code]ResNet50 [paper] [code]ResNet101 [paper] [code]ResNet152 [paper] [code]MobileNet [paper] [code]VGG-11 [paper] [code]VGG-16 [paper] [code]VGG-19 [paper] [code]DecodersLeNet [paper] [code]AlexNet [paper] [code]Linear [docs] [code]PretrainedLeNetEncoderDecoderDatasetWeightsConfigsLogsLeNetLeNetMNISTBEST,PLANCONFIG,TRANSFORMTRAINVALLeNetLeNetFASHION-MNISTBEST,PLANCONFIG,TRANSFORMTRAINVALLeNetLinearMNISTBEST,PLANCONFIG,TRANSFORMTRAINVALLeNetLinearFASHION-MNISTBEST,PLANCONFIG,TRANSFORMTRAINVALLeNetAlexNetMNISTBEST,PLANCONFIG,TRANSFORMTRAINVALLeNetAlexNetFASHION-MNISTBEST,PLANCONFIG,TRANSFORMTRAINVALAlexNetEncoderDecoderDatasetWeightsConfigsLogsAlexNetLeNetMNISTBEST,PLANCONFIG,TRANSFORMTRAINVALAlexNetLeNetFASHION-MNISTBEST,PLANCONFIG,TRANSFORMTRAINVALAlexNetLinearMNISTBEST,PLANCONFIG,TRANSFORMTRAINVALAlexNetLinearFASHION-MNISTBEST,PLANCONFIG,TRANSFORMTRAINVALAlexNetAlexNetMNISTBEST,PLANCONFIG,TRANSFORMTRAINVALAlexNetAlexNetFASHION-MNISTBEST,PLANCONFIG,TRANSFORMTRAINVALGoogleNetEncoderDecoderDatasetWeightsConfigsLogsGoogleNetLinearMNISTBEST,PLANCONFIG,TRANSFORMTRAINVALGoogleNetLinearFASHION-MNISTBEST,PLANCONFIG,TRANSFORMTRAINVALResNetEncoderDecoderDatasetWeightsConfigsLogsResNet18LinearMNISTBEST,PLANCONFIG,TRANSFORMTRAINVALResNet34LinearMNISTBEST,PLANCONFIG,TRANSFORMTRAINVALResNet50LinearMNISTBEST,PLANCONFIG,TRANSFORMTRAINVALResNet101LinearMNISTBEST,PLANCONFIG,TRANSFORMTRAINVALResNet152LinearMNISTBEST,PLANCONFIG,TRANSFORMTRAINVALMobileNetEncoderDecoderDatasetWeightsConfigsLogsMobileNetLinearMNISTBEST,PLANCONFIG,TRANSFORMTRAINVALVGGEncoderDecoderDatasetWeightsConfigsLogsVGG-11LinearMNISTBEST,PLANCONFIG,TRANSFORMTRAINVALVGG-16LinearMNISTBEST,PLANCONFIG,TRANSFORMTRAINVALVGG-19LinearMNISTBEST,PLANCONFIG,TRANSFORMTRAINVALPretrained configs issuesConfig file changed, check configs folder!!!Config must include test_part value, (train_part + valid_part + test_part) value can be < 1.0.You will able to add wandb structure for logging in wandb.Full restructure into branches structure.DatasetsMNIST [files] [code] [classes=10] [mean=[0.1307], std=[0.3801]]FASHION-MNIST [files] [code] [classes=10] [mean=[0.2859], std=[0.3530]]CIFAR-10 [files] [code] [classes=10] [mean=[0.491, 0.482, 0.446], std=[0.247, 0.243, 0.261]]CIFAR-100 [files] [code] [classes=100] [mean=[0.5071, 0.4867, 0.4408], std=[0.2675, 0.2565, 0.2761]]GTSRB [files] [code] [classes=43] [mean=unknown, std=unknown]CUSTOM [docs] [code] [example] [classes=nc] [mean=unknown, std=unknown]LossesCross-Entropy [pytorch,custom] [docs] [code]Binary-Cross-Entropy [pytorch,custom] [docs] [code]Binary-Cross-Entropy-With-Logits [pytorch,custom] [docs] [code]Mean-Squared-Error [pytorch,custom] [docs] [code]Mean-Absolute-Error [pytorch,custom] [docs] [code]MetricsAccuracy [sklearn] [docs] [code]Precision [sklearn] [docs] [code]Recall [sklearn] [docs] [code]F1 [sklearn] [docs] [code]OptimizersAdam [pytorch] [docs] [code]AdamW [pytorch] [docs] [code]Adamax [pytorch] [docs] [code]RAdam [pytorch] [docs] [code]NAdam [pytorch] [docs] [code]SchedulersStepLR [pytorch] [docs] [code]MultiStepLR [pytorch] [docs] [code]PolynomialLRDecay [custom] [docs] [code]ExamplesRun from yaml config.fromopennn_pytorchimportrunconfig='path to yaml config'# check configs folderrun(config)Get encoder and decoder.fromopennn_pytorch.encodersimportget_encoderfromopennn_pytorch.decodersimportget_decoderencoder_name='resnet18'decoder_name='alexnet'decoder_mode='decoder'input_channels=1number_classes=10device='cuda'encoder=get_encoder(encoder_name,input_channels).to(device)model=get_decoder(decoder_name,encoder,number_classes,decoder_mode,device).to(device)3.1 Get dataset.fromopennn_pytorch.datasetsimportget_datasetfromtorchvisionimporttransformstransform_config='path to transform yaml config'dataset_name='mnist'datafiles=Nonetrain_part=0.7valid_part=0.2test_part=0.05transform_lst=opennn_pytorch.transforms_lst(transform_config)transform=transforms.Compose(transform_lst)train_data,valid_data,test_data=get_dataset(dataset_name,train_part,valid_part,test_part,transform,datafiles)3.2 Get custom dataset.fromopennn_pytorch.datasetsimportget_datasetfromtorchvisionimporttransformstransform_config='path to transform yaml config'dataset_name='custom'images='path to folder with images'annotation='path to annotation yaml file with image: class structure'datafiles=(images,annotation)train_part=0.7valid_part=0.2test_part=0.05transform_lst=opennn_pytorch.transforms_lst(transform_config)transform=transforms.Compose(transform_lst)train_data,valid_data,test_data=get_dataset(dataset_name,train_part,valid_part,test_part,transform,datafiles)Get optimizer.fromopennn_pytorch.optimizersimportget_optimizeroptim_name='adam'lr=1e-3betas=(0.9,0.999)eps=1e-8weight_decay=1e-6optimizer=get_optimizer(optim_name,model,lr=lr,betas=betas,eps=opt_eps,weight_decay=weight_decay)Get scheduler.fromopennn_pytorch.schedulersimportget_schedulerscheduler_name='steplr'step=10gamma=0.5milestones=Nonemax_decay_steps=Noneend_lr=Nonepower=Nonescheduler=get_scheduler(scheduler_name,optimizer,step=step,gamma=gamma,milestones=milestones,max_decay_steps=mdsteps,end_lr=end_lr,power=power)Get loss function.fromopennn_pytorch.lossesimportget_lossloss_fn='custom_mse'loss_fn,one_hot=get_loss(loss_fn)Get metrics functions.fromopennn_pytorch.metricsimportget_metricsmetrics_names=['accuracy','precision','recall','f1_score']number_classes=10metrics_fn=get_metrics(metrics_names,nc=number_classes)Train/Test.fromopennn_pytorch.algoimporttrain,test,predictionimportrandomalgorithm='train'batch_size=16class_names=['0','1','2','3','4','5','6','7','8','9']number_classes=10save_every=5epochs=20wandb_flag=Truewandb_metrics=['accuracy','f1_score']train_dataloader=torch.utils.data.DataLoader(train_data,batch_size=batch_size,shuffle=True)valid_dataloader=torch.utils.data.DataLoader(valid_data,batch_size=batch_size,shuffle=False)test_dataloader=torch.utils.data.DataLoader(test_data,batch_size=1,shuffle=False)ifalgorithm=='train':train(train_dataloader,valid_dataloader,model,optimizer,scheduler,loss_fn,metrics_fn,epochs,checkpoints,logs,device,save_every,one_hot,number_classes,wandb_flag,wandb_metrics)elifalgorithm=='test':test_logs=test(test_dataloader,model,loss_fn,metrics_fn,logs,device,one_hot,number_classes,wandb_flag,wandb_metrics)ifpred:indices=random.sample(range(0,len(test_data)),10)os.mkdir(test_logs+'/prediction',0o777)foriinrange(10):tmp_range=range(number_classes)tmp_dct={i:names[i]foriintmp_range}prediction(test_data,model,device,tmp_dct,test_logs+f'/prediction/{i}',indices[i])WandbWandbis very powerful logging tool, you will able to log metrics, hyperparamets, model hooks etc.wandblogin
<yourapitokenfromwandb.ai>CitationProjectcitation.LicenseProject is distributed underMIT License.