本文整理汇总了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
示例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
示例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
示例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)
示例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