Skip to content

Instantly share code, notes, and snippets.

@pranjalAI
Created September 11, 2020 08:49
Show Gist options
  • Save pranjalAI/dfedbb6e0c6fa9e93c801cb86a38d90f to your computer and use it in GitHub Desktop.
Save pranjalAI/dfedbb6e0c6fa9e93c801cb86a38d90f to your computer and use it in GitHub Desktop.
!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