File size: 2,494 Bytes
f1725f0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
import json
from pathlib import Path
from collections import Counter
BASE_DIR = Path(__file__).resolve().parent
JSON_PATH = BASE_DIR / "train.json"
with open(JSON_PATH, "r", encoding="utf-8") as f:
records = json.load(f)
annotation_types = Counter()
non_list_examples = []
boundary_examples = []
for i, record in enumerate(records):
annotations = record.get("annotations")
annotation_types[type(annotations).__name__] += 1
if not isinstance(annotations, list) and len(non_list_examples) < 10:
non_list_examples.append({
"record_index": i,
"img_name": record.get("img_name"),
"local_image": record.get("local_image"),
"annotations_type": type(annotations).__name__,
"annotations_value": annotations,
})
if isinstance(annotations, list):
for ann_index, ann in enumerate(annotations):
if not isinstance(ann, dict):
continue
polygon = ann.get("polygon", [])
if not isinstance(polygon, list):
continue
for point in polygon:
if (
isinstance(point, (list, tuple))
and len(point) == 2
and all(isinstance(v, (int, float)) for v in point)
and (point[0] >= 512 or point[1] >= 512
or point[0] < 0 or point[1] < 0)
):
if len(boundary_examples) < 10:
boundary_examples.append({
"record_index": i,
"img_name": record.get("img_name"),
"local_image": record.get("local_image"),
"annotation_index": ann_index,
"text": ann.get("text"),
"polygon": polygon,
"image_width": record.get("image_width"),
"image_height": record.get("image_height"),
})
break
print("ANNOTATION VALUE TYPES")
for kind, count in annotation_types.items():
print(f"{kind}: {count}")
print("\nEXAMPLES WHERE ANNOTATIONS IS NOT A LIST")
print(json.dumps(non_list_examples, ensure_ascii=False, indent=2))
print("\nEXAMPLES WITH OUT-OF-BOUNDS COORDINATES")
print(json.dumps(boundary_examples, ensure_ascii=False, indent=2))
|