Package: fastorch
FastorchPytorchis convenient and easy to use, whileKerasis designed to experiment quickly. Do you want to possessbothPytorch's convenience and Keras'  fast experimentation? The answer isfastorch.Traditional classification task training flow in pytorch################################# import dependencies ###############################importtorch.nnasnnimporttorchfromtorch.utils.dataimportDataset,DataLoader################################# define your network ###############################classnetwork(nn.Module):def__init__(self):super(network,self).__init__()self.fc=nn.Sequential(nn.Linear(1000,500),nn.ReLU(True),nn.Linear(500,500),nn.ReLU(True),nn.Linear(500,500),nn.ReLU(True),nn.Linear(500,500),nn.ReLU(True),nn.Linear(500,100),nn.ReLU(True),nn.Linear(100,100),nn.ReLU(True),nn.Linear(100,10),)defforward(self,x):returnself.fc(x)################################## prepare dataset ##################################classmydataset(Dataset):def__init__(self,x,y):self.x=xself.y=ydef__getitem__(self,item):returnself.x[item],self.y[item]def__len__(self):returnself.x.size(0)# for simplicity, randomly generate datas,X=torch.randn(5000,1000)Y=torch.randint(0,10,size=(5000,))BATCH_SIZE=100trainset=mydataset(X,Y)train_loader=DataLoader(trainset,batch_size=BATCH_SIZE,shuffle=True)########################### assign optimizer and criterion ##########################optimizer=torch.optim.SGD(net.parameters(),lr=0.01)criterion=nn.CrossEntropyLoss()############################## define and run training ##############################device="cuda"iftorch.cuda.is_available()else"cpu"EPOCH=10net=network().to(device)forepochinrange(EPOCH):forx,yintrain_loader:x,y=x.to(device),y.to(device)optimizer.zero_grad()out=net(x)loss=criterion(out,y)loss.backward()optimizer.step()print('Epoch%d-> loss:%.4f'%(epoch,loss.item()))It's simple and straightforward, but is that enough? Below givesfastorch resolution.Training with fastorch################################# import dependencies ###############################importtorchimportfastorch################################# define your network ###############################'''inherit from fastorch in your own network'''classnetwork(fastorch.models.Model):def__init__(self):super(network,self).__init__()self.fc=nn.Sequential(nn.Linear(1000,500),nn.ReLU(True),nn.Linear(500,500),nn.ReLU(True),nn.Linear(500,500),nn.ReLU(True),nn.Linear(500,500),nn.ReLU(True),nn.Linear(500,100),nn.ReLU(True),nn.Linear(100,100),nn.ReLU(True),nn.Linear(100,10),)defforward(self,x):returnself.fc(x)################################## prepare dataset ################################### for simplicity, randomly generate datas,X=torch.randn(5000,1000)Y=torch.randint(0,10,size=(5000,))#################################### run training ###################################net=network()net.fit(x=X,y=Y,optimizer='sgd',criterion='cross_entropy',batch_size=BATCH_SIZE,epochs=1,verbose=1)'''Epoch[1/1]2100/5000 [========>***********] - 1s - 68ms/batch -batch_loss: 2.2993 -batch_acc: 0.1200'''InstallationBefore installing Fastorch, please install the followingdependencies:python >= 3.0 (3.6 is recommend)pytorch (1.0+ is recommend)Then you can install Fastorchby using pip:$ pip install fastorchSupportsWhen usingfastorch.models.Model, make sure your network isinheritedfromfastorch.models.Model.- fastorch.models.Modelfit(train_dataset=None,x=None,y=None,optimizer=None,criterion=None,transform=None,batch_size=None,epochs=1,verbose=1,print_acc=True,callbacks=None,validation_dataset=None,validation_split=0.0,validation_data=None,validation_transform=None,shuffle=True,initial_epoch=0,steps_per_epoch=None,device=None, **kwargs)train_dataset: training dataset, which inherited fromtorch.utils.data.Dataset. Make surexandyare not None whentrain_datasetis None.x: training data, it can beTensor銆乣ndarrayorList`. You need passxandywhentrain_datasetis None.y: training target, it can beTensor銆乣ndarrayorList`. You need passxandywhentrain_datasetis None.optimizer: model optimizer, it can bestror an instance ofpytorch optimizer, when passing str('sgd', 'adam'), fastorch will automatically declare the corresponding pytorch optimizer.criterion: loss function, it can bestror an instance ofpytorch objective function, when passing str('mse', 'cross_entropy', etc.), fastorch will automatically declare the corresponding pytorch objective function .transform:  applyingtorchvision.transformsonxandyortrain_dataset.batch_size: training batch_size,  default is 32 if not specified.epochs: training stop epochs, default is 1 if not specified.verbose: log display mode, 0 = silent, 1 = progress bar, 2 = print each line.print_acc: True or False, passing True if you are doing classification task.callbacks: waiting for implemented.validation_dataset:  validation dataset, which inherited fromtorch.utils.data.Dataset.validation_split: split validation data from training data's ratio, make surexandyare not None when using this argument.validation_data: tuple of validation x and validation y.validation_transform:  applyingtorchvision.transformsonvalidation_dataor data split byvalidation_split.shuffle: whether shuffle the training data.initial_epoch: start training epoch.steps_per_epoch: int or None, if specified, batch_size will be set as total_sample_nums /steps_per_epoch.device: specify device, otherwise fastorch will set device according totorch.cuda.is_available().**kwargs: arguments used fortorch.utils.data.Dataloader, etc.evaluate(dataset=None,dataloader=None,x=None,y=None,transform=None,batch_size=None,verbose=1,criterion=None,print_acc=True,steps=None,device=None, **kwargs)dataset: evaluate dataset, which inherited fromtorch.utils.data.Dataset. Make suredataloaderorxandyare not None whendatasetis None.dataloader: evaluate dataloader, which inherited fromtorch.utils.data.Dataloader. Make suredatasetorxandyare not None whendataloaderis None.x: test data, it can beTensor銆乣ndarrayorList`. You need passxandywhendatasetordataloaderis None.y: test target, it can beTensor銆乣ndarrayorList`. You need passxandywhendatasetordataloaderis None.transform:  applyingtorchvision.transformsonxandyordataset.batch_size: evaluate batch_size,  default is 32 if not specified.verbose: log display mode, 0 = silent, 1 = progress bar, 2 = print each line.criterion: loss function, it can bestror an instance ofpytorch objective function, when passing str('mse', 'cross_entropy', etc.), fastorch will automatically declare the corresponding pytorch objective function .print_acc: True or False, passing True if you are doing classification task.steps: int or None, if specified, batch_size will be set as total_sample_nums /steps.device: specify device, otherwise fastorch will set device according totorch.cuda.is_available().**kwargs: arguments used fortorch.utils.data.Dataloader, etc.- fastorch.functionalfit(model=None,train_dataset=None,x=None,y=None,optimizer=None,criterion=None,transform=None,batch_size=None,epochs=1,verbose=1,print_acc=True,callbacks=None,validation_dataset=None,validation_split=0.0,validation_data=None,validation_transform=None,shuffle=True,initial_epoch=0,steps_per_epoch=None,device=None, **kwargs)model: your network, must be specify.train_dataset: training dataset, which inherited fromtorch.utils.data.Dataset. Make surexandyare not None whentrain_datasetis None.x: training data, it can beTensor銆乣ndarrayorList`. You need passxandywhentrain_datasetis None.y: training target, it can beTensor銆乣ndarrayorList`. You need passxandywhentrain_datasetis None.optimizer: model optimizer, it can bestror an instance ofpytorch optimizer, when passing str('sgd', 'adam'), fastorch will automatically declare the corresponding pytorch optimizer.criterion: loss function, it can bestror an instance ofpytorch objective function, when passing str('mse', 'cross_entropy', etc.), fastorch will automatically declare the corresponding pytorch objective function .transform:  applyingtorchvision.transformsonxandyortrain_dataset.batch_size: training batch_size,  default is 32 if not specified.epochs: training stop epochs, default is 1 if not specified.verbose: log display mode, 0 = silent, 1 = progress bar, 2 = print each line.print_acc: True or False, passing True if you are doing classification task.callbacks: waiting for implemented.validation_dataset:  validation dataset, which inherited fromtorch.utils.data.Dataset.validation_split: split validation data from training data's ratio, make surexandyare not None when using this argument.validation_data: tuple of validation x and validation y.validation_transform:  applyingtorchvision.transformsonvalidation_dataor data split byvalidation_split.shuffle: whether shuffle the training data.initial_epoch: start training epoch.steps_per_epoch: int or None, if specified, batch_size will be set as total_sample_nums /steps_per_epoch.device: specify device, otherwise fastorch will set device according totorch.cuda.is_available().**kwargs: arguments used fortorch.utils.data.Dataloader, etc.evaluate((model=None,dataset=None,dataloader=None,x=None,y=None,transform=None,batch_size=None,verbose=1,criterion=None,print_acc=True,steps=None,device=None, **kwargs)model: your network, must be specify.dataset: evaluate dataset, which inherited fromtorch.utils.data.Dataset. Make suredataloaderorxandyare not None whendatasetis None.dataloader: evaluate dataloader, which inherited fromtorch.utils.data.Dataloader. Make suredatasetorxandyare not None whendataloaderis None.x: test data, it can beTensor銆乣ndarrayorList`. You need passxandywhendatasetordataloaderis None.y: test target, it can beTensor銆乣ndarrayorList`. You need passxandywhendatasetordataloaderis None.transform:  applyingtorchvision.transformsonxandyordataset.batch_size: evaluate batch_size,  default is 32 if not specified.verbose: log display mode, 0 = silent, 1 = progress bar, 2 = print each line.criterion: loss function, it can bestror an instance ofpytorch objective function, when passing str('mse', 'cross_entropy', etc.), fastorch will automatically declare the corresponding pytorch objective function .print_acc: True or False, passing True if you are doing classification task.steps: int or None, if specified, batch_size will be set as total_sample_nums /steps.device: specify device, otherwise fastorch will set device according totorch.cuda.is_available().**kwargs: arguments used fortorch.utils.data.Dataloader, etc.