Package: deepsplines
DeepSplinesis a framework to train the activation functions of a neural network.The aim of this repository is to:Facilitate the reproduction of the results reported in the research papers:Learning Activation Functions in Deep (Spline) Neural Networks;Deep Neural Networks with Trainable Activations and Controlled Lipschitz Constant.Enable a seamless integration of deep spline activation functions in a custom neural network.The proposed scheme is based on the theoretical work ofM.Unser.Table of ContentsRequirementsInstallationQuick InstallDevelopper InstallUsageReproducing resultsDevelopersReferencesLicenseAcknowledgementsRequirementspython >= 3.7numpy >= 1.10pytorch >= 1.5.1torchvision >= 0.2.2matplotlib >= 3.3.1(optional) CUDAThe code was developed and tested on a x86_64 Linux system.InstallationTo install the package, we first create an environment with python 3.7 (or greater):>>condacreate-y-ndeepsplinespython=3.7>>sourceactivatedeepsplinesQuick InstallDeepSplinesis available onPypi.
Therefore, you can install the package via the command:>>pipinstalldeepsplinesFor NVIDIA GPU compatibility, you need to additionally installcudatoolkit(viacondainstall-canacondacudatoolkit)Developper InstallIt is also possible to installDeepSplinesfrom the source for developpers:>>gitclonehttps://github.com/joaquimcampos/DeepSplines>>cd<repository_dir>/>>pipinstall-e.UsageHere we show an example on how to adapt thePyTorch CIFAR-10 tutorialto use DeepBSpline activations.fromdeepsplines.ds_modulesimportdsnnclassDSNet(dsnn.DSModule):def__init__(self):super().__init__()self.conv_ds=nn.ModuleList()self.fc_ds=nn.ModuleList()# deepspline parametersopt_params={'size':51,'range_':4,'init':'leaky_relu','save_memory':False}# convolutional layer with 6 output channelsself.conv1=nn.Conv2d(3,6,5)self.conv_ds.append(dsnn.DeepBSpline('conv',6,**opt_params))self.pool=nn.MaxPool2d(2,2)self.conv2=nn.Conv2d(6,16,5)self.conv_ds.append(dsnn.DeepBSpline('conv',16,**opt_params))# fully-connected layer with 120 output unitsself.fc1=nn.Linear(16*5*5,120)self.fc_ds.append(dsnn.DeepBSpline('fc',120,**opt_params))self.fc2=nn.Linear(120,84)self.fc_ds.append(dsnn.DeepBSpline('fc',84,**opt_params))self.fc3=nn.Linear(84,10)defforward(self,x):x=self.pool(self.conv_ds[0](self.conv1(x)))x=self.pool(self.conv_ds[1](self.conv2(x)))x=torch.flatten(x,1)# flatten all dimensions except batchx=self.fc_ds[0](self.fc1(x))x=self.fc_ds[1](self.fc2(x))x=self.fc3(x)returnxdsnet=DSNet()dsnet.to(device)main_optimizer=optim.SGD(dsnet.parameters_no_deepspline(),lr=0.001,momentum=0.9)aux_optimizer=optim.Adam(dsnet.parameters_deepspline())lmbda=1e-4# regularization weightlipschitz=False# lipschitz controlforepochinrange(2):fori,datainenumerate(trainloader):# get the inputs; data is a list of [inputs, labels]inputs,labels=data[0].to(device),data[1].to(device)# zero the parameter gradientsmain_optimizer.zero_grad()aux_optimizer.zero_grad()outputs=dsnet(inputs)loss=criterion(outputs,labels)# add regularization lossiflipschitzisTrue:loss=loss+lmbda*dsnet.BV2()else:loss=loss+lmbda*dsnet.TV2()loss.backward()main_optimizer.step()aux_optimizer.step()For full details, please consultscripts/deepsplines_tutorial.py.Reproducing resultsTo reproduce the results shown in the research papers[Bohra-Campos2020]and[Aziznejad2020]one can run the following scripts:>>./scripts/run_resnet32_cifar.py>>./scripts/run_nin_cifar.py>>./scripts/run_twoDnet.pyTo see the running options, please add--helpto the commands above.DevelopersDeepSplinesis developed by theBiomedical Imaging Group,École Polytéchnique Fédérale de Lausanne, Switzerland.For citing this package, please see:http://doi.org/10.5281/zenodo.5156042Original authors:Joaquim Campos(joaquimcampos15@hotmail.com)Pakshal Bohra(pakshal.bohra@epfl.ch)Contributors:Harshit GuptaReferences[Bohra-Campos2020]Bohra, J. Campos, H. Gupta, S. Aziznejad, M. Unser, “Learning Activation Functions in Deep (Spline) Neural Networks,” IEEE Open Journal of Signal Processing, vol. 1, pp.295-309, November 19, 2020.[Aziznejad2020]Aziznejad, H. Gupta, J. Campos, M. Unser, “Deep Neural Networks with Trainable Activations and Controlled Lipschitz Constant,” IEEE Transactions on Signal Processing, vol. 68, pp. 4688-4699, August 10, 2020.LicenseThe code is released under the terms of theMIT LicenseAcknowledgementsThis work was supported in part by the Swiss National Science Foundation under Grant 200020_184646 / 1 and in part by the European Research Council (ERC)
under Grant 692726-GlobalBioIm.MIT LicenseCopyright (c) 2021 Joaquim Campos, Pakshal BohraPermission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.