Skip to content

Commit

Permalink
Merge pull request #31 from FastAccounting/feature/bugfix_font_file_v…
Browse files Browse the repository at this point in the history
…ersion_error

[Bug] use ttf file of prior verion
  • Loading branch information
tomoakitakeuchi committed Jun 3, 2024
2 parents db1eec7 + 53bb687 commit 050c3a3
Show file tree
Hide file tree
Showing 12 changed files with 814 additions and 18 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ or
pip install -e .
```

### Confirm Installation

```shell
cd nobunaga
nobunaga
```

### Analize error
Before analyzing detection error,
Expand Down Expand Up @@ -112,3 +118,7 @@ max(IoU) ≤ tb for all GT.
#### Miss Error (Miss)
All undetected ground truths (false negatives) are not already covered by classification or localization error.
In Nobunaga, "not already covered by all other errors" define as Miss Error, and more labels tend to be explained as Miss Error more than other errors.

## Copyright
We use GenEi Gothic-Font to visualize above errors.
![Distribution site](https://okoneya.jp/font/)
Binary file added assets/font/GenEiGothicP-Regular.otf
Binary file not shown.
40 changes: 35 additions & 5 deletions nobunaga/command_line.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import os.path

import nobunaga.constants as Const
from nobunaga.evaluator import Evaluator
Expand All @@ -8,17 +9,46 @@

def arg():
parser = argparse.ArgumentParser()
parser.add_argument("--gt", "-g", type=str, default="", required=True)
parser.add_argument("--pred", "-p", type=str, default="", required=True)
parser.add_argument("--image_dir", "-d", type=str, default="", required=True)
parser.add_argument("--gt", "-g", type=str, default="test/jsons/gt_coco.json", required=False)
parser.add_argument("--pred", "-p", type=str, default="test/jsons/pred_coco.json", required=False)
parser.add_argument("--image_dir", "-d", type=str, default="test/images/", required=False)
parser.add_argument("--iou_threshold", "-i", type=float, default=0.5)
parser.add_argument("--confidence_threshold", "-c", type=float, default=0.7)
parser.add_argument("--model_name", "-m", type=str, default="")
parser.add_argument("--normalize", type=bool, default=False)
parser.add_argument("--output_image", "-o", action="store_true")
parser.add_argument("--output_image", "-o", default=True)
args = parser.parse_args()
print(args)

error_args_name = ""
error_args_value = ""
if not os.path.exists(args.gt):
error_args_name = "gt"
error_args_value = args.gt
if not os.path.exists(args.pred):
error_args_name = "pred"
error_args_value = args.pred
if not os.path.exists(args.image_dir):
error_args_name = "image_dir"
error_args_value = args.image_dir
if error_args_value != "":
print("'{error_args_name}' : '{error_args}' does not exist.".format(
error_args_name=error_args_name,
error_args=error_args_value
))
exit()

if not os.path.isdir(args.image_dir):
error_args_name = "image_dir"
error_args_value = args.image_dir
if error_args_value != "":
print("'{error_args_name}' : '{error_args}' have to be directory.".format(
error_args_name=error_args_name,
error_args=error_args_value
))
exit()

for arg_name, value in vars(args).items():
print(f"{arg_name.ljust(21)}: {value}")
return args


Expand Down
17 changes: 12 additions & 5 deletions nobunaga/io/gt_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@ def __init__(self, file_path: str):
self._annotations = {}
self._categories = {}

for image in cocojson["images"]:
for image in cocojson.get("images", []):
self._images[image.get("id", -1)] = image

for annotation in cocojson["annotations"]:
if self._annotations.get(annotation.get("image_id", ""), "") == "":
self._annotations[annotation.get("image_id", "")] = []
self._annotations[annotation.get("image_id", "")].append(annotation)
for annotation in cocojson.get("annotations", []):
image_id = annotation.get("image_id")
if annotation.get("segments_info"):
if self._annotations.get(image_id, "") == "":
self._annotations[image_id] = []
for anno in annotation.get("segments_info"):
self._annotations[image_id].append(anno)
else:
if self._annotations.get(image_id, "") == "":
self._annotations[image_id] = []
self._annotations[image_id].append(annotation)

for category in cocojson["categories"] if "categories" in cocojson else []:
self._categories[category.get("id", -1)] = category.get("name", "")
Expand Down
2 changes: 2 additions & 0 deletions nobunaga/io/plot_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def plot_pie(
# pie plot for error type breakdown
error_sizes = evaluation.get_main_error_distribution()
fig, ax = plt.subplots(1, 1, figsize=(image_size, image_size), dpi=high_dpi)
if error_sizes == [0, 0, 0, 0, 0, 0]:
error_sizes = [0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001]
patches, outer_text, inner_text = ax.pie(
error_sizes,
colors=colors_main.values(),
Expand Down
23 changes: 18 additions & 5 deletions nobunaga/io/pred_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,26 @@
class PredJson(object):
def __init__(self, file_path: str):
with open(file_path, "r") as json_file:
cocojson = json.load(json_file)
pred_json = json.load(json_file)
self._annotations = {}

for annotation in cocojson:
if self._annotations.get(annotation.get("image_id", ""), "") == "":
self._annotations[annotation.get("image_id", "")] = []
self._annotations[annotation.get("image_id", "")].append(annotation)
pred_json_list = []
if type(pred_json) == list:
pred_json_list = pred_json
elif type(pred_json) == dict:
for data_type, annotations in pred_json.items():
if data_type == "annotations":
for annotation in annotations:
image_id = annotation.get("image_id")
for anno in annotation.get("segments_info", []):
anno["image_id"] = image_id
pred_json_list.append(anno)

for annotation in pred_json_list:
image_id = annotation.get("image_id")
if self._annotations.get(image_id, "") == "":
self._annotations[image_id] = []
self._annotations[image_id].append(annotation)

def get_annotations(self):
return self._annotations
Expand Down
5 changes: 2 additions & 3 deletions nobunaga/io/visualizer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import math
import os
import platform

import numpy as np
Expand Down Expand Up @@ -70,9 +71,7 @@ def write_label(image_path: str, new_file_path: str, bboxes: dict, col_size: int


def get_font(text_size: int):
font_path = "/Library/Fonts/Arial Unicode.ttf"
if platform.system() == "Linux":
font_path = "/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf"
font_path = "assets/font/GenEiGothicP-Regular.otf"
font = ImageFont.truetype(font_path, text_size)
return font

Expand Down
Binary file added test/images/000000396863.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
189 changes: 189 additions & 0 deletions test/jsons/gt_coco.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
{
"images": [
{
"license": 6,
"file_name": "000000396863.jpg",
"height": 426,
"width": 640,
"id": 396863
}
],
"annotations": [
{
"segments_info": [
{
"id": 4537186,
"category_id": 1,
"iscrowd": 0,
"bbox": [
227,
280,
15,
15
],
"area": 145
},
{
"id": 2895691,
"category_id": 1,
"iscrowd": 0,
"bbox": [
91,
16,
117,
251
],
"area": 12310
},
{
"id": 1053465,
"category_id": 19,
"iscrowd": 0,
"bbox": [
551,
16,
89,
406
],
"area": 30272
},
{
"id": 4873063,
"category_id": 19,
"iscrowd": 0,
"bbox": [
96,
103,
181,
312
],
"area": 24064
},
{
"id": 14342366,
"category_id": 125,
"iscrowd": 0,
"bbox": [
266,
164,
288,
76
],
"area": 7280
},
{
"id": 14932171,
"category_id": 148,
"iscrowd": 0,
"bbox": [
223,
185,
340,
206
],
"area": 45470
},
{
"id": 15855856,
"category_id": 187,
"iscrowd": 0,
"bbox": [
347,
0,
203,
73
],
"area": 8153
},
{
"id": 5989216,
"category_id": 192,
"iscrowd": 0,
"bbox": [
300,
0,
340,
106
],
"area": 14545
},
{
"id": 6780803,
"category_id": 194,
"iscrowd": 0,
"bbox": [
34,
323,
241,
103
],
"area": 8950
}
],
"file_name": "000000396863.jpg",
"image_id": 396863
}
],
"categories": [
{
"supercategory": "person",
"isthing": 1,
"id": 1,
"name": "person"
},
{
"supercategory": "vehicle",
"isthing": 1,
"id": 2,
"name": "bicycle"
},
{
"supercategory": "animal",
"isthing": 1,
"id": 19,
"name": "horse"
},
{
"supercategory": "animal",
"isthing": 1,
"id": 20,
"name": "sheep"
},
{
"supercategory": "ground",
"isthing": 0,
"id": 125,
"name": "gravel"
},
{
"supercategory": "water",
"isthing": 0,
"id": 148,
"name": "river"
},
{
"supercategory": "ground",
"isthing": 0,
"id": 149,
"name": "road"
},
{
"supercategory": "sky",
"isthing": 0,
"id": 187,
"name": "sky-other-merged"
},
{
"supercategory": "solid",
"isthing": 0,
"id": 192,
"name": "mountain-merged"
},
{
"supercategory": "ground",
"isthing": 0,
"id": 194,
"name": "dirt-merged"
}
]
}
Loading

0 comments on commit 050c3a3

Please sign in to comment.