3 from __future__
import print_function
9 from robocup_knowledge
import knowledge_loader
12 Counts the images in the subdirectories of
13 ~/MEGA/data<ROBOT_ENV>/training_data/annotated. Both the verified and
14 unverified annotations are checked and a summary is printed to screen.
16 - Per object that is present in the database: the amount of images present in the directory
17 - If images are not present in the database, a warning is printed
34 """ Counts the images in the subdirectories of 'path'. The subdirectories are identified by the provided objects.
35 The results are printed to screen
37 :param objects: list with strings
38 :param path: string indicating the path
43 p = os.path.join(path, o)
46 if not os.path.exists(p):
49 ustats.append((o, len(os.listdir(p))))
52 ustats.sort(key=
lambda tup: tup[1], reverse=
True)
55 print(
"{}: {}".format(s[0], s[1]))
57 print(BColors.WARNING +
"{}: {}".format(s[0], s[1]) + BColors.ENDC)
60 print(BColors.BOLD +
"\nPossible mismatches:" + BColors.ENDC)
61 print(
"Annotated but not in knowledge")
62 for candidate
in os.listdir(path):
63 if candidate
not in objects:
64 print(BColors.WARNING + candidate + BColors.ENDC)
69 if __name__ ==
"__main__":
72 common_knowledge = knowledge_loader.load_knowledge(
"common")
73 objects = common_knowledge.object_names
74 objects_set = set(objects)
77 robot_env = os.environ.get(
"ROBOT_ENV")
79 tensorflow_labels_path = os.path.join(os.path.expanduser(
"~"),
"MEGA",
"data", robot_env,
"models",
"tensorflow_ros",
"output_labels.txt")
80 with open(tensorflow_labels_path)
as tensorflow_labels_file:
81 raw_labels_lines = tensorflow_labels_file.readlines()
82 tensorflow_labels = [line.strip()
for line
in raw_labels_lines]
83 tensorflow_set = set(tensorflow_labels)
85 print(
"objects that are present in objects_set but not in tensorflow_set\n")
86 for o
in objects_set.difference(tensorflow_set):
90 print(
"objects that are present in tensorflow_set but not in objects_set\n")
91 for t
in tensorflow_set.difference(objects_set):
96 path = os.path.join(os.path.expanduser(
"~"),
"MEGA",
"data", robot_env,
"training_data",
"annotated")
99 for v
in [
"verified",
"unverified"]:
100 tpath = os.path.join(path, v)
101 print(BColors.HEADER + BColors.BOLD + v.upper() + BColors.ENDC +
':\n')