我正在尝试理解如何处理来自model.predict的结果。
yhat =model.predict(图像),我正在寻找什么样的回报,但它是一种结构……但后来我在网上发现了这个,这让我很困惑。
有人能帮我理解一下model.predict(x)吗?
我正在尝试获取一个值,这样我就可以看到它是一件或另一件事。这是一个两级分类。
谢谢。
def get_predicition(image):
height, width = image.shape[:2]
try: # If in case face is not detected at any frame
face = face_detector(image, 1)[0] # Face detection
x, y, size = get_boundingbox(face=face, width=width, height=height) # Calling to get bound box around the face
except IndexError:
pass
cropped_face = image[y:y+size, x:x+size] # cropping the face
output,label = evaluate(cropped_face) # Sending the cropped face to get classifier result
font_face = cv2.FONT_HERSHEY_SIMPLEX # font settings
thickness = 2
font_scale = 1
if label=='Real':
color = (0,255, 0)
else:
color = (0, 0, 255)
x = face.left() # Setting the bounding box on uncropped image
y = face.top()
w = face.right() - x
h = face.bottom() - y
cv2.putText(image, label+'_'+str('%.2f'%output)+'%', (x, y+h+30),
font_face, font_scale,
color, thickness, 2) # Putting the label and confidence values
return cv2.rectangle(image, (x, y), (x + w, y + h), color, 2)# draw box over face
def evaluate(cropped_face):
# Read the image and resize it
img = cv2.resize(cropped_face, (224, 224))
# Reshape
x = img.reshape((1,) + img.shape)
x /= 255.
result = model_Xc.predict([x])[0][0] # result = model_Xc.predict([x])[0][0]
if result > 0.5:
animal = "cat"
else:
animal = "dog"
result = 1 - result
return result, animal
发布于 2020-01-19 05:33:29
res = model_Xc.predict(img)[0][0]
res = 0.026140803
它给出了结果数组中的最小值
和
res = model_Xc.predict(img)[0][1]
它给出了结果数组的最大值
https://stackoverflow.com/questions/59803355
复制相似问题