diff --git a/README.md b/README.md index 37f992e..1ada9c6 100644 --- a/README.md +++ b/README.md @@ -3,23 +3,27 @@ This repository contains utilities to perform Pseudo Labeling. ## Scripts +Install required libraries. + +`python3 -r requirements.txt` + ### Perform Pseudo Label For now, our script just create YOLO labels that saved in txt file. There are some optional arguments that we can add when run the script, including --data_path, --CUDA, etc. -`python3 pseudo_label.py` +`python3 scripts/pseudo_label.py` ### Delete Related Files when the Detection Result is Empty To make our dataset cleaner, our script can delete annotation file and image when the detection result is empty. It can also delete line in the file that contain all the image's name. In this script there is just one optional argument (--data_path), the default value is "data". -`python3 delete_empty_detection.py` +`python3 scripts/delete_empty_detection.py` ### Change Annotation Format YOLO annotation's format that we want is `(class_id, x, y, width, height)`. This script is used to convert `(class_id, center_x, center_y, width, height)` format to our format. -`python3 change_annotation_format.py` +`python3 scripts/change_annotation_format.py` ### Check YOLO model Latency ``` diff --git a/change_annotation_format.py b/change_annotation_format.py deleted file mode 100644 index df05314..0000000 --- a/change_annotation_format.py +++ /dev/null @@ -1,59 +0,0 @@ -# Copyright (c) 2021 Ichiro ITS -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -import argparse -import os -from tqdm import tqdm - -if __name__ == "__main__": - parser = argparse.ArgumentParser() - parser.add_argument('--data_path', help='path for image data', - type=str, default="data") - arg = parser.parse_args() - - data_path = arg.data_path - - # loop every directory in directory - for name in os.listdir(data_path): - target_dir = os.path.join(data_path, name) - if os.path.isdir(target_dir): - print(f"\nRunning on directory {target_dir}...") - - - for file in tqdm(os.listdir(target_dir)): - full_path = os.path.join(target_dir, file) - file_name = full_path.split('.')[0] - extension = full_path.split('.')[-1] - - if os.path.isfile(full_path) and extension == 'txt': - with open(f"{file_name}.txt", "r") as file: - detected_objects = file.readlines() - - for i in range(len(detected_objects)): - class_id, center_x, center_y, w, h = detected_objects[i].split() - - w = float(w) - h = float(h) - x = float(center_x) - w/2 - y = float(center_y) - h/2 - detected_objects[i] = f"{class_id} {x} {y} {w} {h}\n" - - with open(f"{file_name}.txt", "w") as file: - file.writelines(detected_objects) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..13ce499 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +cv2 +tqdm +Yolo diff --git a/scripts/change_annotation_format.py b/scripts/change_annotation_format.py new file mode 100644 index 0000000..b0e8829 --- /dev/null +++ b/scripts/change_annotation_format.py @@ -0,0 +1,59 @@ +# Copyright (c) 2021 Ichiro ITS +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +import argparse +import os +from tqdm import tqdm + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument( + "--data_path", help="path for image data", type=str, default="data" + ) + arg = parser.parse_args() + + data_path = arg.data_path + + # loop every directory in directory + for name in os.listdir(data_path): + target_dir = os.path.join(data_path, name) + if os.path.isdir(target_dir): + print(f"\nRunning on directory {target_dir}...") + + for file in tqdm(os.listdir(target_dir)): + full_path = os.path.join(target_dir, file) + file_name = full_path.split(".")[0] + extension = full_path.split(".")[-1] + + if os.path.isfile(full_path) and extension == "txt": + with open(f"{file_name}.txt", "r") as file: + detected_objects = file.readlines() + + for i in range(len(detected_objects)): + class_id, center_x, center_y, w, h = detected_objects[i].split() + + w = float(w) + h = float(h) + x = float(center_x) - w / 2 + y = float(center_y) - h / 2 + detected_objects[i] = f"{class_id} {x} {y} {w} {h}\n" + + with open(f"{file_name}.txt", "w") as file: + file.writelines(detected_objects) diff --git a/check_latency.cpp b/scripts/check_latency.cpp similarity index 100% rename from check_latency.cpp rename to scripts/check_latency.cpp diff --git a/data_split.py b/scripts/data_split.py similarity index 100% rename from data_split.py rename to scripts/data_split.py diff --git a/delete_empty_detection.py b/scripts/delete_empty_detection.py similarity index 100% rename from delete_empty_detection.py rename to scripts/delete_empty_detection.py diff --git a/pseudo_label.py b/scripts/pseudo_label.py similarity index 100% rename from pseudo_label.py rename to scripts/pseudo_label.py diff --git a/yolo.py b/scripts/yolo.py similarity index 100% rename from yolo.py rename to scripts/yolo.py