Package: wavemix
WaveMixResource-efficient Token Mixing for Images using 2D Discrete Wavelet TransformWaveMix ArchitectureWaveMix-LiteWe propose WaveMixâ€“ a novel neural architecture for computer vision that is resource-efficient yet generalizable and scalable. WaveMix networks achieve comparable or better accuracy than the state-of-the-art convolutional neural networks, vision transformers, and token mixers for several tasks, establishing new benchmarks for segmentation on Cityscapes; and for classification on Places-365, f ive EMNIST datasets, and iNAT-mini. Remarkably, WaveMix architectures require fewer parameters to achieve these benchmarks compared to the previous state-of-the-art. Moreover, when controlled for the number of parameters, WaveMix requires lesser GPU RAM, which translates to savings in time, cost, and energy. To achieve these gains we used multi-level two-dimensional discrete wavelet transform (2D-DWT) in WaveMix blocks, which has the following advantages: (1) It reorganizes spatial information based on three strong image priorsâ€“ scale-invariance, shift-invariance, and sparseness of edges, (2) in a lossless manner without adding parameters, (3) while also reducing the spatial sizes of feature maps, which reduces the memory and time required for forward and backward passes, and (4) expanding the receptive field faster than convolutions do. The whole architecture is a stack of self-similar and resolution-preserving WaveMix blocks, which allows architectural f lexibility for various tasks and levels of resource availability.TaskDatasetMetricValueSemantic SegmentationCityscapesSingle-scale mIoU82.70% (SOTA)Image ClassificationImageNet-1kAccuracy74.93%Parameter EfficiencyTaskModelParameters99% Accu. in MNISTWaveMix Lite-8/10356690% Accu. in Fashion MNISTWaveMix Lite-8/5715680% Accu. in CIFAR-10WaveMix Lite-32/73705890% Accu. in CIFAR-10WaveMix Lite-64/6520106The high parameter efficiency is obtained by replacing Deconvolution layers with UpsamplingThis is an implementation of code from the following papers :Openreview Paper,ArXiv Paper 1,ArXiv Paper 2Install$pipinstallwavemixUsageSemantic Segmentationimporttorch,wavemixfromwavemix.SemSegmentimportWaveMiximporttorchmodel=WaveMix(num_classes=20,depth=16,mult=2,ff_channel=256,final_dim=256,dropout=0.5,level=4,stride=2)img=torch.randn(1,3,256,256)preds=model(img)# (1, 20, 256, 256)Image Classificationimporttorch,wavemixfromwavemix.classificationimportWaveMiximporttorchmodel=WaveMix(num_classes=1000,depth=16,mult=2,ff_channel=192,final_dim=192,dropout=0.5,level=3,patch_size=4,)img=torch.randn(1,3,256,256)preds=model(img)# (1, 1000)Single Image Super-resolutionimportwavemix,torchfromwavemix.sisrimportWaveMixmodel=WaveMix(depth=4,mult=2,ff_channel=144,final_dim=144,dropout=0.5,level=1,)img=torch.randn(1,3,256,256)out=model(img)# (1, 3, 512, 512)To use a single Waveblockimportwavemix,torchfromwavemiximportLevel1WaveblockParametersnum_classes: int.Number of classes to classify/segment.depth: int.Number of WaveMix blocks.mult: int.Expansion of channels in the MLP (FeedForward) layer.ff_channel: int.No. of output channels from the MLP (FeedForward) layer.final_dim: int.Final dimension of output tensor after initial Conv layers. Channel dimension when tensor is fed to WaveBlocks.dropout: float between[0, 1], default0..Dropout rate.level: int.Number of levels of 2D wavelet transform to be used in Waveblocks. Currently supports levels from 1 to 4.stride: int.Stride used in the initial convolutional layers to reduce the input resolution before being fed to Waveblocks.initial_conv: str.Deciding between strided convolution or patchifying convolutions in the intial conv layer. Used for classification. 'pachify' or 'strided'.patch_size: int.Size of each non-overlaping patch in case of patchifying convolution. Should be a multiple of 4.Cite the following papers@misc{
p2022wavemix,
title={WaveMix: Multi-Resolution Token Mixing for Images},
author={Pranav Jeevan P and Amit Sethi},
year={2022},
url={https://openreview.net/forum?id=tBoSm4hUWV}
}

@misc{jeevan2022wavemix,
    title={WaveMix: Resource-efficient Token Mixing for Images},
    author={Pranav Jeevan and Amit Sethi},
    year={2022},
    eprint={2203.03689},
    archivePrefix={arXiv},
    primaryClass={cs.CV}
}

@misc{jeevan2023wavemix,
      title={WaveMix: A Resource-efficient Neural Network for Image Analysis}, 
      author={Pranav Jeevan and Kavitha Viswanathan and Anandu A S and Amit Sethi},
      year={2023},
      eprint={2205.14375},
      archivePrefix={arXiv},
      primaryClass={cs.CV}
}