Skip to content

Commit ca90586

Browse files
update show_statistics
1 parent 27485d8 commit ca90586

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

python_benchmarks/objdetect_benchmark/objdetect_benchmark.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -339,27 +339,30 @@ def read(self, path="test", filename="test"):
339339

340340

341341
def set_plt():
342+
# Turn interactive plotting off
343+
plt.ioff()
342344
plt.rcParams["figure.figsize"] = (15, 9)
343345
plt.rcParams["figure.subplot.bottom"] = 0.3
344346
plt.rcParams["figure.subplot.left"] = 0.05
345347
plt.rcParams["figure.subplot.right"] = 0.99
346348

347349

348350
def show_statistic(obj_type, category, statistics, accuracy, path):
349-
l1 = np.array(list(deepflatten(statistics)))
350-
max_error = accuracy
351-
print(obj_type + ' ' + category + " max detected error", max(l1[l1 < max_error]))
352-
print(obj_type + ' ' + category + " mean detected error", np.mean(l1[l1 < max_error]))
353-
print()
354-
data_frame = pd.DataFrame(l1)
351+
objs = np.array(list(deepflatten(statistics)))
352+
detected = objs[objs < accuracy]
353+
frame = {"category": category, "detected " + obj_type: len(detected)/len(objs),
354+
"total detected " + obj_type: len(detected), "total " + obj_type: len(detected),
355+
"average error " + obj_type: np.mean(detected)}
356+
data_frame = pd.DataFrame(objs)
355357
data_frame.hist(bins=500)
356358
plt.title(category + ' ' + obj_type)
357359
plt.xlabel('error')
358-
plt.xticks(np.arange(0., float(max_error)+.25, .25))
360+
plt.xticks(np.arange(0., float(accuracy)+.25, .25))
359361
plt.ylabel('frequency')
360362
# plt.show()
361363
plt.savefig(path + '/' + category + '_' + obj_type + '.jpg')
362364
plt.close()
365+
return frame
363366

364367

365368
def get_time():
@@ -369,12 +372,14 @@ def get_time():
369372
def show_statistics(distances, accuracy, dataset_path):
370373
output_dict = dataset_path + '/' + get_time()
371374
os.mkdir(output_dict)
375+
draw_all = False
376+
result = []
372377
set_plt()
373378
for obj_type, statistics in distances.items():
374-
# l1 = np.array(list(deepflatten(statistics[2])))
375-
show_statistic(obj_type, 'all', statistics[2], accuracy, output_dict)
376379
for category, image_names, category_statistics in zip(statistics[0], statistics[1], statistics[2]):
377-
show_statistic(obj_type, category, category_statistics, accuracy, output_dict)
380+
result.append(show_statistic(obj_type, category, category_statistics, accuracy, output_dict))
381+
if not draw_all:
382+
continue
378383
if not os.path.exists(output_dict + '/' + category):
379384
os.mkdir(output_dict + '/' + category)
380385
for image_name, image_statistics in zip(image_names, category_statistics):
@@ -384,6 +389,10 @@ def show_statistics(distances, accuracy, dataset_path):
384389
plt.ylabel('error')
385390
plt.savefig(output_dict + '/' + category + '/' + obj_type + '_' + image_name + '.jpg')
386391
plt.close()
392+
result.append(show_statistic(obj_type, 'all', statistics[2], accuracy, output_dict))
393+
data_frame = pd.DataFrame(result)
394+
data_frame = data_frame.groupby('category', as_index=False, sort=False).last()
395+
print(data_frame.to_string(index=False))
387396

388397

389398
def read_distances(filename):

0 commit comments

Comments
 (0)