-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathyoloFolder.py
75 lines (58 loc) · 2.1 KB
/
yoloFolder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import glob
import cv2
import argparse
import os.path as osp
def image_resize(image, width = None, height = None, inter = cv2.INTER_AREA):
# initialize the dimensions of the image to be resized and
# grab the image size
dim = None
(h, w) = image.shape[:2]
# if both the width and height are None, then return the
# original image
if width is None and height is None:
return image
# check to see if the width is None
if width is None:
# calculate the ratio of the height and construct the
# dimensions
r = height / float(h)
dim = (int(w * r), height)
# otherwise, the height is None
else:
# calculate the ratio of the width and construct the
# dimensions
r = width / float(w)
dim = (width, int(h * r))
# resize the image
resized = cv2.resize(image, dim, interpolation = inter)
# return the resized image
return resized
if __name__ =="__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--root", help="Path pointing to the YOLO folder", type=str,required=True)
opt = parser.parse_args()
root = opt.root
trPath = osp.join(root,"YOLO/Train/")
trFile = "./data/RoboCup/train.txt"
with open(trFile,"w+") as file:
for fName in glob.glob1(trPath,"*.png"):
file.write(trPath+fName + "\n")
file.close()
tePath = osp.join(root,"YOLO/Test/")
teFile = "./data/RoboCup/test.txt"
with open(teFile, "w+") as file:
for fName in glob.glob1(tePath, "*.png"):
file.write(tePath + fName + "\n")
file.close()
trPath = osp.join(root,"YOLO/Finetune/train/")
trFile = "./data/RoboCup/FinetuneTrain.txt"
with open(trFile,"w+") as file:
for fName in glob.glob1(trPath,"*.png"):
file.write(trPath+fName + "\n")
file.close()
tePath = osp.join(root,"YOLO/Finetune/test/")
teFile = "./data/RoboCup/FinetuneTest.txt"
with open(teFile, "w+") as file:
for fName in glob.glob1(tePath, "*.png"):
file.write(tePath + fName + "\n")
file.close()