# BaDLAD
The Dataset paper is available at: https://arxiv.org/abs/2303.05325.

# About the Dataset
The dataset for this competition comprises about 34,000 Bengali documents annotated using polygon boundaries and rectangular bounding boxes. These documents range from newspaper articles, official documents, notices, and government gadgets to novels, comics, magazines, and even liberation war records.


<img src="https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F10747121%2F5174eee762e639cc95d3947559af144f%2FIMG_0052.png?generation=1687142796077441&alt=media"  width="90%" height="30%">

<img src="https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F10747121%2F326a661f994df5d01e0a697a1eeded42%2FIMG_0053.png?generation=1687142841349263&alt=media"  width="90%" height="30%">


The annotations specify the regions in these documents that fall into 4 classes - 
- Paragraph
- Text Box
- Image
- Table

Your task is to design a deep learning pipeline that takes in a document image (`.png`) and predicts bounding polygon segments (masks) for each occurrence of the classes mentioned above in the input image. 

# Data Details
There are 20,365 training and 13,000 test images. The `train` and `test` images can be found in in `badlad/images/` directory, whereas the labels for the `train` dataset can be found in `badlad/labels/` directory. 

## Train

Training set images are in `badlad/images/train`. 

The `train` images have `labels` corresponding to them. For your convenience, we provide 2 forms of labels:
1. **COCO Format**: `badlad/labels/coco_format/train` 
    The COCO format labels are in `badlad-train-coco.json` file. This `JSON` file has some notable fields:
   1. `categories`: Maps instance categories to their assigned IDs. 
   2. `images`: Maps image IDs (`id`) to their hashed name, height, and width. 
    For example,

        | ImageId | Width | Height | ImageFile | FilePath |
        | ------- | ----- | ------ | --------- | -------- |
        | 0 | 720 | 995 | `846df66a-610e-4356-b369-6788885a0dc5.png` | `badlad/images/train/846df66a-610e-4356-b369-6788885a0dc5.png` |
    
   3. `annotations`: This is a list of the polygon bounding segments for each instance of the categories occurring in each image. The contents of this category are the crux of the problem:
      - `segmentation`: Polygon `(x, y)` coordinate pairs of it's vertices. 
For example, the first annotation has its first vertex at `(86.328, 179.007)`. The following pairs complete the polygon region of the annotation. 
      - `image_id`: The image this annotation is for. 
      - `category_id`: The category this annotation is bounding. It may be a paragraph, text box, image, or table. 
      - `id`: Annotation ID, identifies each annotation. 
      - `bbox`: The rectangular bounding box that best estimates the annotated region. 
    
    This list holds all the annotations for each instance of the categories for all images. 

2. **YOLOv8 Format**: `badlad/labels/yolov8_format/train`
    Each training image has its label as a text file of the same name in the mentioned directory. 
    For example,

    | Image | Label |
    | ----- | ----- |
    | `badlad/images/train/846df66a-610e-4356-b369-6788885a0dc5.png` | `badlad/labels/yolov8_format/train/846df66a-610e-4356-b369-6788885a0dc5.txt` |

    You can read more about the expected YOLOv8 data format [here](https://docs.ultralytics.com/datasets/segment/).

## Test

Test set images are in `badlad/images/test`. 

The test set has no provided annotations. Your task is to learn the bounding polygon from the train set and predict it for the test set images. 

However, the test set does have metadata associated with each image. That metadata can be found in `badlad/test-metadata.json`. This `JSON` file consists of all the fields of the training labels *except the annotations*. 

# Predictions

Your model should predict the masks for bounding polygons in each image. A mask is a 2D matrix corresponding to each input image pixel. The contents of each pixel position can be `0` or `1`. If the pixel position is marked `0`, then that position corresponds to the background category, no paragraph, text box, image, or table exists at that pixel. This mask is called a **binary mask** because of its content. Each prediction category (paragraph, text box, image, table) has a binary mask for each image. For example, image `846df66a-610e-4356-b369-6788885a0dc5.png` has 4 binary masks, for each existing category - that predict where in the image, that specific category occurs. 

<img src="https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F10747121%2F54232aef9b0ceab41a33f8113cd0600e%2F__results___71_0.png?generation=1687185171344197&alt=media" height="80%" width="80%"/>

# Cite the Paper

```
@article{shihab2023badlad,
  title={BaDLAD: A Large Multi-Domain Bengali Document Layout Analysis Dataset},
  author={Shihab, Md Istiak Hossain and Hasan, Md Rakibul and Emon, Mahfuzur Rahman and Hossen, Syed Mobassir and Ansary, Md Nazmuddoha and Ahmed, Intesur and Rakib, Fazle Rabbi and Dhruvo, Shahriar Elahi and Dip, Souhardya Saha and Pavel, Akib Hasan and others},
  journal={arXiv preprint arXiv:2303.05325},
  year={2023}
}
```