{'fraction_non_alphanumeric': 0.02833207492899004, 'fraction_numerical': 0.005141480602595908, 'mean_word_length': 4.393445801822765, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 6, '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}}
Robust Detection of Objects under Periodic Motion with Gaussian Process Filtering

Object Detection (OD) is an important task in Computer Vision with many practical applications. For some use cases, OD must be done on videos, where the object of interest has a periodic motion. In this paper, we formalize the problem of periodic OD, which consists in improving the performance of an OD model in the specific case where the object of interest is repeating similar spatio-temporal trajectories with respect to the video frames. The proposed approach is based on training a Gaussian Process to model the periodic motion, and use it to filter out the erroneous predictions of the OD model. By simulating various OD models and periodic trajectories, we demonstrate that this filtering approach, which is entirely data-driven, improves the detection performance by a large margin.


I. INTRODUCTION
Object Detection (OD) is a Computer Vision task consisting in localizing members of a given object category in an image [1]. In practice, this is done by predicting rectangular Bounding Boxes (BB) coordinates to encompass the studied objects in an image. Throughout the last decades, OD has been widely studied and huge progress has been made with the appearance of deep learning based approaches [2]- [7]. A complete survey of the OD literature is beyond of the scope of this paper. Nonetheless, two recent surveys can be found in the literature [8], [9].
In this paper, we consider the specific case of OD in streams of images, where the objects to be detected are having a periodic motion in the video frames. In order to better understand this setting, two practical use cases are presented in Fig. 1. In Fig. 1a, an OD model is running on the frames recorded by a fixed camera, to detect objects equally spaced on an automated production line. This scenario has important practical applications in industry [10]- [12], where a strong OD model can serve to detect missing parts or to identify regions of interest to conduct more precise quality analysis. On another note, in Fig. 1b, the observed object is fixed but the camera, mounted on a robotic platform, is moving under a periodic motion. Autonomous drones, equipped with cameras and having periodic motions, also have many practical applications such as crops monitoring [13], damage identification in infrastructures [14] or intrusion detection [15]. In these scenarios, robust methods for detection of fixed objects can serve directly to conduct these analyses or as a way to improve localization algorithms. In both cases, the expected BBs appear periodically in the video frame and have the same spatio-temporal trajectories, eventually with some noise.
(a) A fixed camera running OD on equally spaced objects on a conveyor belt (b) A drone with a periodic motion running OD on fixed objects. In previous works, different computer vision problems dealing with objects in motion have been studied. For instance, the similarity between frames has been measured in order to identify and characterize periodic motions [16]. Käs and Nicolas carried out an approach for trajectory estimation from compressed video files [17]. A survey about the identification of patterns in spatiotemporal trajectories has been proposed [18], as well a method for pixel-level identification of moving objects in video [19]. Finally, the periodic motion of the studied objects has been leveraged in order to conduct better anomaly detection [20]. In this paper we aim to leverage the periodic motion to improve the performance of an OD model. To the best of our knowledge, despite its relevance in various practical applications, this problem has never been formally studied.
In the setting of this paper, we consider that an object detection model is already available for the studied objects, but that it is imperfect, i.e. making recognition errors (both false positives and false negatives). Such weak object detection models can occur when few training data are available or when training is performed on 3D CAD models, among other reasons. Under the only assumption that the detected objects have periodic trajectories in the video frames, we aim to propose a post-processing method to filter out the wrong OD predictions. In order to do this, training data are first gathered by running the OD model on the real system and recording the predicted BBs. These spatiotemporal data are then used to train a Gaussian Process [21] (GP) to model the periodic trajectories of the BBs. Finally, at inference time, a set of rules on the GP predictions is proposed to discard the wrong predictions of the OD model. We note that in the case where the false positive ratio of the initial OD model is too high, a manual data cleaning of the GP training set must be performed, otherwise an automated outlier detection method, based on DBSCAN clustering [22], is proposed in this work.
Our approach is validated on realistic simulated data generated from different periodic trajectories, different levels of initial OD performance, and different levels of noise in the BBs positioning. The results on these datasets show that the proposed GP filtering approach can improve the initial OD model precision-recall curves by a large margin. Besides improving OD robustness, this method also has the advantages of being fast, easy to train and it requires no prior knowledge about the objects motion.
The paper is organized as follows. First, notations are introduced and preliminary concepts necessary to understand the approach and its experimental validation are presented in Section II. Then, in Section III, both training and inference steps of the proposed GP filtering method are explained in details. The proposed validation on realistic synthetic datasets is presented in Section IV, together with the discussion of the results. Finally, conclusions and directions for future work are exposed in Section V.

II. PREREQUISITES AND NOTATIONS
In this section, the notations used throughout this paper are introduced and some essential concepts to understand the method are presented. All along this paper, the different steps of the method are illustrated using a simulated toy example.

A. Characterization of an OD model
Let ϕ θ be an object detection model, which weights θ have already been optimized with respect to the detection task at hand. For a given image I, ϕ θ (I) returns a list of (l, c, s) tuples, where l consists of four coordinates that identify a Bounding Box (BB), c is the predicted category of the object in the BB, and s is the confidence score that the BB contains object c. In order to simplify the notations, we consider that ϕ θ is trained to recognize a single object. Thus, predictions can be represented by (l, s) tuples only. Extending the method to multiple objects simply consists in independently replicating the approach for each of the predicted classes.
For a specific inference situation, e.g. OD on a given production line, the model performance is fully characterized by its precision-recall (PR) curve. In order to better explain what a PR curve is, we need to introduce some intermediate concepts. First of all, we introduce the confidence threshold τ s , such that a given prediction (l, s) is kept if s > τ s and discarded otherwise. Then, for a given ground-truth BB l * , we define the Intersection over Union (IoU) of l and l * as the ratio between the intersection area and the union area of the two BBs. After fixing a threshold on IoU (τ IoU ) that complies with the expectations of the application, we can state that l an l * represent the same object if IoU(l, l * ) > τ IoU . From these definitions, we can then say that a detection (l, s) is a true positive (TP) if s > τ s and if there exists a ground truth BB l * such that IoU(l, l * ) > τ IoU . If there is not any ground truth satisfying the latter condition, (l, s) is a false positive (FP). Conversely, when a ground truth BB is left without any matching predicted detection, it counts as a false negative (FN). Finally, in case multiple predictions correspond to the same ground-truth, only the one with the highest confidence score counts as a TP, while the others are considered FP.
With the above definitions, for a given dataset, we can then define precision as the total number of TP divided by the total number of model predictions: A high precision means that most of the predicted BBs had a corresponding ground truth. In other words, the object detector is not producing bad predictions. On the other hand, recall is defined as A high recall means that most of the ground truth BBs had a corresponding prediction. In other words, the object detector finds most objects in the images. Both Recall and Precision vary between 0 and 1, where 1 means perfection. For a given OD model ϕ θ , the values of Precision and Recall changes for different values of τ s . Hence, to characterize ϕ θ , we use the Precision-Recall curve, which is plotted by sampling different values of τ s and reporting the corresponding PR points in the plot. Besides the model and the value chosen for τ IoU , the PR curve also depends on the test dataset on which it is computed. For this reason, we talk about the PR curve with respect to a specific inference situation, as the model could perform differently in another environment. The PR curve of the model used for the simulated toy example is presented in Fig. 2. It can be observed that, for a recall of 0 (τ s = 1) the precision is 1, which makes sense as when there is no prediction at all there is also no wrong prediction. Then, when τ s decreases, the number of predicted BBs increases, thus making the recall increase and the precision decrease.

B. Periodic trajectory of an object
In the setting studied in this paper, the object that must be detected by ϕ θ has a periodic motion with respect to the video frames. This periodic trajectory is defined in the three-dimensional space (x, y, t), where x and y are the pixel coordinates in the video frames and t is the time. A spatiotemporal periodic trajectory (Γ, T ) is represented by both • a period T , • a nominal function Γ : t − → {x, y}, defining the position of the center of the object in the video frame at a given time. Γ is defined in R + , and we have Γ(t+T ) = Γ(t). We also note that Γ output can be Null when the object is not in the video frame. The periodic trajectory used for the simulated toy example is shown in Fig. 3. When time passes, the object enters the image plane, the center of the BB moves along the line shown in Fig. 3a before exiting the video frames, this process is repeated periodically. The period T is the time between two corresponding points in the trajectories (Fig. 3b), for this case it is 8 seconds. The t-x view of this toy trajectory is not presented here as it does not provide much additional information.

C. Generate a simulated periodic OD process
Once the PR curve of the OD model ϕ θ and the periodic trajectory of the object (Γ, T ) have been defined, the entire OD process of the periodic system can be simulated for any fixed value of the recall. In order to do this, we first need   to discretize the time such that each time step corresponds to a video frame recording and OD BBs prediction. For each simulated video frame, (Γ, T ) is used to define the true position of the BB center. Then, for a given recall value, the PR curve can be used to know the corresponding precision and to compute both P F N and P F P , respectively the probability to fail detecting the object and the probability to detect a wrong object. For a given total simulation time, these probabilities are defined as where N frames is the number of frames in the generated simulation and N obj is the number of frames in which an object is actually present. The formula in equation 4 is simply the expected proportion of false positives with respect to the total number of simulated frames. Once P F N and P F P are known, the OD prediction can be easily simulated frame after frame by sampling the true and false BBs. In addition to simulating the imperfect OD model and the physics of the problem (periodic trajectory), we also add noise to both the (x, y) location and the time recording. The former accounts for the errors in the trajectory and the errors in predicted BB positions, while the latter accounts for errors in the time measurement process (e.g. communication lag). In practice, for our toy example a new frame is simulated every 0.1 second (sampling time). We use Gaussian noise with mean 0 and standard deviation of 0.1 for position (diagonal covariance matrix) and 5 × 10 −3 for time. Three periods of the noisy simulated OD data for the toy problem can be seen in Fig. 4.

III. PROPOSED APPROACH
An overview of the approach proposed in this paper can be seen in Fig. 5. It consists in gathering training data by running the real world OD system for some periods and recording the center of the predicted BBs as well as their associated time. Then, these noisy data are pre-processed in order to align the trajectories and filter the false positives. The clean data are then used to fit a Gaussian Process model which predicts the time from the xy coordinates of a BB center. At inference, when a new BB is predicted by the OD model, the trained GP model is used to filter out wrong boxes in real time. In this section, the different steps of the proposed periodic OD filtering approach are presented in details. The toy example presented in Section II is used to illustrate these steps.

A. Gaussian Process training
First, the methodology to fit a GP model to the periodic trajectory is presented in the following steps.
1) Collecting training data: The collection of training data consists in running the real OD system for a number of periods N , defined by the user. To run the real OD system, a point in the PR curve of the OD model ϕ θ should be selected by fixing the value of τ s . A configuration with high recall should be selected in order to get sufficient TPs for the GP training. In practice, the best results were obtained for recall= 0.9, and we found that N = 5 is sufficient to train a good filtering model. Then, for each prediction made by ϕ θ , the BB center as well as the time since the beginning of the experiment are recorded. This generates a set of three-dimensional data points (x, y, t). Fig. 4 shows the projection on the ty-plane of this dataset for the toy example with N = 3.
2) Aligning training data: In order to align training data, the period T of the object motion needs to be identified. To do this, we leverage the fact that the density of points is lower when the object is not actually present in the frame. Indeed, between two object appearances in the video, the predictions only consist of FP, whereas when the object is present there are both TP and FP. Hence, in order to identify the period T , we run a density-based clustering algorithm (DBSCAN [22]) on the one-dimensional projection of the training data along the t-axis. In practice, we use the scikit-learn [23] implementation of DBSCAN with eps = 0.5, min samples = 5 and euclidean distances. Fig. 6a shows the DBSCAN clusters assignment for the training set gathered from the toy example, with N = 3. Once the clusters representing different trajectory instances have been identified, the estimated period T can be computed as follows: where M ed is the median, |C| is the total number of defined clusters, and t i min (respectively t i max ) is the smallest (respectively larger) time value of cluster i. Eq.(5) simply estimates the distance between corresponding points in two consecutive clusters. Considering both first and last points, as well as using the median, reduce the potential risk of error from including a FP at the extremity of one cluster. Once the period has been estimated from the noisy data, they can be aligned using the modulo operation, by replacing the t component by t mod T (Fig. 6b).
3) Cleaning training data: To remove the outliers (FP) from the aligned training set, we rely on the fact that the density of points should be higher where objects were actually present. In fact, after alignment, there should be around N points (maybe less in case of FN) in the neighborhoods of true predictions, whereas there is no reason for such pattern for FPs. Hence, a second stage of DBSCAN clustering is applied to the (x, y, t mod T ) 3-dimensional data. The optimal DBSCAN hyper-parameters for this step depend on the number of training period N (estimated from the data) and the noise in the point locations (unknown). Hence, we set the number of neighbors (min samples) to 0.8×N and the optimal eps is computed using the elbow method [24]. Fig. 7a shows the results from this clustering on the toy example (N = 3), all point belonging to a cluster are displayed in green while others are in red. The clean aligned training data obtained after removing the outliers can be seen in Fig. 7b.

4) Gaussian Process training:
The clean aligned training set presented above is then used to fit a GP model GP to the object spatio-temporal trajectory. A GP is a non-parametric Bayesian regression approach that finds a distribution over the possible functions that are consistent with the observed data. For a detailed overview of Gaussian processes, we refer the reader to [21]. In order to be useful for BB filtering, GP is fit to model the following function:    In other words, we want to train a predictive model such that, for every pixel in the image, we can predict the trajectory time at which the center of the object is supposed to be at this location. The main advantage of using a GP model is that, for a given input point (x, y), it does not only return the predicted valuet but also the standard deviation of the model at that precise input pointσ. The latter can serve as a proxy for the uncertainty of the model at a given input pixel, it depends on the distance from the closest points seen by the model during training. Having this information is very useful to define a BB filter directly from data, as shown latter in Section III-B.  from Fig. 7b. We can see that along the object trajectory, GP is highly confident about its prediction, and the uncertainty increases as we move away from the nominal trajectory line. 5) Manual data cleaning for bad initial OD model: As shown later in the experimental results (Section IV), when the initial OD model ϕ θ is bad, the approach presented to align and clean training data does not work well. This is because there are too many outliers between trajectories and the clustering fails to identify the period T . When this happens, one can fix this problem by manually removing the FPs in the training data before running the data alignment step. After this initial manual cleaning, the approach is the same. Both automatic and manual data cleaning are evaluated in our experiments for different initial OD models.

B. Online bounding box filtering at inference time
After GP has been trained by following the approach presented above, it can be used to improve ϕ θ robustness on the periodic OD task at hand. This is done by filtering BBs online as soon as they appear, in real time. In order to do this, we first need to compute the maximum of uncertainty across all training samples σ max . Then, when a new frame is recorded, we run ϕ θ to obtain BBs predictions. If a BB passes the thresholding test on confidence scores (s > τ s ), its center (x, y) is given as input to GP for time prediction: {t,σ} = GP(x, y).
Then, two filtering tests are computed on the predictions: where t is the cyclic execution time (t = t mod T , with t being the time since the beginning of the execution). If Eq.(8) is true, it means that the point is close to the nominal trajectory of the object. If Eq.(9) is true, it means that the predicted time corresponds to the actual time of the experiment. Hence, when both conditions are true, it means that the predicted BB is at the right location and at the right time, where the object is supposed to be. In this way, the GP filtering step consists in running both tests on every predicted BB and discarding any prediction that fails at least one of them. We also underline that when the starting time for inference does not match the starting time for the training sample trajectories, the first few predictions verifying condition of Eq.(8) can be used to match prediction time and run time.
After applying this method, some bounding boxes are removed by the GP filtering. On the one hand, if the training went well, most of the boxes discarded should be FPs and, for a given recall value of the original ϕ θ model, the post-filtering precision should be higher than the original precision. On the other hand, as some TPs might also be removed while no FNs are removed, the post-filtering recall is lower or equal than the original recall. However, if, as expected, the filter removes significantly more FPs than TPs, the confidence threshold τ s can be lowered in order to increase the initial recall without lowering the precision, thanks to the filtering. To evaluate the impact of the GP filtering approach, we can run the inference process presented here for all possible values of the initial ϕ θ recall. Then, by computing the post-filtering recall and precision for each of these values, we can compute the postfiltering PR curve. The new PR curve obtained after filtering for the toy problem can be seen in Fig. 9. It was computed on a validation set composed of 10 simulated noisy periods. We can see that the post-filtering curve is always above the PR curve of the original model, which means that it performs better. A quantitative comparison for different PR curves and trajectories is proposed in Section IV.

A. Experimental setup
In order to test the GP filtering approach presented in Section III, we propose to study the behavior for three different nominal trajectories and four different OD models, characterized by their PR curves. The PR curves of the 4 simulated OD models are shown in Fig. 10. As we can see, they are indexed such that if i > j, PR i is better than PR j . Likewise, Fig. 11 represents the nominal trajectory lines in the image plane for all three simulated trajectories used for evaluation. In order to assess the ability of the GP to model different kind of trajectories, we selected one straight line, one convex curve and an oscillating function. For all trajectories, the period T is set to 8 seconds and the time for an object to traverse an image to 5.2 seconds. The evaluation of the proposed method consists in comparing the OD performance before and after filtering, for all 12 possible combinations of trajectories and PR curves. Finally, we note that the toy problem studied all along this paper corresponds to PR 3 and Γ 3 . x y 1 2 3 Fig. 11: Nominal support lines for the 3 simulated periodic OD trajectories used to evaluate our proposed GP filtering approach.

B. Quantitative Analysis
As already mentioned, OD models performance can be compared qualitatively by visually analyzing their PR curves. However, in order to conduct a formal objective evaluation, it is better to compare models quantitatively, using relevant numerical metrics. The most commonly used metric to evaluate an OD model is called mean Average Precision. For single class object detection it is simply Average Precision (AP) and it is the mean precision across all possible values of recall. It is defined as the area under the PR curve: However, it has recently been argued that AP fails to accurately evaluate models for practical scenarios [25]. Indeed, in practice, a model will be used for a single value of the threshold τ s and thus at a single point in the PR curve. For this reason, it might be better to evaluate a model by its performance at the optimal PR configuration. Hence, we also introduce the optimal F1-score metric (oF1), which is a variant of oLRP [25]. This new metric is introduced because we do not consider the width and height of the bounding boxes but only their centers in the simulated scenarios studied. In this sense, the localization component of oLRP cannot be computed. To define oF1, we first need to introduce the F1-score, which is the harmonic mean of the precision and recall: From this definition, we can evaluate F1 for all points along the PR curve of a model and choose the precision recall pair with highest F1-score as the operating point for the OD model. This way, the oF1 score of a given model is the value of the F1-score at this operating point. It represents the precisionrecall balance of a model in its best configuration and has values in [0, 1]. An oF1 score of 1 means that there exist a confidence threshold τ s such that the model finds all ground truth BB and does not produce any FP. The results obtained for the 12 simulated configurations presented above are shown in Table I. For a given metric, the gain in performance by applying the proposed GP filtering approach can be measured by comparing the post-filtering results (Auto cleaning or Manual cleaning) with the reference value of the original model. The bold numbers represent the cases in which there is a gain in performance. C. Discussion Table I shows that for all tested OD models and trajectories, if a manual cleaning of training data is performed, the filtering provides an important performance gain, especially for the worst initial models. For example, the original PR 1 model does not have any threshold configuration leading F1-score higher than 0.714, whereas after filtering oF1 is higher than 0.94 for all three trajectories. Manual filtering simply means removing the FPs produced by the model in the few trajectories recorded for training, which is not such a tedious and complicated task regarding the potential gain in performance obtained. Furthermore, we can also see that when the initial model gets better (PR 3 and PR 4 ), the cleaning method presented in Section III can automatically handle the training data preprocessing. This means that if we can train a good OD model for a task where the object has a periodic motion, substantial improvement can be obtain with very little human effort, simply by recording a few periods of time and running our automatic method.

V. CONCLUSION
In this paper, we proposed a method to improve robustness of OD models for cases where the object of interest has a periodic motion with respect to the video frames. Our approach consists in gathering a training dataset by running the real system for some periods of time and fitting a Gaussian Process regression model to the observed (x,y,t) positions. This GP is then used at inference time to identify the FPs within the BBs predicted by the OD model. Our approach was tested in simulations for different OD models and trajectories. The obtained results show that this filtering can significantly increase the OD performance for the periodic system.
Several potential directions for future work have been identified. First, the method should be validated on real systems, such as the ones presented in Fig. 1. Data for this evaluation are currently being gathered by our team to enrich the experimental validation of our approach. Second, more characteristics of the BBs (height, width) could be used as input for the GP filter in order to have more accurate time prediction and by extension more accurate FPs removal. Finally, the approach proposed in this paper for period identification fails for cases where the object never leaves the video frame. Small adaptation can be made in order to succeed in such cases, e.g. running clustering directly in the xy-plane. However, this should be better formalized and tested in the future.