-
Notifications
You must be signed in to change notification settings - Fork 19
/
predict_imgs.py
32 lines (28 loc) · 907 Bytes
/
predict_imgs.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
from nets.yolo3 import yolo_body
from keras.layers import Input
from yolo import YOLO
from PIL import Image
import tqdm
yolo = YOLO()
test_file = "test_imglist.txt"
img_file = "./img"
with open(test_file) as f:
lines = f.readlines()
n_test = len(lines)
print("num of test images:",n_test)
output_csv = open("sub.csv","a")
for line in lines:
img_path = line.strip()
img_name = line.strip().split("/")[1].split(".")[0]
# print(img_name)
# print(img_path)
# print(img_path)
image = Image.open(img_path)
predict_img_info = yolo.detect_images(image)
predict_img_info = str(predict_img_info).strip("[").strip("]").replace("'","")
#print(predict_img_info)
text = img_name + ".jpg" + "," + str(predict_img_info) + "\n"
output_csv.write(text)
output_csv.close()
yolo.close_session()
print("all done")