当前位置: 首页>>代码示例>>Python>>正文


Python image.preprocess_image方法代码示例

本文整理汇总了Python中keras_retinanet.utils.image.preprocess_image方法的典型用法代码示例。如果您正苦于以下问题:Python image.preprocess_image方法的具体用法?Python image.preprocess_image怎么用?Python image.preprocess_image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在keras_retinanet.utils.image的用法示例。


在下文中一共展示了image.preprocess_image方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: detection_as_classification

# 需要导入模块: from keras_retinanet.utils import image [as 别名]
# 或者: from keras_retinanet.utils.image import preprocess_image [as 别名]
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 
开发者ID:921kiyo,项目名称:3d-dl,代码行数:26,代码来源:train_keras_retinanet.py

示例2: get_retinanet_detection

# 需要导入模块: from keras_retinanet.utils import image [as 别名]
# 或者: from keras_retinanet.utils.image import preprocess_image [as 别名]
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 
开发者ID:kirumang,项目名称:Pix2Pose,代码行数:29,代码来源:5_evaluation_bop_basic.py

示例3: detect

# 需要导入模块: from keras_retinanet.utils import image [as 别名]
# 或者: from keras_retinanet.utils.image import preprocess_image [as 别名]
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 
开发者ID:notAI-tech,项目名称:NudeNet,代码行数:17,代码来源:detector.py

示例4: process_detection

# 需要导入模块: from keras_retinanet.utils import image [as 别名]
# 或者: from keras_retinanet.utils.image import preprocess_image [as 别名]
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) 
开发者ID:DLR-RM,项目名称:AugmentedAutoencoder,代码行数:42,代码来源:aae_retina_pose_estimator.py

示例5: predict

# 需要导入模块: from keras_retinanet.utils import image [as 别名]
# 或者: from keras_retinanet.utils.image import preprocess_image [as 别名]
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 
开发者ID:holms-ur,项目名称:fine-tuning,代码行数:34,代码来源:predict.py


注:本文中的keras_retinanet.utils.image.preprocess_image方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。