Package: torch-trandsforms
torch traNDsformsA pytorch-first transform library for ND data, such as multi-channel 3D volumesFeaturestorch traNDsforms is an easy to use transform library for N-dimensional PyTorch dataDifferentiable, accelerated ND transformations with most tensorsOne transform pipeline for all your data usingKeyedTransformsCustomizable and lightweightNo superfluous dependenciesCollaborativeInstallationpipinstalltorch_trandsformsorpoetryaddtorch-trandsformsor potentiallycondainstalltorch_trandsformsUsageCreating the RandomRotate90 class, as an example of customizing your own transform:importtorchfromtorch_trandsforms.baseimportBaseTransformclassRandomRotate90(BaseTransform):# note the use of BaseTransform as base class here"""Rotates the input 90 degrees around a randomly determined axisNOTE: This is the not actual implementation of RandomRotate90"""def__init__(self,nd=3,p=0.5):super().__init__(p=p,nd=nd)self.options=self._get_options(nd)def_get_options(self,nd):"""Create potential rotations based on the nd argumentThis can be lower than the number of dimensions of the actual inputin case you do not want a leading dimension to be rotated"""options=[]foriinrange(nd):forjinrange(nd):ifnoti==j:options.append((-i-1,-j-1))returnoptionsdefget_parameters(self,**inputs):"""overrides the base get_parameters to choose a randomrotation option for each input"""rotation=random.choice(self.options)return{'rot':rotation}defapply(self,input,**params):"""apply MUST be overwrittenIt is applied to each input sequentially, and thus must haveparameters that are exactly equal for each instance,meaning most likely NO randomization here"""rot=params['rot']returntorch.rot90(input,dims=rot)And we can now use our class to demonstrate the library functionality:torch.manual_seed(451)# all randomization uses torch.random in the actual implementationtensor=torch.arange(16).view(2,2,2,2)# create a 4D tensoranother_tensor=torch.arange(16).view(2,2,2,2)# create an exactly equal tensor for demonstrationprint(tensor)print(another_tensor)random_rotator=RandomRotate90(nd=2,p=1.)# we only want the last two dimensions to be rotateable but it should rotate every time (p=1)transformed=random_rotator(data=tensor,foo=another_tensor)# "data" is arbitrary, it is the key that will be returned, demonstrated by "foo"print(transformed['data'])print(transformed['foo'])For more examples of use, seeEXAMPLES.mdSpeedPlease seeTIMING.mdfor timings. Seetest_speed.pyfor methodology.SupportPlease useIssuesfor any issues, feature requests, or general feedback.RoadmapFor now, traNDsforms is in early alpha. That will continue for a while, while basic functionality is implemented.The roadmap is determined by the collaborative efforts of every user that provides feedback, reports bugs, or produces pull requests. Thank you!For now, the roadmap looks something like this:Implement basic functionality (normalize, dtype changing, change device)Implement value-level noise functionality (uniform, salt and pepper, gaussian)Implement structural transforms (cropping, flipping)Implement placeholder transforms for not-yet-ND-capable transforms (arbitrary rotation, scaling)More examples, including better visualsDevelopment structure: Lock main && publishMove basic functionality to _functional and _utilsLater additions (and reasons for postponing):Arbitrary rotations (missing ND affine_grid and grid_sample)Gaussian Blur (missing implementation of ND convolution)Affine transformations (missing efficient ND computation)Potential additions:Geometric operations using PyTorch GeometricPoint clouds, meshes using PyTorch 3DData loading, sampling, and structurestorchscript compatibilityContributingSeeContributingAuthorsThe project is maintained by developers at theAlexandra InstituteOliver G. Hjermitslev (ohjerm)oliver.gyldenberg@alexandra.dk...to be expanded...LicenseSee theMIT License📃 Citation@misc{torch-trandsforms,author={Alexandra Institute},title={A pytorch-first transform library for ND data, such as multi-channel 3D volumes},year={2023},publisher={GitHub},journal={GitHub repository},howpublished={\url{https://github.com/alexandrainst/torch-trandsforms}}}