Python keras_retinanet.utils.image.preprocess_image() Examples
The following are 7
code examples of keras_retinanet.utils.image.preprocess_image().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
keras_retinanet.utils.image
, or try the search function
.
Example #1
Source File: train_keras_retinanet.py From 3d-dl with MIT License | 6 votes |
def detection_as_classification(model, test_generator): """ Given a test_generator that is a regular Keras image generator (for classification tasks), run a DAC evaluate using the given model, and return the toal number of TP's and FP's :param model: model to run predictions :param test_generator: Keras ImageGenerator iterator :return: true positive number, and false positive number (detections) """ i = 0 TP = 0 FP = 0 for X,Y in test_generator: if i >= len(test_generator): break # otherwise will run indefinitely X = rgb2bgr(X) X = preprocess_image(X) boxes, scores, labels = model.predict_on_batch(X) tp, fp = evaluate(filter(scores, labels, score_threshold), Y) i += 1 TP += tp FP += fp return TP, FP
Example #2
Source File: train_keras_retinanet.py From 3d-dl with MIT License | 6 votes |
def detection_as_classification(model, test_generator): """ Given a test_generator that is a regular Keras image generator (for classification tasks), run a DAC evaluate using the given model, and return the toal number of TP's and FP's :param model: model to run predictions :param test_generator: Keras ImageGenerator iterator :return: true positive number, and false positive number (detections) """ i = 0 TP = 0 FP = 0 for X,Y in test_generator: if i >= len(test_generator): break # otherwise will run indefinitely X = rgb2bgr(X) X = preprocess_image(X) boxes, scores, labels = model.predict_on_batch(X) tp, fp = evaluate(filter(scores, labels, score_threshold), Y) i += 1 TP += tp FP += fp return TP, FP
Example #3
Source File: 5_evaluation_bop_basic.py From Pix2Pose with MIT License | 5 votes |
def get_retinanet_detection(image_t,model): image = preprocess_image(image_t[:,:,::-1]) #needs bgr order bgr? image, scale = resize_image(image) boxes, scores, labels = model.predict_on_batch(np.expand_dims(image, axis=0)) boxes /= scale boxes = boxes[0] scores = scores[0] labels = labels[0] score_mask = scores>0 if(np.sum(score_mask)==0): return np.array([[-1,-1,-1,-1]]),-1,-1,-1 else: scores = scores[score_mask] boxes = boxes[score_mask] labels = labels[score_mask] rois = np.zeros((boxes.shape[0],4),np.int) rois[:,0] = boxes[:,1] rois[:,1] = boxes[:,0] rois[:,2] = boxes[:,3] rois[:,3] = boxes[:,2] obj_orders = labels obj_ids = model_ids[obj_orders] return rois,obj_orders,obj_ids,scores
Example #4
Source File: 5_evaluation_bop_icp3d.py From Pix2Pose with MIT License | 5 votes |
def get_retinanet_detection(image_t,model): image = preprocess_image(image_t[:,:,::-1]) #needs bgr order bgr? image, scale = resize_image(image) boxes, scores, labels = model.predict_on_batch(np.expand_dims(image, axis=0)) boxes /= scale boxes = boxes[0] scores = scores[0] labels = labels[0] score_mask = scores>0 if(np.sum(score_mask)==0): return np.array([[-1,-1,-1,-1]]),-1,-1,-1 else: scores = scores[score_mask] boxes = boxes[score_mask] labels = labels[score_mask] rois = np.zeros((boxes.shape[0],4),np.int) rois[:,0] = boxes[:,1] rois[:,1] = boxes[:,0] rois[:,2] = boxes[:,3] rois[:,3] = boxes[:,2] obj_orders = labels obj_ids = model_ids[obj_orders] return rois,obj_orders,obj_ids,scores
Example #5
Source File: detector.py From NudeNet with GNU General Public License v3.0 | 5 votes |
def detect(self, img_path, min_prob=0.6): image = read_image_bgr(img_path) image = preprocess_image(image) image, scale = resize_image(image) boxes, scores, labels = Detector.detection_model.predict_on_batch(np.expand_dims(image, axis=0)) boxes /= scale processed_boxes = [] for box, score, label in zip(boxes[0], scores[0], labels[0]): if score < min_prob: continue box = box.astype(int).tolist() label = Detector.classes[label] processed_boxes.append({'box': box, 'score': score, 'label': label}) return processed_boxes
Example #6
Source File: aae_retina_pose_estimator.py From AugmentedAutoencoder with MIT License | 5 votes |
def process_detection(self, color_img): H, W = color_img.shape[:2] pre_image = preprocess_image(color_img) res_image, scale = resize_image(pre_image) batch_image = np.expand_dims(res_image, axis=0) print batch_image.shape print batch_image.dtype boxes, scores, labels = self.detector.predict_on_batch(batch_image) valid_dets = np.where(scores[0] >= self.det_threshold) boxes /= scale scores = scores[0][valid_dets] boxes = boxes[0][valid_dets] labels = labels[0][valid_dets] filtered_boxes = [] filtered_scores = [] filtered_labels = [] for box,score,label in zip(boxes, scores, labels): box[0] = np.minimum(np.maximum(box[0],0),W) box[1] = np.minimum(np.maximum(box[1],0),H) box[2] = np.minimum(np.maximum(box[2],0),W) box[3] = np.minimum(np.maximum(box[3],0),H) bb_xywh = np.array([box[0],box[1],box[2]-box[0],box[3]-box[1]]) if bb_xywh[2] < 0 or bb_xywh[3] < 0: continue filtered_boxes.append(bb_xywh) filtered_scores.append(score) filtered_labels.append(label) return (filtered_boxes, filtered_scores, filtered_labels)
Example #7
Source File: predict.py From fine-tuning with GNU General Public License v3.0 | 5 votes |
def predict(imagePath): # load the input image (in BGR order), clone it, and preprocess it image = read_image_bgr(imagePath) output = image.copy() image = preprocess_image(image) (image, scale) = resize_image(image) image = np.expand_dims(image, axis=0) # detect objects in the input image and correct for the image scale (boxes, scores, labels) = model.predict_on_batch(image) boxes /= scale # loop over the detections for (box, score, label) in zip(boxes[0], scores[0], labels[0]): # filter out weak detections if score < 0.5: continue # convert the bounding box coordinates from floats to integers box = box.astype("int") # build the label and draw the label + bounding box on the output # image label = "{}: {:.2f}".format(LABELS[label], score) cv2.rectangle(output, (box[0], box[1]), (box[2], box[3]), (0, 255, 0), 2) cv2.putText(output, label, (box[0], box[1] - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2) # show the output image cv2.imwrite("prediction.jpg", output) return boxes