Skip to content

Commit c53097c

Browse files
[Bug] Resolving font file errors that occurred due to library updates.
- Corrected to use free font otf files instead of ttf files included in the library. - Fixed so that it can be executed regardless of whether the json format is detectron or coco. - Added test data for operation confirmation - Added input check for arguments at runtime
1 parent 6f4b632 commit c53097c

12 files changed

+812
-15
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ or
2222
pip install -e .
2323
```
2424

25+
### Confirm Installation
26+
27+
```shell
28+
cd nobunaga
29+
nobunaga
30+
```
2531

2632
### Analize error
2733
Before analyzing detection error,
@@ -112,3 +118,7 @@ max(IoU) ≤ tb for all GT.
112118
#### Miss Error (Miss)
113119
All undetected ground truths (false negatives) are not already covered by classification or localization error.
114120
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.
121+
122+
## Copyright
123+
We use GenEi Gothic-Font to visualize above errors.
124+
![Distribution site](https://okoneya.jp/font/)

assets/font/GenEiGothicP-Regular.otf

4.5 MB
Binary file not shown.

nobunaga/command_line.py

+34-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import argparse
2+
import os.path
23

34
import nobunaga.constants as Const
45
from nobunaga.evaluator import Evaluator
@@ -8,17 +9,46 @@
89

910
def arg():
1011
parser = argparse.ArgumentParser()
11-
parser.add_argument("--gt", "-g", type=str, default="", required=True)
12-
parser.add_argument("--pred", "-p", type=str, default="", required=True)
13-
parser.add_argument("--image_dir", "-d", type=str, default="", required=True)
12+
parser.add_argument("--gt", "-g", type=str, default="test/jsons/gt_coco.json", required=False)
13+
parser.add_argument("--pred", "-p", type=str, default="test/jsons/pred_coco.json", required=False)
14+
parser.add_argument("--image_dir", "-d", type=str, default="test/images/", required=False)
1415
parser.add_argument("--iou_threshold", "-i", type=float, default=0.5)
1516
parser.add_argument("--confidence_threshold", "-c", type=float, default=0.7)
1617
parser.add_argument("--model_name", "-m", type=str, default="")
1718
parser.add_argument("--normalize", type=bool, default=False)
1819
parser.add_argument("--output_image", "-o", default=True)
1920
args = parser.parse_args()
20-
print(args)
2121

22+
error_args_name = ""
23+
error_args_value = ""
24+
if not os.path.exists(args.gt):
25+
error_args_name = "gt"
26+
error_args_value = args.gt
27+
if not os.path.exists(args.pred):
28+
error_args_name = "pred"
29+
error_args_value = args.pred
30+
if not os.path.exists(args.image_dir):
31+
error_args_name = "image_dir"
32+
error_args_value = args.image_dir
33+
if error_args_value != "":
34+
print("'{error_args_name}' : '{error_args}' does not exist.".format(
35+
error_args_name=error_args_name,
36+
error_args=error_args_value
37+
))
38+
exit()
39+
40+
if not os.path.isdir(args.image_dir):
41+
error_args_name = "image_dir"
42+
error_args_value = args.image_dir
43+
if error_args_value != "":
44+
print("'{error_args_name}' : '{error_args}' have to be directory.".format(
45+
error_args_name=error_args_name,
46+
error_args=error_args_value
47+
))
48+
exit()
49+
50+
for arg_name, value in vars(args).items():
51+
print(f"{arg_name.ljust(21)}: {value}")
2252
return args
2353

2454

nobunaga/io/gt_json.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,20 @@ def __init__(self, file_path: str):
99
self._annotations = {}
1010
self._categories = {}
1111

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

15-
for annotation in cocojson["annotations"]:
16-
if self._annotations.get(annotation.get("image_id", ""), "") == "":
17-
self._annotations[annotation.get("image_id", "")] = []
18-
self._annotations[annotation.get("image_id", "")].append(annotation)
15+
for annotation in cocojson.get("annotations", []):
16+
image_id = annotation.get("image_id")
17+
if annotation.get("segments_info"):
18+
if self._annotations.get(image_id, "") == "":
19+
self._annotations[image_id] = []
20+
for anno in annotation.get("segments_info"):
21+
self._annotations[image_id].append(anno)
22+
else:
23+
if self._annotations.get(image_id, "") == "":
24+
self._annotations[image_id] = []
25+
self._annotations[image_id].append(annotation)
1926

2027
for category in cocojson["categories"] if "categories" in cocojson else []:
2128
self._categories[category.get("id", -1)] = category.get("name", "")

nobunaga/io/plot_util.py

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ def plot_pie(
2222
# pie plot for error type breakdown
2323
error_sizes = evaluation.get_main_error_distribution()
2424
fig, ax = plt.subplots(1, 1, figsize=(image_size, image_size), dpi=high_dpi)
25+
if error_sizes == [0, 0, 0, 0, 0, 0]:
26+
error_sizes = [0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001]
2527
patches, outer_text, inner_text = ax.pie(
2628
error_sizes,
2729
colors=colors_main.values(),

nobunaga/io/pred_json.py

+18-5
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,26 @@
44
class PredJson(object):
55
def __init__(self, file_path: str):
66
with open(file_path, "r") as json_file:
7-
cocojson = json.load(json_file)
7+
pred_json = json.load(json_file)
88
self._annotations = {}
99

10-
for annotation in cocojson:
11-
if self._annotations.get(annotation.get("image_id", ""), "") == "":
12-
self._annotations[annotation.get("image_id", "")] = []
13-
self._annotations[annotation.get("image_id", "")].append(annotation)
10+
pred_json_list = []
11+
if type(pred_json) == list:
12+
pred_json_list = pred_json
13+
elif type(pred_json) == dict:
14+
for data_type, annotations in pred_json.items():
15+
if data_type == "annotations":
16+
for annotation in annotations:
17+
image_id = annotation.get("image_id")
18+
for anno in annotation.get("segments_info", []):
19+
anno["image_id"] = image_id
20+
pred_json_list.append(anno)
21+
22+
for annotation in pred_json_list:
23+
image_id = annotation.get("image_id")
24+
if self._annotations.get(image_id, "") == "":
25+
self._annotations[image_id] = []
26+
self._annotations[image_id].append(annotation)
1427

1528
def get_annotations(self):
1629
return self._annotations

nobunaga/io/visualizer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def write_label(image_path: str, new_file_path: str, bboxes: dict, col_size: int
7171

7272

7373
def get_font(text_size: int):
74-
font_path = "assets/font/DejaVuSansMono.ttf"
74+
font_path = "assets/font/GenEiGothicP-Regular.otf"
7575
font = ImageFont.truetype(font_path, text_size)
7676
return font
7777

test/images/000000396863.jpg

34 KB
Loading

test/jsons/gt_coco.json

+189
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
{
2+
"images": [
3+
{
4+
"license": 6,
5+
"file_name": "000000396863.jpg",
6+
"height": 426,
7+
"width": 640,
8+
"id": 396863
9+
}
10+
],
11+
"annotations": [
12+
{
13+
"segments_info": [
14+
{
15+
"id": 4537186,
16+
"category_id": 1,
17+
"iscrowd": 0,
18+
"bbox": [
19+
227,
20+
280,
21+
15,
22+
15
23+
],
24+
"area": 145
25+
},
26+
{
27+
"id": 2895691,
28+
"category_id": 1,
29+
"iscrowd": 0,
30+
"bbox": [
31+
91,
32+
16,
33+
117,
34+
251
35+
],
36+
"area": 12310
37+
},
38+
{
39+
"id": 1053465,
40+
"category_id": 19,
41+
"iscrowd": 0,
42+
"bbox": [
43+
551,
44+
16,
45+
89,
46+
406
47+
],
48+
"area": 30272
49+
},
50+
{
51+
"id": 4873063,
52+
"category_id": 19,
53+
"iscrowd": 0,
54+
"bbox": [
55+
96,
56+
103,
57+
181,
58+
312
59+
],
60+
"area": 24064
61+
},
62+
{
63+
"id": 14342366,
64+
"category_id": 125,
65+
"iscrowd": 0,
66+
"bbox": [
67+
266,
68+
164,
69+
288,
70+
76
71+
],
72+
"area": 7280
73+
},
74+
{
75+
"id": 14932171,
76+
"category_id": 148,
77+
"iscrowd": 0,
78+
"bbox": [
79+
223,
80+
185,
81+
340,
82+
206
83+
],
84+
"area": 45470
85+
},
86+
{
87+
"id": 15855856,
88+
"category_id": 187,
89+
"iscrowd": 0,
90+
"bbox": [
91+
347,
92+
0,
93+
203,
94+
73
95+
],
96+
"area": 8153
97+
},
98+
{
99+
"id": 5989216,
100+
"category_id": 192,
101+
"iscrowd": 0,
102+
"bbox": [
103+
300,
104+
0,
105+
340,
106+
106
107+
],
108+
"area": 14545
109+
},
110+
{
111+
"id": 6780803,
112+
"category_id": 194,
113+
"iscrowd": 0,
114+
"bbox": [
115+
34,
116+
323,
117+
241,
118+
103
119+
],
120+
"area": 8950
121+
}
122+
],
123+
"file_name": "000000396863.jpg",
124+
"image_id": 396863
125+
}
126+
],
127+
"categories": [
128+
{
129+
"supercategory": "person",
130+
"isthing": 1,
131+
"id": 1,
132+
"name": "person"
133+
},
134+
{
135+
"supercategory": "vehicle",
136+
"isthing": 1,
137+
"id": 2,
138+
"name": "bicycle"
139+
},
140+
{
141+
"supercategory": "animal",
142+
"isthing": 1,
143+
"id": 19,
144+
"name": "horse"
145+
},
146+
{
147+
"supercategory": "animal",
148+
"isthing": 1,
149+
"id": 20,
150+
"name": "sheep"
151+
},
152+
{
153+
"supercategory": "ground",
154+
"isthing": 0,
155+
"id": 125,
156+
"name": "gravel"
157+
},
158+
{
159+
"supercategory": "water",
160+
"isthing": 0,
161+
"id": 148,
162+
"name": "river"
163+
},
164+
{
165+
"supercategory": "ground",
166+
"isthing": 0,
167+
"id": 149,
168+
"name": "road"
169+
},
170+
{
171+
"supercategory": "sky",
172+
"isthing": 0,
173+
"id": 187,
174+
"name": "sky-other-merged"
175+
},
176+
{
177+
"supercategory": "solid",
178+
"isthing": 0,
179+
"id": 192,
180+
"name": "mountain-merged"
181+
},
182+
{
183+
"supercategory": "ground",
184+
"isthing": 0,
185+
"id": 194,
186+
"name": "dirt-merged"
187+
}
188+
]
189+
}

0 commit comments

Comments
 (0)