# Detection of Marine Oil Spill from PlanetScope Images Using CNN and Transformer Models
## 3 Method
### Dataset Preparation  
The satellite and labeled images were divided into 256 \(\times\) 256 pixel segments, considering the dimensions of the oil spills and the efficacy of the model learning process. To avoid biased learning toward a specific class, it is important to ensure that the ratio of pixels between classes does not differ significantly. Images containing a significant proportion of land, clouds, or null values were excluded to maintain a relatively consistent ratio between marine oil spill and background classes. As a result, 260 sets of satellite images with blue, green, red, and NIR channels, along with their corresponding labeled images, were prepared.  
The test results of a deep learning model trained with a limited dataset can vary depending on how the dataset is partitioned, potentially leading to an inaccurate assessment of the model's performance. To evaluate the model's generalization performance, we conducted five rounds of training and assessment using k-fold cross-validation. The 260 datasets were initially divided into five random samples, which were then used for training, validation, and testing. Each round was configured with three folds for training,one for validation, and one for testing, resulting in a ratio of 6:2:2 for the training, validation, and test sets, respectively (Figure 3).  
Overfitting can occur when the training dataset is insufficient, leading to predictions biased toward specific data subsets. To mitigate this issue, we employed data augmentation techniques to expand the datasets and help the model learn diverse patterns. Data augmentation can prevent overfitting, enhance the generalization performance, and contribute to the development of more robust models. It is crucial to ensure that the original dataset and its augmented versions are not included in the training and test groups simultaneously, as this could lead to data leakage, resulting in an overestimation of the model's performance and distortion of the actual results. Therefore, data augmentation was implemented within each separated fold during the cross-validation process. The open-source data augmentation library Albumentations was used to apply geometrical and spectral transformations to the images, including rotation, flipping, optical distortion, grid distortion, RGB shift, and brightness/contrast adjustments. The original 260 images were augmented tenfold, resulting in 2600 datasets. Of these, 1560 were used for training, 520 for validation, and 520 for testing (Figure 4).  
To enhance the stability of the model, the pixel values of the input data were normalized. Instead of using min-max normalization, which can be susceptible to issues arising from extreme values, we utilized z-standardization. This method is more robust in handling outliers by using the mean (\(\mu\)) and standard deviation (\(\sigma\)) of the data. The mean and standard deviation for each channel were calculated, and all pixel values were normalized using the z-score formula. This normalization process ensures that the input data has a mean of zero and a standard deviation of one, enhancing the model's convergence during training. Each pixel value \(z\) is calculated using Formula (1):  
\[z=\frac{x-\mu}{\sigma} \tag{1}\]  
where \(z\) represents the z-score, \(x\) is the value being standardized, \(\mu\) is the mean of the dataset, and \(\sigma\) is the standard deviation of the dataset.  
Figure 3: Concept of the 5-fold cross-validation in this study.