There are many annotations format for different types of models. Usually, binary masks are used for U-NET and FPN model training. Suppose, if we want to train the MASK R-CNN model for instance segmentation using the same dataset, we need the COCO format annotations. This is the method we developed to convert binary mask to COCO annotation format. Here, your images names should be in the format of "name_id.png" as image id for the COCO format annotation will create from the image name.
Step 1: Clone this repository
!git clone https://github.com/Dilagshan/Binary-Mask-to-COCO-Annotation-Format.git
Step 2: Change the path of the directory
cd /Binary-Mask-to-COCO-Annotation-Format
Step 3: Install the requirement libraries
!pip install -r requirement.txt
Step 4: Import the file named " binary_to_coco.py"
from binary_to_coco import create_coco
Step 5: Define the input for the function create_coco.
input_path_list = "list containing the paths of all binary images"
output_path = "path where you want to save the COCO annotations as json file"
create_coco(input_path, output_path)