Skip to content

Commit 3f64987

Browse files
committed
small updates to scripts
1 parent 9f16748 commit 3f64987

File tree

5 files changed

+22
-10
lines changed

5 files changed

+22
-10
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
data/dataset/
2+
checkpoints/
3+
__pycache__

core/utils.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -143,22 +143,23 @@ def draw_bbox(image, bboxes, classes=read_class_names(cfg.YOLO.CLASSES), show_la
143143
coor[2] = int(coor[2] * image_h)
144144
coor[1] = int(coor[1] * image_w)
145145
coor[3] = int(coor[3] * image_w)
146+
coor = coor.astype(int)
146147

147148
fontScale = 0.5
148149
score = out_scores[0][i]
149150
class_ind = int(out_classes[0][i])
150151
bbox_color = colors[class_ind]
151152
bbox_thick = int(0.6 * (image_h + image_w) / 600)
152153
c1, c2 = (coor[1], coor[0]), (coor[3], coor[2])
153-
cv2.rectangle(image, c1, c2, bbox_color, bbox_thick)
154+
cv2.rectangle(img = image, pt1 = c1, pt2= c2, color=bbox_color, thickness= bbox_thick)
154155

155156
if show_label:
156157
bbox_mess = '%s: %.2f' % (classes[class_ind], score)
157158
t_size = cv2.getTextSize(bbox_mess, 0, fontScale, thickness=bbox_thick // 2)[0]
158-
c3 = (c1[0] + t_size[0], c1[1] - t_size[1] - 3)
159-
cv2.rectangle(image, c1, (np.float32(c3[0]), np.float32(c3[1])), bbox_color, -1) #filled
159+
c3 = (c1[0] + t_size[0], c1[1] + t_size[1] + 5)
160+
cv2.rectangle(img= image, pt1= c1, pt2=(int(c3[0]), int(c3[1])), color=bbox_color, thickness= -1) #filled
160161

161-
cv2.putText(image, bbox_mess, (c1[0], np.float32(c1[1] - 2)), cv2.FONT_HERSHEY_SIMPLEX,
162+
cv2.putText(image, bbox_mess, (int(c1[0]), int(c1[1] + t_size[1] + 2)), cv2.FONT_HERSHEY_SIMPLEX,
162163
fontScale, (0, 0, 0), bbox_thick // 2, lineType=cv2.LINE_AA)
163164
return image
164165

detect.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,29 @@ def main(_argv):
5050
interpreter.allocate_tensors()
5151
input_details = interpreter.get_input_details()
5252
output_details = interpreter.get_output_details()
53-
print(input_details)
54-
print(output_details)
53+
for key,value in input_details[0].items():
54+
print(key,value)
55+
for key,value in output_details[0].items():
56+
print(key,value)
5557
interpreter.set_tensor(input_details[0]['index'], images_data)
5658
interpreter.invoke()
5759
pred = [interpreter.get_tensor(output_details[i]['index']) for i in range(len(output_details))]
60+
print("PREDICTION", np.shape(pred[0]))
5861
if FLAGS.model == 'yolov3' and FLAGS.tiny == True:
5962
boxes, pred_conf = filter_boxes(pred[1], pred[0], score_threshold=0.25, input_shape=tf.constant([input_size, input_size]))
6063
else:
61-
boxes, pred_conf = filter_boxes(pred[0], pred[1], score_threshold=0.25, input_shape=tf.constant([input_size, input_size]))
64+
pred_bbox = pred
65+
for value in pred_bbox:
66+
boxes = value[:, :, 0:4]
67+
pred_conf = value[:, :, 4:]
68+
# boxes, pred_conf = filter_boxes(pred[0], pred[1], score_threshold=0.25, input_shape=tf.constant([input_size, input_size]))
6269
else:
6370
saved_model_loaded = tf.saved_model.load(FLAGS.weights, tags=[tag_constants.SERVING])
6471
infer = saved_model_loaded.signatures['serving_default']
6572
batch_data = tf.constant(images_data)
6673
pred_bbox = infer(batch_data)
74+
for key,value in pred_bbox.items():
75+
print(f"{key}: {np.shape(value)}")
6776
for key, value in pred_bbox.items():
6877
boxes = value[:, :, 0:4]
6978
pred_conf = value[:, :, 4:]

result.png

-13 KB
Loading

scripts/coco_annotation.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77
import cv2
88

99
flags.DEFINE_string('coco_data', './val2017.pkl', 'path to coco data')
10-
flags.DEFINE_string('classes', '../data/classes/coco.names', 'path to classes file')
10+
flags.DEFINE_string('classes', '../classes/coco.names', 'path to classes file')
1111
flags.DEFINE_string('coco_path', "/Volumes/Elements/data/coco_dataset/coco", 'resize images to')
1212
flags.DEFINE_string('image_path', "images/val2017", 'path to image val')
13-
flags.DEFINE_string('anno_path_val', '../data/dataset/val2017.txt', 'path to classes file')
13+
flags.DEFINE_string('anno_path_val', './val2017.txt', 'output file')
1414

1515
def convert_annotation(output, data, data_type = "val"):
1616
class_names = [c.strip() for c in open(FLAGS.classes).readlines()]
1717
replace_dict = {"couch": "sofa", "airplane": "aeroplane", "tv": "tvmonitor", "motorcycle": "motorbike"}
18-
1918
if os.path.exists(output): os.remove(output)
2019
directory_path = os.path.join(FLAGS.coco_path, FLAGS.image_path)
2120
# if data_type == "train":

0 commit comments

Comments
 (0)