qqwweee / keras-yolo3

A Keras implementation of YOLOv3 (Tensorflow backend)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to get yolov3 accuracy?

heshuju opened this issue · comments

I use tiny weight to predict image, but it can not detect.So I want to check accuracy.The loss is < 0.1,but " mask = box_scores >= score_threshold"'s result is all False.
Here is my predict code

from keras.layers import Input
from keras import backend as K
from yolo3.utils import letterbox_image
from PIL import Image, ImageFont, ImageDraw
import numpy as np
import cv2
import os
from yolo import YOLO as YOLO
def get_layer_output(model, x, index = -1):
layer = K.function([model.input], [model.layers[index].output])
return layer([x])[0]
K.set_learning_phase(0)
num_anchors = 6
num_classes = 1
model_image_size = (416, 416)
model_path = "trained_weights_final.h5"
frame = cv2.imread("person.jpg")
#print(type(image))
image = Image.fromarray(frame)
image = letterbox_image(image, model_image_size)
image = np.array(image, dtype='float32')
print(image.shape)
image /= 255.
image = np.expand_dims(image, 0) # Add batch dimension.
#image = numpy.array(image)
yolo_model = tiny_yolo_body(Input(shape=(None,None,3)), num_anchors//2, num_classes)
yolo_model.load_weights(model_path) # make sure model, anchors and classes match
#predicted = (get_layer_output(yolo_model, image, -1), get_layer_output(yolo_model, image, -2))
anchors_path = YOLO.get_defaults('anchors_path')
anchors_path = os.path.expanduser(anchors_path)
print(anchors_path)
anchors = []
with open(anchors_path) as f:
anchors = f.readline()
anchors = [float(x) for x in anchors.split(',')]
anchors = np.array(anchors).reshape(-1, 2)
out1, out2 = yolo_model.predict(image)
print(np.array(out1).shape, np.array(out2).shape)
predicted = [out1, out2]
boxes, scores, classes = yolo_eval(predicted, anchors, num_classes, model_image_size)

I use tiny weight to predict image, but it can not detect.So I want to check accuracy.The loss is < 0.1,but " mask = box_scores >= score_threshold"'s result is all False.

Here is my predict code
from keras.layers import Input
from keras import backend as K
from yolo3.utils import letterbox_image
from PIL import Image, ImageFont, ImageDraw
import numpy as np
import cv2
import os
from yolo import YOLO as YOLO
def get_layer_output(model, x, index = -1):
layer = K.function([model.input], [model.layers[index].output])
return layer([x])[0]
K.set_learning_phase(0)
num_anchors = 6
num_classes = 1
model_image_size = (416, 416)
model_path = "trained_weights_final.h5"
frame = cv2.imread("person.jpg")
#print(type(image))
image = Image.fromarray(frame)
image = letterbox_image(image, model_image_size)
image = np.array(image, dtype='float32')
print(image.shape)
image /= 255.
image = np.expand_dims(image, 0) # Add batch dimension.
#image = numpy.array(image)
yolo_model = tiny_yolo_body(Input(shape=(None,None,3)), num_anchors//2, num_classes)
yolo_model.load_weights(model_path) # make sure model, anchors and classes match
#predicted = (get_layer_output(yolo_model, image, -1), get_layer_output(yolo_model, image, -2))
anchors_path = YOLO.get_defaults('anchors_path')
anchors_path = os.path.expanduser(anchors_path)
print(anchors_path)
anchors = []
with open(anchors_path) as f:
anchors = f.readline()
anchors = [float(x) for x in anchors.split(',')]
anchors = np.array(anchors).reshape(-1, 2)
out1, out2 = yolo_model.predict(image)
print(np.array(out1).shape, np.array(out2).shape)
predicted = [out1, out2]
boxes, scores, classes = yolo_eval(predicted, anchors, num_classes, model_image_size)