{'fraction_non_alphanumeric': 0.03533748569975848, 'fraction_numerical': 0.02033812126604805, 'mean_word_length': 4.746895544192841, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Semantic Segmentation using Neural Ordinary Differential Equations

The idea of neural Ordinary Differential Equations (ODE) is to approximate the derivative of a function (data model) instead of the function itself. In residual networks, instead of having a discrete sequence of hidden layers, the derivative of the continuous dynamics of hidden state can be parameterized by an ODE. It has been shown that this type of neural network is able to produce the same results as an equivalent residual network for image classification. In this paper, we design a novel neural ODE for the semantic segmentation task. We start by a baseline network that consists of residual modules, then we use the modules to build our neural ODE network. We show that our neural ODE is able to achieve the state-of-the-art results using 57% less memory for training, 42% less memory for testing, and 68% less number of parameters. We evaluate our model on the Cityscapes, CamVid, LIP, and PASCAL-Context datasets.


Introduction
Neural Ordinary Differential Equations. In machine learning, we try to iteratively find a function that best describes the data. There are two basic approaches to finding this function. The first approach is to directly approximate the function by an analytical or numerical method. An ordinary linear regression falls into this category. The second approach is to approximate the derivative of the function. This results in an Ordinary Differential Equation (ODE) which by solving, we get the approximation of the function. We can parameterize the derivative of the function as a neural network. Now, consider a residual network [15] where all the hidden states have the same dimension. Such networks generate an output by doing a sequence of transformations to a hidden state [6]: By adding infinite number of layers, we get the continuous dynamics of hidden units using an ODE defined by a neural network [6]:  For the up-sampling, we use bilinear interpolation to avoid the checkerboard artifact [31].
where f (h(t), t, θ) is a neural network layer parameterized by θ at layer t. By solving the integral: we can get the output value of a hidden layer at some depth T . Semantic Segmentation. Semantic segmentation refers to the process of assigning each pixel in an image to a class label. Current state-of-the-art neural networks for semantic segmentation require a considerable amount of memory for training (especially with high-resolution images). Based on the fact that neural ODEs use less memory [6], in this paper we propose a novel neural ODE design for the semantic segmentation task. We evaluate our model on the Cityscapes [8], CamVid [2], LIP [12], and PASCAL-Context [28] datasets and show that it is able to produce the state-of-the-art results using 57% less memory for training, 42% less memory for testing, and 68% less number of parameters.

Related Work
Neural ODEs. Recently, several works have analyzed the relationship between dynamical systems and deep neural networks. In [40], the authors propose the idea of using continuous dynamical systems as a tool for machine learning. In [25], it has been shown that many effective networks, such as ResNet [15], PolyNet [43], FractalNet [19], and RevNet [11], can be interpreted as different numerical discretizations of differential equations. When the discretization step approaches zero, it yields a family of neural networks, which are called neural ODEs [6]. [6] proposes to compute gradients using the adjoint sensitivity method [33], in which there is no need to store intermediate quantities during the forward pass of the network. In [46], an interpretation of Dense Convolutional Networks (DenseNets) [17] and Convolutional Neural Networks with Alternately Updated Clique (CliqueNets) [41] is provided from a dynamical systems view point.
Memory Usage Reduction. There are methods to reduce memory footprints. Reduced precision formats are binary floating-point formats that occupy less than 32 bits (four bytes) [9,27]. These formats either reduce the accuracy or add some processing overhead for converting high precision to low precision. Many other memory reduction techniques are derivatives of binomial gradient check-pointing [14,7,35]. The overall idea of gradient checkpointing is that the results of cheap operations such as batch normalization [18] or ReLU can be dropped and then recomputed later. All the gradient check-pointing approaches add processing overhead during training.
Semantic Segmentation. Current state-of-the-art methods for semantic segmentation are based on convolutional neural networks. These networks have different architectures. Encoder-decoder or hourglass networks are used in many computer vision tasks like object detection [22], human pose estimation [29], image-based localization [26], and semantic segmentation [23,1,30]. Generally, they are made of an encoder and decoder parts such that, the encoder gradually reduces the feature maps resolution and captures high-level semantic information, and the decoder gradually recovers the low-level details. Because these networks lose the image details during the encoder path, they are not able to achieve the highest results without using skip connections. Spatial pyramid pooling models perform spatial pyramid pooling [20,13] at different grid scales or apply several parallel atrous convolution [4] with different rates. These models include the two well-known PSPNet [44] and DeepLab [5]. High-resolution representation networks [39,16,10,45] try to maintain a high-resolution hidden state from input to output. By doing low-resolution convolutions in parallel streams, high-level features are gained while low-level details are not lost. Since these networks require a lot of memory, they first down-sample the input image to a lower resolution before the main body. Some approaches [4,3] do post-processing, such as conditional random fields, on the network's output to improve the segmentation details, especially around the object boundaries. These approaches add some processing overhead to training and testing.
Semantic Segmentation using Neural ODEs. There are only a few methods for semantic segmentation that have partially incorporated neural ODEs in the network design. In [32], a U-Net is modified to use neural ODEs. In this design, the repeated residual blocks in each branch are replaced by a neural ODE that wraps around only one convolutional block. Although U-Net is a wellknown network, more recent networks can achieve higher results than U-Net. In this paper, we design our network based on the HRNetV2 [39] which can achieve the state-of-the-art accuracy on the Cityscapes [8], CamVid [2], and LIP [12] datasets. Similar to [32], another modified U-Net is introduced in [21]. This Fig. 2. The baseline network is created by repeating the last module from HRNetV2 [39] which has four branches with different feature-map resolutions. We use skip connections at the module level (not drawn). So, each module is treated as a residual block. Each small block in a module consists of one set of batch normalization [18], ReLU, and convolutional layers. This network is not a neural ODE and is trained similarly to HRNetV2.
time, instead of replacing a branch with a neural ODE block, a neural ODE block is added at the end of each branch. In [38], a novel approach that combines neural ODEs and the Level Set method is proposed. This approach parameterizes the derivative of the contour as a neural ODE that implicitly learns a forcing function describing the evolution of the contour. This approach is limited to the segmentation of images with one target class.

Method
We introduce a baseline network that is trained without the use of neural ODEs. Then we introduce a neural ODE equivalent to the baseline network. Our goal is to compare the results step by step, from a state-of-the-art network to the baseline network, then to the neural ODE network.

Baseline Network
At the time of writing, one of the state-of-the-art methods in semantic segmentation is HRNetV2 [39]. We try to adopt this network architecture and turn it into a residual form such that each module is like a residual block. To this aim, we repeat the last module in series, multiple times and treat each one of them as a residual unit (as depicted in Figure 2). This way, the network consists of multiple residual modules, each module has four branches with different feature-map resolutions, and each branch has multiple residual blocks. In our experiments in this paper, we repeat the main module six times to keep the number of parameters close to HRNetV2. We use this baseline network to gradually evaluate the design of our neural ODE network.

SegNode
Since the baseline network has an overall residual form, we can turn it into a neural ODE. In this form, a single or multiple modules act as the function f in Equation 1. This module (or modules) is wrapped in an ODE solver. Since the main module has four convolutional streams with different resolutions and number of channels, we use convolutional layers to create the input feature-maps with the corresponding resolution and number of channels. The resulting four tensors are fed to the ODE solver. The output of the ODE solver has the same format as its input. By using four convolutional layers, the number of channels of the output feature maps is changed to the number of classes. Then, the feature maps are re-scaled to the higher resolution using bilinear interpolation and added together to produce the final output (as shown in Figure 1). Bilinear interpolation is used to avoid the checkerboard artifact [31]. We call our network SegNode for short.

Experiments
We evaluate our approach on four datasets: Cityscapes [8], CamVid [2], LIP [12], and PASCAL-Context [28]. Additionally, since the existing neural ODE methods for semantic segmentation have not been evaluated on these datasets, we train and test the two U-Net based methods [32,21] on these datasets and report their accuracy.

Setup
We pretrain our baseline and SegNode networks on ImageNet [37] and use the pre-trained networks in all our experiments. We use the mean Intersection over Union (mIoU) metric to compare all the methods. For the baseline network, we use AdamW optimizer [24] with a weight decay of 0.05 and batch size of 16. We apply the "polynomial" learning rate policy with a poly exponent of 0.9 and an initial learning rate of 0.0001.
For SegNode, we use the Runge-Kutta ODE solver provided by [6]. Also, we use the adjoint sensitivity method [33] which is available in the same implementation. We use the SGD optimizer with a base learning rate of 0.1, a momentum of 0.9, and no weight decay. The polynomial learning rate decay function is used with a poly exponent of 0.9.

Method
Maximum For both the baseline network and SegNode, similar to HRNetV2 [39], we use a stem for the input image, which consists of two stride-2 3×3 convolutions to decrease the resolution to 1/4, and is connected to the main body. The main body outputs the feature maps with the same resolution (1/4), which are then made larger as the original resolution using bilinear interpolation. Each stream in the main body has 48, 96, 192, and 384 channels respectively from the highest resolution to the lowest. We use two modules in the main body to achieve the highest accuracy.

Cityscapes
The Cityscapes dataset [8] contains 5k high quality pixel-level finely annotated street images. The finely annotated images are divided into 2,975/500/1,525 images for training, validation, and testing. Also, the dataset contains additional 20k coarsely annotated images. There are 30 classes, and 19 classes among them are used for evaluation. We train on the training, validation, and coarse sets to get the highest accuracy on the test set.

CamVid
Compared to Cityscapes [8], CamVid [2] is a much smaller dataset focusing on semantic segmentation for driving scenarios. The original version is composed of 701 annotated images in 32 classes with size 960×720 from five video sequences. However, most literature only focuses on the protocol proposed in [1] which splits the dataset into 367 training, 101 validation, and 233 test images in 11 classes. We follow this protocol for training on CamVid.

LIP
The LIP dataset [12] contains 50,462 human images with detailed annotations. The dataset is divided into 30,462 training, 10,000 validation, and 10,000 test images. The model evaluation is done on 20 categories (including the background label). We follow the common testing protocol [36,39] and resize the images to 473×473.

PASCAL-Context
The PASCAL-Context dataset [28] adds annotations for more than 400 additional categories to the PASCAL VOC 2010 dataset. It contains 4,998 training and 5,105 validation images, subsets of PASCAL VOC 2010 dataset. The dataset annotations cover 100% of pixels while the previous annotations covered around 29%. We follow [39,42] and evaluate our method on 59 sub-categories.  Table 1 compares the results of our proposed method to different variants of HRNetV2 and existing neural ODE methods. On average our method performs better than HRNetV2 and its variants by a small margin. We tried and improved the existing neural ODE methods in our implementation by increasing the number of parameters and tuning hyper-parameters. Still, our proposed design can achieve higher accuracy by a large margin. The main reason is that we started our design from a better-performing network architecture and modified it step-by-step towards the final design.

Empirical Computational Cost
In this section, we provide an empirical comparison between our approach and a few well-known networks. We use an NVIDIA Tesla V100 32GB with the same network hyper-parameters as used before. All the experiments are implemented in Python using PyTorch. The results are calculated on CamVid [2] dataset with an image size of 480 × 360. Table 2 compares a few important empirical computational measures. Our method requires the least amount of memory, but the longest computation time for training and testing by a large margin. In particular, compared to HRNetV2 [39], while our method has 68% less number of parameters, it requires 57% less memory for training and 42% less memory for testing. On the other side, HRNetV2 requires 47% less training time and 59% less testing time.

Trajectory Error
In this section, we show how the ODE solver gradually improves its output during test time. Figure 3 visualizes the segmentation output of the network trajectories over time for one sample image. This figure shows the steps that the ODE solver takes during solving the network. To generate each step, the corresponding hyper-parameter of the ODE solver is modified to partially solve its input. Figure 4 shows the average mean IoU error of the trajectories over time for all the samples in the PASCAL-Context validation set. One of the biggest issues with neural ODEs is that they require more computational resources during test time. To alleviate this problem, it is possible to sacrifice accuracy for speed. As an example, by sacrificing 3% of accuracy, the required computational time decreases by 50%.

Conclusion
Based on a current state-of-the-art network, we proposed a novel neural ODE design for semantic segmentation. The new idea of neural ODEs helped us to reduce the memory requirement with the cost of more processing time. While using a notably less amount of memory, our method (SegNode) was able to achieve state-of-the-art results. The proposed method can be used for all the computer vision tasks that can make use of dense 2D predictions such as human pose estimation and object detection tasks.