Python keras_retinanet.utils.image.resize_image() Examples
The following are 7
code examples of keras_retinanet.utils.image.resize_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: 5_evaluation_bop_icp3d.py From Pix2Pose with MIT License | 6 votes |
def get_rcnn_detection(image_t,model): image_t_resized, window, scale, padding, crop = utils.resize_image( np.copy(image_t), min_dim=config.IMAGE_MIN_DIM, min_scale=config.IMAGE_MIN_SCALE, max_dim=config.IMAGE_MAX_DIM, mode=config.IMAGE_RESIZE_MODE) if(scale!=1): print("Warning.. have to adjust the scale") results = model.detect([image_t_resized], verbose=0) r = results[0] rois = r['rois'] rois = rois - [window[0],window[1],window[0],window[1]] obj_orders = np.array(r['class_ids'])-1 obj_ids = model_ids[obj_orders] #now c_ids are the same annotation those of the names of ply/gt files scores = np.array(r['scores']) masks = r['masks'][window[0]:window[2],window[1]:window[3],:] return rois,obj_orders,obj_ids,scores,masks
Example #2
Source File: 5_evaluation_bop_basic.py From Pix2Pose with MIT License | 5 votes |
def get_rcnn_detection(image_t,model): image_t_resized, window, scale, padding, crop = utils.resize_image( np.copy(image_t), min_dim=config.IMAGE_MIN_DIM, min_scale=config.IMAGE_MIN_SCALE, max_dim=config.IMAGE_MAX_DIM, mode=config.IMAGE_RESIZE_MODE) if(scale!=1): print("Warning.. have to adjust the scale") results = model.detect([image_t_resized], verbose=0) r = results[0] rois = r['rois'] if(scale!=1): masks_all = r['masks'][window[0]:window[2],window[1]:window[3],:] masks = np.zeros((image_t.shape[0],image_t.shape[1],masks_all.shape[2]),bool) for mask_id in range(masks_all.shape[2]): masks[:,:,mask_id]=resize(masks_all[:,:,mask_id].astype(np.float),(image_t.shape[0],image_t.shape[1]))>0.5 #resize all the masks rois=rois/scale window = np.array(window) window[0] = window[0]/scale window[1] = window[1]/scale window[2] = window[2]/scale window[3] = window[3]/scale else: masks = r['masks'][window[0]:window[2],window[1]:window[3],:] rois = rois - [window[0],window[1],window[0],window[1]] obj_orders = np.array(r['class_ids'])-1 obj_ids = model_ids[obj_orders] #now c_ids are the same annotation those of the names of ply/gt files scores = np.array(r['scores']) return rois,obj_orders,obj_ids,scores,masks
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