Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy Up Files and Dependencies #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@ This repository contains utilities to perform Pseudo Labeling.

## Scripts

Install required libraries.

`pip3 install -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
```
Expand Down
59 changes: 0 additions & 59 deletions change_annotation_format.py

This file was deleted.

3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
opencv-contrib-python>=4.5.5.64
opencv-python>=4.5.5.62
tqdm>=4.62.3
59 changes: 59 additions & 0 deletions scripts/change_annotation_format.py
Original file line number Diff line number Diff line change
@@ -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 <data_path> 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)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.