Created
September 11, 2020 08:49
-
-
Save pranjalAI/dfedbb6e0c6fa9e93c801cb86a38d90f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!unrar e /mydrive/Colab/yolov4/Glasses.rar -d data/obj | |
import glob | |
import os | |
import re | |
txt_file_paths = glob.glob(r"data/obj/*.txt") | |
for i, file_path in enumerate(txt_file_paths): | |
# get image size | |
with open(file_path, "r") as f_o: | |
lines = f_o.readlines() | |
text_converted = [] | |
for line in lines: | |
print(line) | |
numbers = re.findall("[0-9.]+", line) | |
print(numbers) | |
if numbers: | |
# Define coordinates | |
text = "{} {} {} {} {}".format(0, numbers[1], numbers[2], numbers[3], numbers[4]) | |
text_converted.append(text) | |
print(i, file_path) | |
print(text) | |
# Write file | |
with open(file_path, 'w') as fp: | |
for item in text_converted: | |
fp.writelines("%s\n" % item) | |
import glob | |
images_list = glob.glob("data/obj/*.jpg") | |
#Create training.txt file | |
file = open("data/train.txt", "w") | |
file.write("\n".join(images_list)) | |
file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment