When I studied Python with YOLOv3 code, I wanted to record it as a memo. We will update each content as soon as it is available.
This time, we will deal with the case where the text content is multiple lines and the case where it is one line.
coco_classes.txt
person
bicycle
car
motorbike
aeroplane
readlines_.py
import os
classes_path = 'model_data/coco_classes.txt'
#Change to home directory
classes_path = os.path.expanduser(classes_path)
with open(classes_path) as f:
#Make text into one list as character string + line feed
class_names = f.readlines()
#Put the value on the nth line in the text in c and remove the line breaks
for c in class_names:
c = c.strip()
print(c)
tiny_yolo_anchors.txt
10,14, 23,27, 37,58, 81,82, 135,169, 344,319
readline_.py
import os
anchors_path= 'model_data/tiny_yolo_anchors.txt'
#Change to home directory
anchors_path= os.path.expanduser(classes_path)
with open(anchors_path) as f:
#Make text into one list as character string + line feed
anchors_path= f.readline()
#In the text','Put the nth value of the value separated by with in x and change it to float type
for x in anchors.split(','):
x = float(x)
print(x)
#Accompanying the above process
anchors = [float(x) for x in anchors.split(',')]
play_with_anchors_value.py
import os
import numpy as np
anchors_path= 'model_data/tiny_yolo_anchors.txt'
with open(anchors_path) as f:
anchors_path= f.readline()
print(anchors_path)
#10,14, 23,27, 37,58, 81,82, 135,169, 344,319
anchors = [float(x) for x in anchors.split(',')]
print(anchors_path)
#[10.0, 14.0, 23.0, 27.0, 37.0, 58.0, 81.0, 82.0, 135.0, 169.0, 344.0, 319.0]
anchors = np.array(anchors).reshape(-1, 2)#Arrange into two columns of coordinates,-1 is treated as correction
print(anchors_path)
"""
[[ 10. 14.]
[ 23. 27.]
[ 37. 58.]
[ 81. 82.]
[135. 169.]
[344. 319.]]
"""
Decoding code is (maybe) studying.
Recommended Posts