SlowGuess/NeurIPS_2023_OCR huggingface dataset:
where  $*$  is the traditional Cartesian convolution operator, and  $\delta(i,j) := \mathbf{D}^{-1}(\mathbf{v}_{\kappa_+(i,j)}^{\mathcal{R}} - \mathbf{v}_i^{\mathcal{R}} - \mathbf{v}_j^{\mathcal{S}})$  is a constant by which we shift the appropriate coset of  $a_{\mathcal{L}_{\mathcal{R}}}$ .
A practical note about this operation is in order. We are typically limited to rectangular support for  $\mathrm{supp}(\tilde{f}_j)$  in all popular implementations of Cartesian convolution. To address this, we simply take the "ZeroOut" approach [47], and zero out any inappropriate elements in the square filters' support.
Pooling The pooling operator also naturally extends to lattice tensors, we note this in the following definition.
Definition 3.7. For a lattice tensor  $a_{\mathcal{L}\mathcal{R}}$  and filter geometry  $\mathcal{L}_{\mathcal{P}}$  where the region  $\mathcal{P}$  is strictly positive, lattice pooling is defined as
$$
o _ {b, c, \mathcal {L} _ {R}} [ l, m, \mathbf {n} ] = \max  _ {\mathbf {s} \in \mathcal {L} _ {P}} \left\{a [ l, m, \mathbf {n} + \mathbf {s} ] \right\} \tag {6}
$$
whose output lattice tensor is in  $\mathcal{L}_S$  where  $\mathcal{L}_{\mathcal{R}} = \mathcal{L}_{\mathcal{S}}\oplus \mathcal{L}_{\mathcal{P}}$
We again, re-write this in terms of processing over Cartesian lattices in order to leverage existing frameworks for evaluation
Proposition 3.3. For a lattice tensor  $a_{\mathcal{L}_{\mathcal{R}}}$  and stencil geometry  $\mathcal{L}_{\mathcal{P}}$  where the region  $\mathcal{P}$  is strictly positive, the result of the lattice pooling operation  $o_{b,c,\mathcal{L}_{\mathcal{R}}}[l,m,\mathbf{n}] = \max_{\mathbf{s} \in \mathcal{L}_{\mathcal{P}}} \{a[l,m,\mathbf{n} + \mathbf{s}]\}$  can be written in terms of its output cosets as
$$
\tilde {o} _ {i} [ l, m, \mathbf {n} ] = \max  _ {0 \leq j <   C} \left\{\max  _ {\mathbf {s} \in \mathbf {D} ^ {- 1} \left(\mathcal {L} _ {\mathcal {P}} - \mathbf {v} _ {j}\right) \cap \mathbb {Z} ^ {s}} \left\{\tilde {a} _ {\kappa_ {+} (i, j)} [ \mathbf {n} + \mathbf {s} + \delta (i, j) ] \right\} \right\} \tag {7}
$$
where the maximum operation running over the set  $\mathbf{D}^{-1}(\mathcal{L}_{\mathcal{P}} - \mathbf{v}_j) \cap \mathbb{Z}^s$  is the traditional max pool operator, restricted to the  $j^{\mathrm{th}}$  coset of the stencil.
Downsampling Downsampling (i.e. discarding data then reducing resolution) is another basic operation that we generalize. The most general case for downsampling is to systematically remove samples in such a way that the lattice property is preserved. We take the standard path to define down/up sampling about an integer matrix  $\mathbf{S}$  with  $0 < \det \mathbf{S} \in \mathbb{Z}$ . We obtain the sub-sampled lattice by restricting to the new set  $\mathcal{Q} \coloneqq \mathbf{SL}$ . Loosely, for the new lattice  $\mathcal{Q}$  we obtain the coset decomposition, then subsample the input lattice tensor according to the new decomposition. This yields a new lattice tensor.
Upsampling Upsampling introduces new datapoints (initialized to zero) at a higher resolution lattice. We denote this with a matrix  $\mathbf{S}^{-1}\mathbf{L}\in \mathbb{Z}^{s\times s}$ . This employs the same mechanics as downsampling, but rather than removing points, we introduce new points according to the lattice in question. The mechanics of this are similar to downsampling, and we leave the details to the supplementary implementation.
3.1 Derivative Computation
Since gradient computation is an important feature that must be supported by any deep learning framework, it is crucial to discuss gradient computation from the perspective of lattice tensors. For a given loss function  $h$ , and the lattice tensor  $a$  the gradient  $\partial h / \partial a$  is simply the lattice tensor consisting of the gradients of the individual cosets, that is,  $\partial h / \partial \tilde{a}$ . Computing the gradient of any element-wise operation is straightforward; we simply operate independently on the coset tensors. However, for the remainder of the operations discussed so far, we require more care. We start with convolution.
Proposition 3.4. For a lattice tensor  $a_{\mathcal{L}_{\mathcal{R}}}$  and filter  $f_{\mathcal{L}_{\mathcal{P}}}$  where the region  $\mathcal{P}$  is strictly positive, with convolution defined as
$$
o [ n, i, \mathbf {p} ] := \left(a _ {b, c, \mathcal {L} _ {\mathcal {R}}} \star f _ {c, k, \mathcal {L} _ {\mathcal {P}}}\right) [ n, i, \mathbf {p} ] \tag {8}
$$
whose output lattice tensor is in  $\mathcal{L}_S$  where  $\mathcal{L}_R = \mathcal{L}_S\oplus \mathcal{L}_P$ , the derivatives of the loss  $h$  with respect to the filter and input lattice tensor are given by
$$
\frac {\partial h}{\partial a [ n , i , \mathbf {k} ]} = (o \star \overline {{f _ {c , k , \mathcal {L} _ {\mathcal {P}}}}} [ n, i, \mathbf {k} ], \tag {9}
$$
$$
\frac {\partial h}{\partial f [ i , j , \mathbf {k} ]} = \sum_ {n = 0} ^ {b - 1} \left(\sum_ {\mathbf {p} \in \mathcal {L} _ {\mathcal {S}}} \frac {\partial h}{\partial o [ n , i , \mathbf {p} ]} \cdot a [ n, j, \mathbf {p} + \mathbf {k} ]\right), \tag {10}
$$
where  $\overline{f}$  mirrors the filter and swaps the channels, i.e.  $\overline{f}[i,j,\mathbf{k}]\coloneqq f[j,i,-\mathbf{k}]$ .
Note that it is common to state the filter gradient as a convolution. We avoid introducing new notation to describe this fact and simply note this here.
Proposition 3.5. For a lattice tensor  $a_{\mathcal{L}_{\mathcal{R}}}$  and filter geometry  $\mathcal{L}_{\mathcal{P}}$  where the region  $\mathcal{P}$  is strictly positive, lattice pooling
$$
o _ {b, c, \mathcal {L} _ {R}} [ n, i, \mathbf {k} ] = \max  _ {\mathbf {s} \in \mathcal {L} _ {P}} \left\{a [ n, i, \mathbf {k} + \mathbf {s} ] \right\} \tag {11}
$$
whose output lattice tensor is in  $\mathcal{L}_S$ , has the gradients given by
$$
\frac {\partial h}{\partial a [ n , i , \mathbf {k} ]} = \sum_ {\mathbf {p} \in \mathcal {L} _ {\mathcal {P}}} \frac {\partial h}{\partial o [ n , i , \mathbf {k} - \mathbf {p} ]} \cdot \mu [ n, i, \mathbf {k} - \mathbf {p}, \mathbf {p} ] \tag {12}
$$
$$
\mu [ n, i, \mathbf {p}, \mathbf {q} ] := \left\{ \begin{array}{l l} 1 & \text {i f} \max  _ {\mathbf {s} \in \mathcal {L} _ {P}} \left\{a [ n, i, \mathbf {p} + \mathbf {s} ] \right\} = a [ n, i, \mathbf {p} + \mathbf {q} ] \\ 0 & \text {o t h e r w i s e .} \end{array} \right. \tag {13}
$$
The proofs of these facts are direct consequences of the chain rule, and can be found in the Appendix.
Derivatives of Padding, Downsampling and Upsampling The loss gradient of the downsampling operation is upsampling (taking care to respect the original dimensions of the original lattice tensor) and vice versa. The gradient of the padding operation simply truncates the padded gradient tensor, discarding any gradient signal outside of the original geometry of the tensor from the forward pass. For the most part, we leverage the automatic differentiability of PyTorch to compute derivatives of these operations [31]. However, more streamlined implementations using the forms above may save memory in future iterations of this work, since less temporary tensors must be saved during the forward pass.
4 Exploring non-Cartesian Networks
In this section, we delineate the experiments we conducted to evaluate NCDL. First, we compare NCDL with the closest existing hexagonal convolution library [34]. Subsequently, we explore the use of non-dyadic down/up sampling within bottlenecked architectures. To the best of our knowledge, this operation has not been explored in machine learning. All experiments are conducted on an AMD Ryzen 9 3900X (3.8GHz) with 128GB of DDR4 RAM operating at  $3200\mathrm{MHz}$ , accompanied by an NVIDIA RTX 3090 with 24GB of RAM.
4.1 Hexagonal Convolution
While NCDL focuses primarily on integer lattices, the hexagonal lattice exhibits the same coset structure as the quincunx lattice. This permits the storage of a hexagonal image on a quincunx lattice — convolution can be implemented via the selection of a suitable filter on the quincunx lattice. We assess the efficacy of this method in comparison to HexagDLy [34], which, among all other related works, is conceptually most similar to our approach.
Figure 4: Average run time in milliseconds (ms) as grid size increases, averaged over 100 runs, bench-marked on GPU. Variance is negligible.
Evaluation Figure 4 illustrates the performance trend as the grid size increases. Here, all grids are "equivalent" to the Cartesian grid. That is, we choose our hexagonal domain/lattice tensors to consume roughly the same amount of memory as the Cartesian grid. For example, if our Cartesian grid is  $256 \times 256$ , then each coset of our lattice tensor has a dimension of  $182 \times 182$ . We fixed input and output channels at 32 and 64 respectively (simulating an early stage in a convolutional pipeline). We limit our experiment to the case where the convolution kernel is a hexagonal 1-ring/1-neighborhood filter. We set the stride to 1, as NCDL does not support fused strides with convolution. It is important to note that we employ the same filter sizes as HexagDLy, but our convolutions occur over the separate cosets of
the lattice, which are smaller than the grids over which HexagDLy operates.
There are a few things to note about this experiment. For smaller grid sizes, NCDL exhibited slower performance compared to HexagDLy. This is likely due to the inherent overhead of managing the coset structure and the overhead of GPU kernel queueing. However, beyond a threshold, NCDL vastly outperforms HexagDLy. This is likely due to the fact that HexagDLy operates over larger grids (even though it employs strided convolutions). This effectively increases the computational load, particularly in processing larger inputs. While the strides in HexagDLy's implementation help in reducing the spatial dimensions of the output, the fundamental operation over larger grids does demand additional computational resources. Interestingly, only in one scenario (2048) did a non-Cartesian implementation outperform the Cartesian 1-ring filter. This finding is particularly significant, considering that the Cartesian convolution employs a larger filter size and is thus expected to involve more computation.
4.2 Non-dyadic Downsampling and the Quincunx Lattice
It is somewhat expected that convolution on hexagonal images yields superior results in aspects such as speed or accuracy. Nonetheless, non-Cartesian lattices may enhance performance without necessitating a change in approximation space through other means. In this second set of experiments, we investigate the application of non-dyadic downsampling. That is, as data flows through the network, it starts as a tensor on a Cartesian lattice; subsequent layers perform a convolution, then a downsample operation according to the following sub-sampling matrix  $\mathbf{S} = [-1\ 1;1\ 1]$ . This generates a lattice tensor on the Quincunx lattice. A subsequent convolution (followed by a downsample operation) results in a lattice tensor on the Cartesian lattice. Different levels of convolution alternate between these two grids (analogous to [19]), offering a more gradual reduction in resolution.
Figure 5: The network structures we propose. The auto-encoder experiments we conduct omit the skip connections between the layers. To maintain parity with the quincunx design, additional skip connections were added to the Cartesian case. Both networks share the same amounts of parameters.
Figure 6: Error plots for training and validation. The QCAE marginally outperforms in training, and outperforms with a wider margin in the validation. The table on the right shows the final model performance with respect to various error metrics; superior performance is noted in bold-font.
Quincunx Auto-encoder In this experiment, we establish a rudimentary autoencoder structure that progressively downsamples to a latent space before upsampling back to the image space. We first establish a baseline experiment, incorporating two Cartesian convolutions with  $3 \times 3$  filters, followed by a downsample (we maintain two convolutions to preserve parameter parity with the quincunx case). The Quincunx Convolutional Auto-Encoder (QCAE) lattice encompasses one convolution, a downsample onto the Quincunx lattice, one convolution, and a downsample onto the Cartesian lattice. Figure 5 shows the exact structures we design.
We train our models using the CelebA dataset [30]. Employing a straightforward L1 loss, we measure validation L1, L2, PSNR, SSIM [41] and LPIPs metrics [46]. The network is trained with the Adam optimizer, default parameters, and a batch size of 8. We train for 300,000 iterations, as convergence was observed at this point, and take an average of 5 runs. This represents a total of approximately 160 hours of training time for all experiments.
Salient Object Detection with a Quincunx U-Net In this experiment, we extend the rudimentary auto-encoder from the previous experiment by simply adding skip connections. Figure 5 shows the exact structures we design, and the dotted lines show the additional skip connections that we
Figure 7: Error plots for training and validation. The QCU-Net marginally fits to the data in the training set worse than the strictly Cartesian U-Net. However, the QCU-Net outperforms in generalization for this task. The table on the right shows the validation error at the end of training. Better performance is noted in bold-font.
U-Net	QCU-Net
L1 ↓	0.07583	0.08268
L2 ↓	0.04969	0.05107
BCE ↓	0.19266	0.18706
SSIM ↑	0.2900	0.3074
introduce for this example. We train our models on the DUTS salient object detection dataset [40], and employ a straightforward binary cross-entropy (BCE) loss; we measure validation BCE, L1, L2 and SSIM. The network is trained with the Adam optimizer, with default parameters, and a batch size of 8. We train for 120,000 iterations, as convergence was observed in the validation data at this point.
Discussion In our experiments, introducing a quincunx downsampling shows a notable difference across our tasks. For the autoencoder experiment, we note a small improvement in performance for no additional cost in parameters (Figure 6); replacing a traditional Cartesian convolution with a downsample operation followed by a Quincunx convolution should also be more computationally efficient, since certain convolutions occur on smaller grids. However, due to implementation overhead, we note that this is currently not true. The U-Net experiment is interesting in that it does not show distinctly better performance in training, but validation performance improves for the BCE metric (Figure 7). It is somewhat surprising that other metrics do not reflect the improved validation entropy; however minimizing BCE does not strictly imply that other pixel-wise metrics will improve, due to the way in which BCE weights pixelwise classification errors.
There are a few potential reasons for the improved quantitative performance of these networks. The downsampling scheme is more gradual in a QCAE. This likely leads to a more gradual reduction of information as it passes through the bottleneck of the network. Important information is less likely to be "missed" by this more gradual reduction. The second, more simple explanation may be that the aliasing introduced by the quincunx downsampling operation is much less strong, thereby providing a stronger signal as data pass through lower resolution layers of the network; aliasing is a well-known enemy of neural networks [45].
5 Future Work and Conclusions
This work has presented a general approach to enable the use of non-Cartesian lattices in machine learning. Doing so has opened a new avenue of research by introducing a new twist on a fundamental concept in machine learning. There are many possible avenues for future work: we plan on exploring this in the context of models at scale, for example in generative approaches like GANs or diffusion models [5, 20]. Additionally, modern components, such as the attention mechanism [39], must be generalized to this new structure. There is also still a good amount of performance left on the table. Decomposing convolution across the different cosets separates the convolution operation into disjoint operations that could, for example, take place on completely separate hardware. These separate operations could be scheduled across different memory chips, for example, to avoid bank conflicts or other complications that arise in GPU memory controllers.
We would like to thank Richard Zhang and Derek Nowrouzezahrai for their involvement in earlier less successful iterations of this work and for pushing us to finish this work.
[35] Christian Szegedy, Wei Liu, Yangqing Jia, Pierre Sermanet, Scott Reed, Dragomir Anguelov, Dumitru Erhan, Vincent Vanhoucke, and Andrew Rabinovich. Going deeper with convolutions. In Proceedings of the IEEE conference on computer vision and pattern recognition, pages 1-9, 2015.
[36] Mingxing Tan and Quoc Le. Efficientnet: Rethinking model scaling for convolutional neural networks. In International conference on machine learning, pages 6105-6114. PMLR, 2019.
[37] Mingxing Tan and Quoc Le. Efficientnetv2: Smaller models and faster training. In International conference on machine learning, pages 10096-10106. PMLR, 2021.
[38] Dimitri Van De Ville, Thierry Blu, Michael Unser, Wilfried Philips, Ignace Lemahieu, and Rik Van de Walle. Hex-splines: A novel spline family for hexagonal lattices. IEEE Transactions on Image Processing, 13(6):758-772, 2004.
[39] Ashish Vavwani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Lukasz Kaiser, and Illia Polosukhin. Attention is all you need. Advances in neural information processing systems, 30, 2017.
[40] Lijun Wang, Huchuan Lu, Yifan Wang, Mengyang Feng, Dong Wang, Baocai Yin, and Xiang Ruan. Learning to detect salient objects with image-level supervision. In CVPR, 2017.
[41] Zhou Wang, Alan C Bovik, Hamid R Sheikh, and Eero P Simoncelli. Image quality assessment: from error visibility to structural similarity. IEEE transactions on image processing, 13(4):600-612, 2004.
[42] Feng Xia, Ke Sun, Shuo Yu, Abdul Aziz, Liangtian Wan, Shirui Pan, and Huan Liu. Graph learning: A survey. IEEE Transactions on Artificial Intelligence, 2(2):109-127, 2021.
[43] Kenny Young, Gautham Vasan, and Ryan Hayward. Neurohex: A deep q-learning hex agent. In Computer Games: 5th Workshop on Computer Games, CGW 2016, and 5th Workshop on General Intelligence in Game-Playing Agents, GIGA 2016, Held in Conjunction with the 25th International Conference on Artificial Intelligence, IJCAI 2016, New York, USA, July 9-10, 2016, Revised Selected Papers, pages 3-18. Springer, 2017.
[44] Jiahui Yu, Zhe Lin, Jimei Yang, Xiaohui Shen, Xin Lu, and Thomas S Huang. Free-form image inpainting with gated convolution. In Proceedings of the IEEE/CVF international conference on computer vision, pages 4471-4480, 2019.
[45] Richard Zhang. Making convolutional networks shift-invariant again. In International conference on machine learning, pages 7324-7334. PMLR, 2019.
[46] Richard Zhang, Phillip Isola, Alexei A Efros, Eli Shechtman, and Oliver Wang. The unreasonable effectiveness of deep features as a perceptual metric. In CVPR, 2018.
[47] Yunxiang Zhao, Qiuhong Ke, Flip Korn, Jianzhong Qi, and Rui Zhang. Hexconn: a framework for native hexagonal convolutional neural networks. In 2020 IEEE International Conference on Data Mining (ICDM), pages 1424-1429. IEEE, 2020.