def predict(self, frame): #frame = cv2.resize(frame, (224, 224)) frame = image_utils.img_to_array(frame) frame = np.expand_dims(frame, axis=0) frame = preprocess_input(frame) preds = self.model.predict(frame) return decode_predictions_custom(preds)[0][0]
def predict(self, frame): image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB).astype(np.float32) #image = image.transpose((2, 0, 1)) image = image.reshape((1, ) + image.shape) image = preprocess_input(image) preds = self.model.predict(image) return decode_predictions_custom(preds)[0][0]
def predict(self, frame): imag = image.img_to_array(frame) imag = cv2.resize(imag,(224,224)) imag = np.expand_dims(imag,axis=0) imag = preprocess_input(imag) imag = imag/255 preds = self.model.predict(imag) return decode_predictions_custom(preds)[0]
def model_prediction(test_image_path): test_image = image_preprocess(test_image_path) y_prob = rbc_model.predict(test_image) predictions = decode_predictions_custom(y_prob) return predictions
while frame_number < video_length: cap.set(1, frame_number) ret, frame = cap.read() cv2.resize(frame, (224, 224)) # Load the image using Keras helper ultility print("[INFO] loading and preprocessing image...") image = cv2.resize(frame, (224, 224)) image = image_utils.img_to_array(image) # Convert (3, 224, 224) to (1, 3, 224, 224) # Here "1" is the number of images passed to network # We need it for passing batch containing serveral images in real project image = np.expand_dims(image, axis=0) image = preprocess_input(image) # Classify the image print("[INFO] classifying image...") preds = model.predict(image) (inID, label, prob) = decode_predictions_custom(preds)[0][0] # Display the predictions print("RBC ID: {}, Label: {}, Prob: {}".format(inID, label, prob)) cv2.putText(frame, "Label: {}, Prob: {}".format(label, prob), (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2) cv2.imshow("Classification", frame) cv2.waitKey(0) frame_number += 1 if cv2.waitKey(1) & 0xFF == ord('q'): break cv2.destroyAllWindows() sys.exit()