{'fraction_non_alphanumeric': 0.0325626397090715, 'fraction_numerical': 0.016081139692389817, 'mean_word_length': 4.673670263108082, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 1, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Self-supervised Motion Learning from Static Images

Motions are reflected in videos as the movement of pixels, and actions are essentially patterns of inconsistent motions between the foreground and the background. To well distinguish the actions, especially those with complicated spatio-temporal interactions, correctly locating the prominent motion areas is of crucial importance. However, most motion information in existing videos are difficult to label and training a model with good motion representations with supervision will thus require a large amount of human labour for annotation. In this paper, we address this problem by self-supervised learning. Specifically, we propose to learn Motion from Static Images (MoSI). The model learns to encode motion information by classifying pseudo motions generated by MoSI. We furthermore introduce a static mask in pseudo motions to create local motion patterns, which forces the model to additionally locate notable motion areas for the correct classification.We demonstrate that MoSI can discover regions with large motion even without fine-tuning on the downstream datasets. As a result, the learned motion representations boost the performance of tasks requiring understanding of complex scenes and motions, i.e., action recognition. Extensive experiments show the consistent and transferable improvements achieved by MoSI. Codes will be soon released.


Introduction
Understanding motion patterns is a key challenge in many video understanding problems such as action recognition [7], action localization [43] and action detection [58]. A suitable way to encode motions can significantly boost the performance in those tasks [44]. Early works represent motions using hand-crafted features [38,49,37] based on dense trajectories [48] and optical flow [2]. With the successful application of deep neural networks [15,24,19] and the construction of large scale image and video datasets [5,20], endeavors have been made to design architectures to  [41] visualizations on HMDB51 videos for the conv5 pre-trained by our MoSI on ImageNet [5], where the model locates prominent motions even without fine-tuning on the downstream dataset (See more in Sec. 4.1).
Despite their powerful capability of modeling dynamic variations between frames, the 3D convolutional models require a large amount of manually labeled videos to achieve a good generalized performance [14].
Recently, self-supervised learning has emerged as a powerful technique for training the model without labeled data in both image and video paradigm [54,12,21,6,36]. These methods learn visual representations by exploiting inherent structures of the unlabeled images or videos, for instance, by predicting the correct order of spatial or temporal sequences [54,6,9,26] or by predicting partial contents [12,13,36]. Because videos naturally have an extra axis of time compared to images, some methods manipulate the temporal dimension and predict the playback speeds [1,55]. Although some of the efforts were able to capture the motion information implicitly, almost none of them aims to model motion information of videos explicitly in a self-supervised fashion.
In this work, we seek to train the video model to directly distinguish different motion patterns. The objective is for the model to encode meaningful motion information, so that prominent motions can be discovered and attended to during fine-tuning. Since directly generating predefined motion patterns from a video set may be difficult, we leverage static images for motion generation. Formally, we propose a learning framework that learns motions directly from images (MoSI). Its general structure is shown in Fig. 1. Given the desired direction and the speed of the motions, MoSI generates pseudo motions from static images. By correctly classifying the direction and speed of the movement in the image sequence, models trained with MoSI is able to well encode motion patterns. Furthermore, a static mask (Fig. 3) is applied to the pseudo motion sequences. This produces inconsistent motions between the masked area and the unmasked one, which guides the network to focus on the inconsistent local motions. We term the one with and without static masks as MoSI and unmasked MoSI respectively. Conceptually, the idea of masked MoSI is closely related to attention learning, where the network learns to attend more to the moving areas in videos explicitly created by pseudo motion. Different from the attention mechanism [16,27,28], where attention is generated by carefully designed architectures, the attention learned by MoSI is achieved by purely altering the training data.
To the best of our knowledge, this is the first time that static images are used as the data source for pre-training video models. Using MoSI, we are able to exploit largescale image datasets such as ImageNet [5] to train video models. Although images contain less information about dynamics that are intrinsic in videos, the representations learned with MoSI can be as powerful as those learned using videos in terms of motion understanding. Extensive empirical studies with HMDB51 and UCF101 further demonstrate the effectiveness of MoSI. Compared with other previously published works, we show that the proposed MoSI reaches new state-of-the-art results for learning video representations using RGB modality.

Related Work
Motion learning by architectures. Motion information are crucial for understanding videos. There are mainly two popular architectures that are frequently used for extracting video features, respectively two-stream networks [44,8,51,40,4] and 3D convolutional networks [3,14,47,39,46]. Two-stream networks extracts motions representations explicitly from optical flows, while 3D structures apply convolutions on the temporal dimension [39,47] or space-time cubics [3,46,14] to extract motion cues implicitly. Besides these two architectures, different motion encodings are proposed to better handle motions in videos [28,17,50]. Compared to complicated structure designs that aim at better representing motions, our MoSI can take any video models as the backbone. For simplicity, structures proposed in [47] are adopted for our experiments.
Self-supervised image representation learning. Selfsupervised learning is proven to be a powerful tool for learning representations that are useful to down-stream tasks without requiring labeled data. Using image as data sources, there are patch-based approaches [6,33,32,34] that are inspired by natural language processing methods [31], and image-level pretext tasks, such as image inpainting [36], image colorization [56], motion segment prediction [35] and predicting image rotations [10]. The most similar to our work is [35], where labels are generated by grouping pixels that share the same movement together in videos. There are two crucial differences: (a) the aim of [35] is to learn pixels that belong to the same object by motion segmentation, while our MoSI is proposed to learn motion cues for understanding videos; (b) [35] exploits videos to learn image representations, while MoSI takes advantage of images to learn video representations.
Self-supervised video representation learning. With an extra time dimension, videos provides rich static and dynamic information, and there is thus an abundant supply of various supervision signals. A natural way is to extend patch-based context prediction to spatio-temporal scenarios, such as spatio-temporal puzzles [21], video cloze procedure [30] and frame/clip order prediction [26,54,9]. Besides the extension of image based supervisions, recent works propose to learn representations by predicting future frames [12,13]. In addition, supervision signals can be generated by purely manipulating the time axis. Representative works include speed up prediction [1] and play back rate prediction [55]. All previous video representation learning methods exploit videos as the data source. Hence, the motion patterns have not yet been able to be explicitly learned due to the difficulty of generating predefined motion patterns from videos. In this work, we take images as our data source, and generate deterministic motion patterns for directly learning motion representations.

Motion Learning from Static Images
The goal of MoSI is to learn motion representations. Because directly generating predefined motions from videos could be difficult, MoSI exploit images to generate samples for motion learning. Specifically, MoSI generates pseudo motions with different speeds and directions. To correctly predict the motion pattern, the 3D video backbone is required to distinguish different motion patterns. In addition, to mimic the actions in actual videos, where there exist inconsistent motions between the foreground and the background, we apply a static mask to the generated pseudo motions. In this way, the network is additionally required to locate prominent motion areas and attend less to the background. In short, there are two core components in the proposed MoSI, respectively the pseudo motions and the static masks, which will be discussed in Sec. 2 and Sec. 3.2 respectively. In the following sections, we refer to the framework as MoSI and unmasked MoSI respectively for the variants with and without static masks.

Pseudo Motions
The first component is the pseudo motions. The generation process is visualized in Fig. 1. Given the motion label (x, y) sampled from the label pool L, MoSI crops an continuous sequence of images u ∈ R N ×L×L from the input image (which we term as source image). N and L are selected in accordance to the number of frames and crop size in the downstream task. The generated pseudo motion sequence is then used as the input to the video backbone for motion classification. Label pool. The motion patterns generated by MoSI consists of two axes, respectively a horizontal axis and a vertical axis. The positive direction for them are respectively toward right and down, as in Fig. 1. For each axis, there are C = 2 × K + 1 speeds, where K denotes the granularity of the speeds in one direction (e.g., the positive direction on the horizontal axis). This corresponds to the motion speed set S = {−K, ..., −1, 0, 1, ...K}, where negative values indicate moving in the negative direction of the corresponding axis. K is set to be larger than 1, since we want the network to learn not only the existence but also the magnitude of motions. For simplicity, we decouple the motions for two axis, which means for each label, a non-zero speed only exists on one axis. Therefore, the total size of the label pool is C T = 2 × C − 1 = 4 × K + 1 with K labels for each direction and 1 label denoting static sequence. The label pool can be expressed as follows for each label index i: Note: It is crucial to generate motions for both axes, because the motion patterns in videos can be both horizontal and vertical. See Sec. 4.1 for the empirical results.

Start location End location Possible start area
Uniform sample Figure 2: Exemplar pseudo motion generation processes.
(a) and (b) generates motions respectively in the positive and negative direction of the horizontal axis. The start image is sampled randomly from the possible start area and the position of the end image is calculated using the distance D x and D y . The possible start area is determined so that the end image is located within the source image. N frames are uniformly sampled between the start and the end positions from the source image.
Pseudo motion generation. To generate the samples with different speeds, we define the moving distance from the start to the end of the pseudo motion sequences. For source image with the size of H × W , the distance − → D = (D x , D y ) for the pseudo motion of speed (x, y) ∈ L is defined as: Note that the value of D x and D y could be negative, which denotes moving in the negative direction of an axis. The start location − −− → l start = (x start , y start ) is randomly sampled from a certain area which ensures the end location − − → l end = − −− → l start + − → D is located completely within the source image, as demonstrated in Fig. 2. For example, if D x > 0, the distance between the right border of both the start image and the source image should be at least |D x |. For label (x, y) = (0, 0), where the sampled image sequence is static on both axis, the start location is selected from the whole image with uniform distribution. N images are then sampled with uniform gaps from the source image between the start position − −− → l start and the end position − − → l end . Classification. The generated image sequence u is then fed into a 3D backbone network and a linear classifier. Following [1,10], we employ the same-batch training technique, where each batch contains all transformed image sequences generated from the same source image. This means for each source image, C T image sequences of pseudo motions are generated and included in the same mini-batch. This is found to be significantly effective for reducing the artificial cues. The model is trained by cross entropy loss.

Static Masks
By correctly classifying pseudo motions with different directions and magnitudes, the model is able to recognize different motion patterns. However, since for most videos, actions occur in a constrained area rather than all the spatial locations, one is expected to recognize not only global motion patterns, but also inconsistent motions between the foreground and the background. Another drawback for the model to understand global motion is that the model will possibly focus on just several pixels, as all the motion patterns (speed and direction) in the image sequences are essentially the same. This creates an obvious artificial cue [6,12,53] that hinders the true capability of the model to understand motions. To this end, we introduce static masks as the second core component of the proposed MoSI.
Static masks divide the spatial location into two groups, respectively masked area and unmasked area, as in Fig. 3. The masked area is regarded as the background and the motions within this area is thus removed, by setting the content of this area in all images in u to the q-th image u q . On the other hand, the original contents (i.e., the motions) are retained in the unmasked area of the image sequence u. For simplicity, the unmasked area is by default a square area within the image, with the size of L m × L m . Formally, given the masked pixels m, the content of the p-th image is determined by: where (a, b) is the spatial location of a certain pixel, and q is the randomly selected static image. By applying the static mask, the background area of the image sequence becomes static and the foreground is moving according to the label. To perform correct classification, the model is now required not only to recognize motion patterns, but also to spot where the motion is happening. This benefits a lot for downstream tasks such as action recognition, as the model is equipped with knowledge on where to focus even before fine-tuning on the downstream datasets.

Instantiation
Data preparations. One advantage of the proposed MoSI is that it can train video models on both video datasets and image datasets. This allows for exploiting a large amount of existing image-based datasets. For video and image datasets, the only difference is that the source images need to be first sampled from the videos in the video datasets, while for image datasets, no frame-sampling step is required. Specifically, for video datasets, one frame out of each video is randomly sampled as the source image. Using the same-batch training technique, each image generates C T samples with different labels. We alter the sampled source frame index for different epochs for a larger variety of visual contents. After obtaining the source images, we resize the source image so that the length of the short side is L s . An L s × L s square area is randomly cropped from the resized image, which means H = W = L s in Eq. 2. This ensures that the motion magnitude for the same speed on both axis are the same. Augmentations. It is shown in previous self-supervised approaches that the model tend to learn some artificial cues or trivial solutions [6,12,53] that disrupts the learning of the designed objectives. In our case, we have introduced the static mask to avoid one possible trivial solution, where the model only need to recognize motions in an extremely small area for the prediction of the correct motion class. Based on that, we further randomize the location and the size of the unmasked area. In addition, we randomize the selection of the background frames in the MoSI. In Sec. 4.1, we closely investigate the effect of mask sizes and demonstrate the benefit of our randomization.  [41] of the conv-5 layer on HMDB51 over the models trained by MoSI on ImageNet ((a), (c)) and HMDB51 ((b),(d)) without fine-tuning. Red and blue areas denotes respectively highly and less activated areas. Although no semantic meaning has been taught through MoSI, models trained by MoSI already possess the ability to locate prominent areas according to the motions. In (a) and (b), we additionally compare with the value of optical flow calculated with x 2 + y 2 . It can be observed that most highly activated areas corresponds to regions where motions are significant.

Experiments
Datasets and backbone. For pre-training with MoSI, we employ three video datasets: UCF101 [45], HMDB51 [25], Kinetics [20], as well as the image dataset ImageNet [5]. For evaluation of the learned representation, we use UCF101 and HMDB51. We use R(2+1)D [47] with 10 layers as well as R-2D3D with 18 layers as our backbone, following the configurations in [54,12,13,55]. Self-supervised pre-training. For self-supervised pretraining, we set L s = 320 and resize the source image to 320 × 320 by default. Image sequences of length 16 and size 112×112 with pseudo motions are generated from each source image and fed to the model. The number of speed on each axis is set to 5, which is the minimal number for each direction to have distinct speeds. The total size of our label pool is thus 9. The side length of the unmasked area in our static mask L m is randomly sampled from [0.3, 0.5] × 112. Supervised action classification. During supervised training on UCF101 and HMDB51 for action classification, we train the network with a batch size of 128 samples per GPU for 8 GPUs using Adam with a base learning rate of 0.002 for 300 epochs. For evaluation, we follow the standard protocal [54,47] using 10 clips to produce the final results and report the results on split 1 on both UCF101 and HMDB51. Further details on both self-supervised and supervised training can be referred to the supplemental material.

Understanding MoSI.
In this section, we investigate the models trained by MoSI. We use R-2D3D with 18 layers in this section with the same structure as in [12]. The datasets used for pretraining and fine-tuning are the same unless otherwise specified. For each ablation experiment, only the inspected factor is altered and the rest of the settings are kept according to the ones described before. What has the network learned? We first establish some intuitive understanding of the method, by addressing the question of what has the model learned through MoSI. The Grad-CAM [41] visualization of the last layer in the pretrained model is shown in Fig. 4. Note that no fine-tuning is performed at this stage. As can be seen, the model has learned to pick up salient motion regions in the videos. Especially compared to optical flow, the model trained by MoSI highlights the region where the values of the optical flow is large. Furthermore, despite the model is only given pseudo motions as training data, it is able to transfer the knowledge onto real videos with more complex spatiotemporal relations to discover locate areas with a large motion across different frames. In addition, the prior square motion area does not constrain the model to only look for square areas with motions. Surprisingly, given only prior knowledge of one possible moving region, the model learns to generalize to find multiple prominent motion areas.

Static Horizontal
Vertical Combinations Combinations Figure 5: T-SNE visualization of clustering results on HMDB51. The representations are generated by unmasked MoSI for easy analysis, and without fine-tuning to directly evaluate the learned representation.
We further cluster the learned representation on HMDB51, as in Fig. 5. Although video data are naturally heterogeneous and consist of complex combinations of motions, we can still observe that the movements of a large portions of pixels in three of the five clusters are easily observable, which are vertical, horizontal and static. The motions in the other two clusters are hard to be uniformly described as the multiple movements are present at the same time. Baseline comparison. We then fine-tune the pre-trained model on the action classification task. As in Table 1, models trained with MoSI achieve notable improvements on both datasets. The improvement on HMDB51 reaches 16.5% when using both axes. The performances with only one axis are weaker compared to two axes, but they still outperform the baseline by a notable margin. On UCF101, the improvement of MoSI reaches 7.3%. However, the benefit of using two axes is smaller. This is partially because the motion cue can be of less importance in classifying UCF101 videos, where even using only one image could achieve satisfactory classification performance, as shown in [42]. Which parts of the representations learned using MoSI are the most useful? We further fine-tune the pre-trained weights with different stages of the learned representation frozen, as in Fig. 6. By gradually freezing the representations during fine-tuning, we observe only a small drop in the performance for the first three stages. On HMDB51, fixing one stage even improves the accuracy. This indicate that the models can learn a strong low-level representation  Figure 6: Performance of the model trained by MoSI when the representation is frozen to a certain extent. RI indicates training from random initialization, which is the baseline. The trend indicates the usefulness of the low-level feature learnt by MoSI. MoSI-x and -y indicates MoSI with label pool of respectively only horizontal and vertical labels.
from MoSI. Because MoSI focus less on the semantic understanding of the videos, only fine-tuning the linear layer does not have a high accuracy, which shows that the learned high-level representations are less discriminative. It is natural since the main objective of MoSI is for the network to attend to motions during fine-tuning. The only information that the model receives is different motion patterns, while to discriminate between actions, not only the motion pattern, but also the identity of the moving object need to be recognized. Nevertheless, fine-tuning the last stage on HMDB still gives an improvement of ∼ 5% over its random initialized baseline. Comparing between MoSI with different label pools, we also observe a pattern similar to Table 1: On HMDB51, the models trained using only one axis consistently underperform the two-axes MoSI, while on UCF101, there is not a clear benefit of using two axes.

Ablation Studies
Effects of mask sizes on MoSI. We then investigate the effects of different mask sizes by altering the side length of the unmasked area L m . The results are visualized in Fig. 7. In terms of the pre-training accuracy, we can see that the MoSI task is generally easy on UCF101, with the pre-training accuracy being 73% when L m /L is 0.1 and reaching 100% for 0.4. This is probably because of the numerous similar visual contents in UCF101 that cause the network to memorize the patterns. On the other hand, visual contents in HMDB51 have a larger diversity, thus the pre-training accuracy is lower compared to pre-training on UCF101 with the same parameters. For mask size ratio 0.1, the model can hardly learn to discriminate between different motions when the mask size L m = 0.1 × L s . This demonstrates that the proposed MoSI is not a trivial task that can be learned easily. Comparing different mask sizes, the validation accuracy during pre-training generally improves with the increase of the unmasked area. However, the high performance in our pretext task does not always mean a higher accuracy on the downstream task, which is also observed in [23]. Therefore, a suitable mask size is crucial to ensure a high quality of the representations. We then randomize the unmasked area within the range of L m = [0.3, 0.5] × L s and observe an improvement upon the variants with fixed mask sizes.
Effects of the speed granularity and the number of frames on MoSI. As in Table 2a Table 3: Low-shot fine-tuning on HMDB51. Top-1 accuracy is used for comparison with the baseline (trained from random initialization).
speed granularity. On the other hand, further increasing the granularity on top of 5 does not have a visible improvement as well. This means it is sufficient for the model to possess the basic ability to distinguish different speeds. For different frames, we fix the frame-wise distances for each label and alter the sizes of source images so that the only factor changed is the number of frames. Table 2c and 2d show that using 16 frames to pre-train MoSI achieves the best performance. One possible reason is that the downstream task also uses 16 frames for fine-tuning. Few/low shot fine-tuning. We also evaluate MoSI under a few/low-shot setting, where we randomly sample 3, 5, 7, 9, 11 and 13 videos from each class of the split 1 training set of HMDB51 as the training set for fine-tuning. This corresponds to using only around 4% to 20% of the original dataset. The results are demonstrated in Table 3. Pre-trained using MoSI, the model is consistently better than the random initialized counterpart by a large margin. This shows the effectiveness of MoSI on few-shot video classification. Training on ImageNet. Since MoSI is able to train video models from static images, we additionally use ImageNet as the data source for pre-training. We only use a small   Table 5: State-of-the-art comparisons.
portion of the original ImageNet data because the motion patterns can already be well learned on HMDB51 using only 5k videos. As in Table 4, we further validate that the performance in the pretext task largely depends on the number of data. Increasing the training data results in a higher validation accuracy before it saturates. In terms of the downstream task, the fine-tuning performance generally increases when the number of pre-training data increases before it saturates. Overall, the models pre-trained on Ima-geNet outperforms the ones trained on respective datasets.

Comparison with video-based methods
In Table 5, we demonstrate the performance comparison with the state-of-the-art video self-supervised training methods that only use RGB modality. Overall, MoSI performs competitively against other methods on both UCF101 and HMDB51. Compared to DPC [12] and MemDPC [13] with the same architecture MoSI achieves a much stronger performance on HMDB51. Note that DPC and MemDPC uses a 34-layer R-2D3D model with 224 × 224 as input, while MoSI uses an 18-layer R-2D3D with 112 × 112 as input. Using a stronger backbone R(2+1)D, we achieve the state-of-the-art performance on both UCF101 and HMDB51 datasets.

Discussions
Previous sections have shown that the proposed MoSI framework can train the model to focus on a local area with prominent motions. Despite that the models trained by MoSI achieves a satisfactory improvement on the action recognition task by learning to attend to motions, there are certain limitations. (A) Because of the square shape of the prior unmasked motion area in MoSI, in some cases, the model is somewhat biased toward attending to a square area as visualized in Fig. 8(a). (B) Because no semantic information is encoded during MoSI training (see Sec. 4.1), major movements in the background could also confuse the model, as in Fig. 8(b).
Conclusion. This work proposes MoSI, a simple framework for the video models to learn motion representations from images. It is shown that MoSI can discover and attend to prominent motions in videos, thus yielding a strong representation for the downstream action recognition task. We also demonstrate the possibility of using MoSI to train video models on image datasets. It is hoped that this research can inspire further study in understanding how motions can be encoded into video representations.

A. Appendix
Further training details. During the self-supervised pretraining, we use Adam [22] as our optimizer and use the learning rate of 0.001. The batch size is 10 source images per GPU for 16 GPUs. We use warm-up [11] of 10 epochs starting with a learning rate of 0.0001 and the total number of epochs is 100 except for kinetics, where 2 warm-up epochs and in total 20 epochs are used to train the model. A half-period cosine schedule [29] is adopted. A dropout of 0.5 is used during the pre-training of the video models. Besides the MoSI-specific augmentations, including random sizes and locations of the static mask, we also apply a frame-wise random color jittering following [12,13], for the model to learn not only low-level pixel-correspondence, but also semantic correspondences. The weight decay is set to 1e-4. During fine-tuning on the downstream action classification task, warm-up is applied with a starting learning rate of 1/10 the base learning rate. The weight decay is set to 0.001. Ten warmup epochs is used and the model is trained in total for 300 epochs. Data augmentation include spatial random crop, random horizontal flip, and clip-wise random color jittering with the same parameter as in self-supervised training.