Data augmentation is a key method in Machine Learning and Computer Vision to expand training data by applying diverse transformations to existing samples. Aiming to improve the model's generalization to unseen data, reduce overfitting, and address the challenges posed by imbalanced datasets where certain classes have fewer samples, this method enhances the model's robustness by exposing it to different orientations, lighting conditions, scales, and perspectives in computer vision tasks (e.g. image classification, object detection, segmentation). This approach finds practical application in fields like medical document analysis and quality control in manufacturing.

The Study

A two-month study was performed to optimize a document image classification transformer model adapted for document image analysis using data augmentation techniques. The study focused on exploring the potential of data augmentation to enhance the model's accuracy and address imbalances present in the "Tobacco3482-jpg" open-source dataset.  

Enhancing the model's precision through data augmentation not only holds significance for academic advancements but also presents a tangible avenue for tackling practical hurdles in domains like identity verification, fraud detection, digitization of archival materials, streamlining administrative documents processing and historical document preservation.

But, before analyzing the experimental method we followed and our findings, let's start with the basics: 

What is document image classification? 

Document image classification is a computer vision task of classifying documents based on images of their contents. It is a critical task with diverse applications. However, achieving high accuracy faces challenges due to scarce labelled data and diverse document classes.

What model did we use?

The transformer model used in this study is called DiT (Document Image Transformer) [1], a self-supervised pre-trained transformer model with the following characteristics:

  • It uses large-scale unlabeled text images for Document AI tasks, and it consists of approximately 87 million parameters.
  • It applies the self-supervised objective of BEiT (BERT pre-training of Image Transformers) to 42 million document images, allowing for state-of-the-art results on document image classification.
  • It is fine-tuned on four Document AI benchmarks, encompassing document image classification, document layout analysis, table detection, and text detection.
  • It was fine-tuned on the RVL-CDIP dataset, a collection of 400,000 images, to enhance its capabilities and adapt it for the specific task.
Figure 1: The model architecture of DiT
What dataset did we use?

The "Tobacco3482-jpg dataset" used in this study includes the following classes: Advertisement (ADVE), Email, Form, Letter, Memo, News, Note, Report, Resume and Scientific. The table below showcases the number of files included in each class, marking the level of dataset imbalance. 

ClassesNo of files
Advertisement231
Email600
Form432
Letter586
Memo621
News189
Note202
Report266
Resume121
Scientific262

Each of these classes represents a specific type of document, and accurately classifying them can significantly benefit document-related tasks, information retrieval, and content management across various industries and use cases.

Our experimental approach

To enhance the model's accuracy, we kept the model architecture and hyperparameters constant and modified the training data by experimenting with various data augmentation techniques specifically chosen to address actual problems encountered in document processing. 

The training data used for experimenting with the aforementioned data augmentation techniques were modified to meet the experimental needs. Specifically, we applied rotations of various degrees and flipped documents along horizontal and vertical axes, enabling the model to generalize better. Changes in perspective were introduced to mimic capturing documents from different angles or on non-flat surfaces. Augmentations related to lighting conditions and colour variations helped the model become more robust to diverse image qualities. Moreover, cropping at multiple positions allowed the model to recognize essential content, regardless of its location, further enhancing classification effectiveness. The addition of random dark and bright pixels simulated noise often present in scanned or digitized document images. Finally, zooming out the images provided a broader view, enabling the model to capture intricate details.

Accuracy results:

The table below presents the accuracy results for different augmentation combinations. Starting with 94.3% accuracy, we observed incremental improvements as we introduced various augmentations. The final combination, which included rotation, horizontal flip, brightness and hue adjustment, salt and pepper noise, perspective, five-crop, and zoom-out, achieved the highest accuracy of 96.5%.

Augmentations Accuracy (%)
No augmentation applied94.3
Rotation (2 degrees), Horizontal Flip, Brightness and Hue94.3
Rotation (2 degrees), Horizontal Flip, Brightness and Hue, Salt and Pepper Noise94.9
Rotation (2 degrees), Horizontal Flip, Brightness and Hue, Salt and Pepper Noise, Perspective95.22
Rotation (2 degrees), Horizontal Flip, Brightness and Hue, Salt and Pepper Noise, Perspective, Five Crop, Zoom Out96.5

Table 1. Accuracy results achieved for different data augmentation combinations. {style="height: 374px; width: 479px; border-style: double; background-color: #dee8e3; border-color: #242138; margin-left: auto; margin-right: auto;" width="479"}

Conclusions

In conclusion, our study highlights how data augmentation can significantly improve the accuracy and effectiveness of document image classification models. Throughout our experimental activities, we successfully tackled existing challenges of the implementation of data augmentation by carefully choosing and combining various techniques, making the model stronger and more efficient, even though we used limited labelled data and imbalanced classes.

Examples of augmented images

Some indicative examples of images that were created using augmentation methods are the following: 

Rotation (6 degrees), Horizontal Flip, Brightness and Hue

Figure 2. Example of a document with 6-degree rotation, horizontal flip, brightness, and hue modifications.

Rotation (-6 degrees), Salt and Pepper Noise, Brightness and Hue

Figure 3. Example of a document with -6 degrees rotation, salt and pepper noise, brightness and hue modifications.

Rotation (2 degrees), Horizontal Flip, Salt and Pepper Noise, Perspective

Figure 4. Example of a document with 2 degrees rotation, horizontal flip, salt and pepper noise and perspective transformation.

Horizontal Flip, Brightness and Hue, Salt and Pepper Noise, Crop (top left), Zoom Out

Figure 5. Example of a cropped (upper left) document, horizontally flipped, with brightness and hue modifications, salt and pepper noise and "Zoom Out" transformation.

 

Reference

[1] Li, J., Xu, Y., Lv, T., Cui, L., Zhang, C., and Wei, F. “DiT: Self-supervised Pre-training for Document Image Transformer”, October 10–14, 2022, Lisboa, Portugal (pp. 10 pages). ACM, New York, NY, USA.

 

* This study was performed by Artemis Androni, an undergraduate MEng student at the National Technical University of Athens, under the guidance of Eleanna Koulettou, LIBRA AI Data Scientist, in the framework of her two-month internship at LIBRA AI Technologies.