I am trying to understand what to we do with the result from a model.predict.
yhat = model.predict(image), what kind of return I am looking into, but it is an structure... but then I found this on the web which got me really confused...
Can someone help me understand model.predict([x])[0][0]
I am trying to get a value so I can see it is one thing or another. it is a two-class classification.
Thanks.
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
res = model_Xc.predict(img)[0][0]
res = 0.026140803
it gives you the minimun value from the result array
and
res = model_Xc.predict(img)[0][1]
it gives you the max value from the result array
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.