<jupyter_start><jupyter_text>COCO-annotations generation<jupyter_code># %load_ext autoreload
# %autoreload 2

import os
import sys
import itertools
import math
import logging
import json
import re
import random
from collections import OrderedDict
import numpy as np
import matplotlib
import matplotlib.patches as patches
import matplotlib.lines as lines
from matplotlib.patches import Polygon
import warnings
from PIL import Image

warnings.filterwarnings('ignore')

import utils
import visualize
from visualize import display_images
import model as modellib
from model import log
import xavi

ROOT_DIR = os.getcwd()
XAVI_DIR = "XAVI_Dataset"  # TODO: enter value here<jupyter_output><empty_output><jupyter_text>1. Training set<jupyter_code>subset = "train"
resolution = "512"
json_categories = json.load(open(os.path.join(XAVI_DIR, subset + resolution, "categories.json")))["Categories"]
config = xavi.XaviConfig(json_categories)

# Dataset
dataset = xavi.XaviDataset()
dataset.load_xavi(XAVI_DIR, subset + resolution, xavi.MasksType.PNG, json_categories, (512, 512))
dataset.prepare()

print("Image Count: {}".format(len(dataset.image_ids)))
print("Class Count: {}".format(dataset.num_classes))
for i, info in enumerate(dataset.class_info):
    print("{:3}. {:50}".format(i, info['name']))<jupyter_output><empty_output><jupyter_text>Use PNG masks to generate annotations Use PNG masks of the dataset to generate file of annotations in COCO format:<jupyter_code>dataset.PngMasksToAnnotations("Xavi Datset (train)")<jupyter_output>Finished generating annotations.
Saved to: XAVI_Dataset\val512\annotations.json
Time elapsed: 279.07<jupyter_text>2. Validation set<jupyter_code>subset = "val"
resolution = "512"
json_categories = json.load(open(os.path.join(XAVI_DIR, subset + resolution, "categories.json")))["Categories"]
config = xavi.XaviConfig(json_categories)

# Dataset
dataset = xavi.XaviDataset()
dataset.load_xavi(XAVI_DIR, subset + resolution, xavi.MasksType.PNG, json_categories, (512, 512))
dataset.prepare()

print("Image Count: {}".format(len(dataset.image_ids)))
print("Class Count: {}".format(dataset.num_classes))
for i, info in enumerate(dataset.class_info):
    print("{:3}. {:50}".format(i, info['name']))<jupyter_output><empty_output><jupyter_text>Use PNG masks to generate annotations<jupyter_code>dataset.PngMasksToAnnotations("Xavi Datset (val)")<jupyter_output>Finished generating annotations.
Saved to: XAVI_Dataset\val512\annotations.json
Time elapsed: 279.07<jupyter_text>3. Testing set<jupyter_code>subset = "test"
resolution = "512"
json_categories = json.load(open(os.path.join(XAVI_DIR, subset + resolution, "categories.json")))["Categories"]
config = xavi.XaviConfig(json_categories)

# Dataset
dataset = xavi.XaviDataset()
dataset.load_xavi(XAVI_DIR, subset + resolution, xavi.MasksType.PNG, json_categories, (512, 512))
dataset.prepare()

print("Image Count: {}".format(len(dataset.image_ids)))
print("Class Count: {}".format(dataset.num_classes))
for i, info in enumerate(dataset.class_info):
    print("{:3}. {:50}".format(i, info['name']))<jupyter_output>Image Count: 9848
Class Count: 3
  0. BG                                                
  1. Human                                             
  2. Vehicle_Car<jupyter_text>Use PNG masks to generate annotations<jupyter_code>dataset.PngMasksToAnnotations("Xavi Datset (test)")<jupyter_output>Finished generating annotations.
Saved to: XAVI_Dataset\test512\annotations.json
Elapsed time: 287.66
{'fraction_non_alphanumeric': 0.12048192771084337, 'fraction_numerical': 0.020654044750430294, 'mean_word_length': 6.130879345603272, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '347886', 'license': 'MIT', 'n_tokens_mistral': 1217, 'n_tokens_neox': 1146, 'n_words': 258, 'path': 'XAVI - 3 - Masks generation (COCO annotations).ipynb', 'repo_name': 'Xavi3398/Mask-R-CNN-training-with-generated-synthetic-dataset', 'size': '3486'}