提交 4d82efa0 编写于 作者: W wuzewu

Fix typo

上级 569a9d39
......@@ -24,9 +24,9 @@ from efficientnetb0_small_imagenet.efficientnet import EfficientNetB0_small
author="paddlepaddle",
author_email="paddle-dev@baidu.com",
summary=
"ResNet18vd is a image classfication model, this module is trained with imagenet datasets.",
"EfficientNetB0 is a image classfication model, this module is trained with imagenet datasets.",
version="1.0.0")
class ResNet18vdImageNet(hub.Module):
class EfficientNetB0ImageNet(hub.Module):
def _initialize(self):
self.default_pretrained_model_path = os.path.join(
self.directory, "efficientnetb0_small_imagenet_model")
......@@ -91,8 +91,8 @@ class ResNet18vdImageNet(hub.Module):
with fluid.unique_name.guard():
image = fluid.layers.data(
name="image", shape=[3, 224, 224], dtype="float32")
resnet_vd = EfficientNetB0_small()
output, feature_map = resnet_vd.net(
efficientnet_b0 = EfficientNetB0_small()
output, feature_map = efficientnet_b0.net(
input=image, class_dim=len(self.label_list))
name_prefix = '@HUB_{}@'.format(self.name)
......@@ -169,6 +169,15 @@ class ResNet18vdImageNet(hub.Module):
self._set_config()
self.predictor_set = True
if use_gpu:
try:
_places = os.environ["CUDA_VISIBLE_DEVICES"]
int(_places[0])
except:
raise RuntimeError(
"Attempt to use GPU for prediction, but environment variable CUDA_VISIBLE_DEVICES was not set correctly."
)
all_data = list()
for yield_data in reader(images, paths):
all_data.append(yield_data)
......
......@@ -155,6 +155,15 @@ class FixResnext10132x48dwslImagenet(hub.Module):
Returns:
res (list[dict]): The classfication results.
"""
if use_gpu:
try:
_places = os.environ["CUDA_VISIBLE_DEVICES"]
int(_places[0])
except:
raise RuntimeError(
"Attempt to use GPU for prediction, but environment variable CUDA_VISIBLE_DEVICES was not set correctly."
)
if not self.predictor_set:
self._set_config()
self.predictor_set = True
......
......@@ -155,6 +155,15 @@ class MobileNetV2Animals(hub.Module):
Returns:
res (list[dict]): The classfication results.
"""
if use_gpu:
try:
_places = os.environ["CUDA_VISIBLE_DEVICES"]
int(_places[0])
except:
raise RuntimeError(
"Attempt to use GPU for prediction, but environment variable CUDA_VISIBLE_DEVICES was not set correctly."
)
all_data = list()
for yield_data in reader(images, paths):
all_data.append(yield_data)
......
......@@ -155,6 +155,15 @@ class MobileNetV2Dishes(hub.Module):
Returns:
res (list[dict]): The classfication results.
"""
if use_gpu:
try:
_places = os.environ["CUDA_VISIBLE_DEVICES"]
int(_places[0])
except:
raise RuntimeError(
"Attempt to use GPU for prediction, but environment variable CUDA_VISIBLE_DEVICES was not set correctly."
)
all_data = list()
for yield_data in reader(images, paths):
all_data.append(yield_data)
......
......@@ -178,6 +178,15 @@ class MobileNetV2ImageNetSSLD(hub.Module):
Returns:
res (list[dict]): The classfication results.
"""
if use_gpu:
try:
_places = os.environ["CUDA_VISIBLE_DEVICES"]
int(_places[0])
except:
raise RuntimeError(
"Attempt to use GPU for prediction, but environment variable CUDA_VISIBLE_DEVICES was not set correctly."
)
all_data = list()
for yield_data in reader(images, paths):
all_data.append(yield_data)
......
......@@ -155,6 +155,15 @@ class MobileNetV3Large(hub.Module):
Returns:
res (list[dict]): The classfication results.
"""
if use_gpu:
try:
_places = os.environ["CUDA_VISIBLE_DEVICES"]
int(_places[0])
except:
raise RuntimeError(
"Attempt to use GPU for prediction, but environment variable CUDA_VISIBLE_DEVICES was not set correctly."
)
all_data = list()
for yield_data in reader(images, paths):
all_data.append(yield_data)
......
......@@ -155,6 +155,15 @@ class MobileNetV3Small(hub.Module):
Returns:
res (list[dict]): The classfication results.
"""
if use_gpu:
try:
_places = os.environ["CUDA_VISIBLE_DEVICES"]
int(_places[0])
except:
raise RuntimeError(
"Attempt to use GPU for prediction, but environment variable CUDA_VISIBLE_DEVICES was not set correctly."
)
all_data = list()
for yield_data in reader(images, paths):
all_data.append(yield_data)
......
......@@ -155,6 +155,15 @@ class ResNet18vdImageNet(hub.Module):
Returns:
res (list[dict]): The classfication results.
"""
if use_gpu:
try:
_places = os.environ["CUDA_VISIBLE_DEVICES"]
int(_places[0])
except:
raise RuntimeError(
"Attempt to use GPU for prediction, but environment variable CUDA_VISIBLE_DEVICES was not set correctly."
)
if not self.predictor_set:
self._set_config()
self.predictor_set = True
......
......@@ -155,6 +155,15 @@ class ResNet50vdAnimals(hub.Module):
Returns:
res (list[dict]): The classfication results.
"""
if use_gpu:
try:
_places = os.environ["CUDA_VISIBLE_DEVICES"]
int(_places[0])
except:
raise RuntimeError(
"Attempt to use GPU for prediction, but environment variable CUDA_VISIBLE_DEVICES was not set correctly."
)
all_data = list()
for yield_data in reader(images, paths):
all_data.append(yield_data)
......
......@@ -155,6 +155,15 @@ class ResNet50vdDishes(hub.Module):
Returns:
res (list[dict]): The classfication results.
"""
if use_gpu:
try:
_places = os.environ["CUDA_VISIBLE_DEVICES"]
int(_places[0])
except:
raise RuntimeError(
"Attempt to use GPU for prediction, but environment variable CUDA_VISIBLE_DEVICES was not set correctly."
)
all_data = list()
for yield_data in reader(images, paths):
all_data.append(yield_data)
......
......@@ -155,6 +155,15 @@ class ResNet50vdDishes(hub.Module):
Returns:
res (list[dict]): The classfication results.
"""
if use_gpu:
try:
_places = os.environ["CUDA_VISIBLE_DEVICES"]
int(_places[0])
except:
raise RuntimeError(
"Attempt to use GPU for prediction, but environment variable CUDA_VISIBLE_DEVICES was not set correctly."
)
all_data = list()
for yield_data in reader(images, paths):
all_data.append(yield_data)
......
......@@ -155,6 +155,15 @@ class ResNet50vdWildAnimals(hub.Module):
Returns:
res (list[dict]): The classfication results.
"""
if use_gpu:
try:
_places = os.environ["CUDA_VISIBLE_DEVICES"]
int(_places[0])
except:
raise RuntimeError(
"Attempt to use GPU for prediction, but environment variable CUDA_VISIBLE_DEVICES was not set correctly."
)
all_data = list()
for yield_data in reader(images, paths):
all_data.append(yield_data)
......
......@@ -155,6 +155,15 @@ class SEResNet18vdImageNet(hub.Module):
Returns:
res (list[dict]): The classfication results.
"""
if use_gpu:
try:
_places = os.environ["CUDA_VISIBLE_DEVICES"]
int(_places[0])
except:
raise RuntimeError(
"Attempt to use GPU for prediction, but environment variable CUDA_VISIBLE_DEVICES was not set correctly."
)
if not self.predictor_set:
self._set_config()
self.predictor_set = True
......
......@@ -74,9 +74,9 @@ class FasterRCNNResNet50(hub.Module):
Distill the Head Features, so as to perform transfer learning.
Args:
num_classes (int): number of categories
trainable (bool): whether to set parameters trainable.
pretrained (bool): whether to load default pretrained model.
get_prediction (bool): whether to get prediction.
phase (str): optional choices are 'train' and 'predict'.
Returns:
......@@ -263,6 +263,29 @@ class FasterRCNNResNet50(hub.Module):
fg_thresh=0.5,
class_nums=num_classes)
def save_inference_model(self,
dirname,
model_filename=None,
params_filename=None,
combined=True):
if combined:
model_filename = "__model__" if not model_filename else model_filename
params_filename = "__params__" if not params_filename else params_filename
place = fluid.CPUPlace()
exe = fluid.Executor(place)
program, feeded_var_names, target_vars = fluid.io.load_inference_model(
dirname=self.default_pretrained_model_path, executor=exe)
fluid.io.save_inference_model(
dirname=dirname,
main_program=program,
executor=exe,
feeded_var_names=feeded_var_names,
target_vars=target_vars,
model_filename=model_filename,
params_filename=params_filename)
def object_detection(self,
paths=None,
images=None,
......@@ -294,6 +317,14 @@ class FasterRCNNResNet50(hub.Module):
confidence (float): The confidence of detection result.
save_path (str, optional): The path to save output images.
"""
if use_gpu:
try:
_places = os.environ["CUDA_VISIBLE_DEVICES"]
int(_places[0])
except:
raise RuntimeError(
"Attempt to use GPU for prediction, but environment variable CUDA_VISIBLE_DEVICES was not set correctly."
)
paths = paths if paths else list()
if data and 'image' in data:
paths += data['image']
......@@ -384,7 +415,7 @@ class FasterRCNNResNet50(hub.Module):
Run as a service.
"""
images_decode = [base64_to_cv2(image) for image in images]
results = self.object_detection(images_decode, **kwargs)
results = self.object_detection(images=images_decode, **kwargs)
return results
@runnable
......
......@@ -80,7 +80,7 @@ def clip_bbox(bbox, img_width, img_height):
ymin = max(min(bbox[1], img_height), 0.)
xmax = max(min(bbox[2], img_width), 0.)
ymax = max(min(bbox[3], img_height), 0.)
return xmin, ymin, xmax, ymax
return float(xmin), float(ymin), float(xmax), float(ymax)
def load_label_info(file_path):
......@@ -163,7 +163,7 @@ def postprocess(paths,
bbox = row[2:]
dt = {}
dt['label'] = label_names[category_id]
dt['confidence'] = confidence
dt['confidence'] = float(confidence)
dt['left'], dt['top'], dt['right'], dt['bottom'] = clip_bbox(
bbox, org_img_width, org_img_height)
output_i['data'].append(dt)
......
......@@ -43,7 +43,7 @@ class FasterRCNNResNet50RPN(hub.Module):
self.directory, "faster_rcnn_resnet50_fpn_model")
self.label_names = load_label_info(
os.path.join(self.directory, "label_file.txt"))
# self._set_config()
self._set_config()
def _set_config(self):
"""
......@@ -75,9 +75,9 @@ class FasterRCNNResNet50RPN(hub.Module):
Distill the Head Features, so as to perform transfer learning.
Args:
num_classes (int): number of categories
trainable (bool): whether to set parameters trainable.
pretrained (bool): whether to load default pretrained model.
get_prediction (bool): whether to get prediction.
phase (str): optional choices are 'train' and 'predict'.
Returns:
......@@ -273,6 +273,29 @@ class FasterRCNNResNet50RPN(hub.Module):
fg_thresh=0.5,
class_nums=num_classes)
def save_inference_model(self,
dirname,
model_filename=None,
params_filename=None,
combined=True):
if combined:
model_filename = "__model__" if not model_filename else model_filename
params_filename = "__params__" if not params_filename else params_filename
place = fluid.CPUPlace()
exe = fluid.Executor(place)
program, feeded_var_names, target_vars = fluid.io.load_inference_model(
dirname=self.default_pretrained_model_path, executor=exe)
fluid.io.save_inference_model(
dirname=dirname,
main_program=program,
executor=exe,
feeded_var_names=feeded_var_names,
target_vars=target_vars,
model_filename=model_filename,
params_filename=params_filename)
def object_detection(self,
paths=None,
images=None,
......@@ -304,6 +327,15 @@ class FasterRCNNResNet50RPN(hub.Module):
confidence (float): The confidence of detection result.
save_path (str, optional): The path to save output images.
"""
if use_gpu:
try:
_places = os.environ["CUDA_VISIBLE_DEVICES"]
int(_places[0])
except:
raise RuntimeError(
"Attempt to use GPU for prediction, but environment variable CUDA_VISIBLE_DEVICES was not set correctly."
)
paths = paths if paths else list()
if data and 'image' in data:
paths += data['image']
......@@ -399,7 +431,7 @@ class FasterRCNNResNet50RPN(hub.Module):
Run as a service.
"""
images_decode = [base64_to_cv2(image) for image in images]
results = self.object_detection(images_decode, **kwargs)
results = self.object_detection(images=images_decode, **kwargs)
return results
@runnable
......
......@@ -80,7 +80,7 @@ def clip_bbox(bbox, img_width, img_height):
ymin = max(min(bbox[1], img_height), 0.)
xmax = max(min(bbox[2], img_width), 0.)
ymax = max(min(bbox[3], img_height), 0.)
return xmin, ymin, xmax, ymax
return float(xmin), float(ymin), float(xmax), float(ymax)
def load_label_info(file_path):
......@@ -163,7 +163,7 @@ def postprocess(paths,
bbox = row[2:]
dt = {}
dt['label'] = label_names[category_id]
dt['confidence'] = confidence
dt['confidence'] = float(confidence)
dt['left'], dt['top'], dt['right'], dt['bottom'] = clip_bbox(
bbox, org_img_width, org_img_height)
output_i['data'].append(dt)
......
......@@ -14,6 +14,7 @@ import paddlehub as hub
from paddlehub.module.module import moduleinfo, runnable, serving
from paddle.fluid.core import PaddleTensor, AnalysisConfig, create_paddle_predictor
from paddlehub.io.parser import txt_parser
from paddlehub.common.paddle_helper import add_vars_prefix
from retinanet_resnet50_fpn_coco2017.fpn import FPN
from retinanet_resnet50_fpn_coco2017.retina_head import AnchorGenerator, RetinaTargetAssign, RetinaOutputDecoder, RetinaHead
......@@ -86,10 +87,11 @@ class RetinaNetResNet50FPN(hub.Module):
context_prog = fluid.Program()
startup_program = fluid.Program()
with fluid.program_guard(context_prog, startup_program):
var_prefix = '@HUB_{}@'.format(self.name)
# image
image = fluid.layers.data(
name='image',
shape=[3, 800, 1333],
shape=[-1, 3, -1, -1],
dtype='float32',
lod_level=0)
# im_info
......@@ -133,13 +135,31 @@ class RetinaNetResNet50FPN(hub.Module):
# body_feats
body_feats, spatial_scale = fpn.get_output(body_feats)
# inputs, outputs, context_prog
inputs = {'image': image, 'im_info': im_info}
inputs = {
'image': var_prefix + image.name,
'im_info': var_prefix + im_info.name
}
if get_prediction:
pred = retina_head.get_prediction(body_feats, spatial_scale,
im_info)
outputs = {'bbox_out': pred}
outputs = {'bbox_out': var_prefix + pred.name}
else:
outputs = {'body_feats': body_feats}
outputs = {
'body_features':
[var_prefix + var.name for key, var in body_feats.items()]
}
# add_vars_prefix
add_vars_prefix(context_prog, var_prefix)
add_vars_prefix(fluid.default_startup_program(), var_prefix)
global_vars = context_prog.global_block().vars
inputs = {key: global_vars[value] for key, value in inputs.items()}
outputs = {
key: global_vars[value] if not isinstance(value, list) else
[global_vars[var] for var in value]
for key, value in outputs.items()
}
place = fluid.CPUPlace()
exe = fluid.Executor(place)
......@@ -160,6 +180,29 @@ class RetinaNetResNet50FPN(hub.Module):
exe.run(startup_program)
return inputs, outputs, context_prog
def save_inference_model(self,
dirname,
model_filename=None,
params_filename=None,
combined=True):
if combined:
model_filename = "__model__" if not model_filename else model_filename
params_filename = "__params__" if not params_filename else params_filename
place = fluid.CPUPlace()
exe = fluid.Executor(place)
program, feeded_var_names, target_vars = fluid.io.load_inference_model(
dirname=self.default_pretrained_model_path, executor=exe)
fluid.io.save_inference_model(
dirname=dirname,
main_program=program,
executor=exe,
feeded_var_names=feeded_var_names,
target_vars=target_vars,
model_filename=model_filename,
params_filename=params_filename)
def object_detection(self,
paths=None,
images=None,
......@@ -191,6 +234,15 @@ class RetinaNetResNet50FPN(hub.Module):
confidence (float): The confidence of detection result.
save_path (str, optional): The path to save output images.
"""
if use_gpu:
try:
_places = os.environ["CUDA_VISIBLE_DEVICES"]
int(_places[0])
except:
raise RuntimeError(
"Attempt to use GPU for prediction, but environment variable CUDA_VISIBLE_DEVICES was not set correctly."
)
all_images = list()
paths = paths if paths else list()
for yield_data in test_reader(paths, images):
......@@ -274,7 +326,7 @@ class RetinaNetResNet50FPN(hub.Module):
Run as a service.
"""
images_decode = [base64_to_cv2(image) for image in images]
results = self.object_detection(images_decode, **kwargs)
results = self.object_detection(images=images_decode, **kwargs)
return results
@runnable
......
......@@ -76,7 +76,7 @@ def clip_bbox(bbox, img_width, img_height):
ymin = max(min(bbox[1], img_height), 0.)
xmax = max(min(bbox[2], img_width), 0.)
ymax = max(min(bbox[3], img_height), 0.)
return xmin, ymin, xmax, ymax
return float(xmin), float(ymin), float(xmax), float(ymax)
def load_label_info(file_path):
......@@ -160,7 +160,7 @@ def postprocess(paths, images, data_out, score_thresh, label_names, output_dir,
bbox = row[2:]
dt = {}
dt['label'] = label_names[category_id]
dt['confidence'] = confidence
dt['confidence'] = float(confidence)
dt['left'], dt['top'], dt['right'], dt['bottom'] = clip_bbox(
bbox, org_img_width, org_img_height)
output_i['data'].append(dt)
......
......@@ -188,6 +188,15 @@ class SSDMobileNetv1(hub.Module):
confidence (float): The confidence of detection result.
save_path (str, optional): The path to save output images.
"""
if use_gpu:
try:
_places = os.environ["CUDA_VISIBLE_DEVICES"]
int(_places[0])
except:
raise RuntimeError(
"Attempt to use GPU for prediction, but environment variable CUDA_VISIBLE_DEVICES was not set correctly."
)
paths = paths if paths else list()
if data and 'image' in data:
paths += data['image']
......@@ -244,7 +253,7 @@ class SSDMobileNetv1(hub.Module):
Run as a service.
"""
images_decode = [base64_to_cv2(image) for image in images]
results = self.object_detection(images_decode, **kwargs)
results = self.object_detection(images=images_decode, **kwargs)
return results
@runnable
......
......@@ -77,7 +77,7 @@ def clip_bbox(bbox, img_width, img_height):
ymin = max(min(bbox[1], img_height), 0.)
xmax = max(min(bbox[2], img_width), 0.)
ymax = max(min(bbox[3], img_height), 0.)
return xmin, ymin, xmax, ymax
return float(xmin), float(ymin), float(xmax), float(ymax)
def load_label_info(file_path):
......@@ -163,7 +163,7 @@ def postprocess(paths,
bbox[3] = bbox[3] * org_img_height
dt = {}
dt['label'] = label_names[category_id]
dt['confidence'] = confidence
dt['confidence'] = float(confidence)
dt['left'], dt['top'], dt['right'], dt['bottom'] = clip_bbox(
bbox, org_img_width, org_img_height)
output_i['data'].append(dt)
......
......@@ -242,7 +242,7 @@ class SSDVGG16(hub.Module):
Run as a service.
"""
images_decode = [base64_to_cv2(image) for image in images]
results = self.object_detection(images_decode, **kwargs)
results = self.object_detection(images=images_decode, **kwargs)
return results
@runnable
......
......@@ -77,7 +77,7 @@ def clip_bbox(bbox, img_width, img_height):
ymin = max(min(bbox[1], img_height), 0.)
xmax = max(min(bbox[2], img_width), 0.)
ymax = max(min(bbox[3], img_height), 0.)
return xmin, ymin, xmax, ymax
return float(xmin), float(ymin), float(xmax), float(ymax)
def load_label_info(file_path):
......@@ -163,7 +163,7 @@ def postprocess(paths,
bbox[3] = bbox[3] * org_img_height
dt = {}
dt['label'] = label_names[category_id]
dt['confidence'] = confidence
dt['confidence'] = float(confidence)
dt['left'], dt['top'], dt['right'], dt['bottom'] = clip_bbox(
bbox, org_img_width, org_img_height)
output_i['data'].append(dt)
......
......@@ -194,6 +194,15 @@ class SSDVGG16_512(hub.Module):
confidence (float): The confidence of detection result.
save_path (str, optional): The path to save output images.
"""
if use_gpu:
try:
_places = os.environ["CUDA_VISIBLE_DEVICES"]
int(_places[0])
except:
raise RuntimeError(
"Attempt to use GPU for prediction, but environment variable CUDA_VISIBLE_DEVICES was not set correctly."
)
paths = paths if paths else list()
data_reader = partial(reader, paths, images)
batch_reader = fluid.io.batch(data_reader, batch_size=batch_size)
......@@ -247,7 +256,7 @@ class SSDVGG16_512(hub.Module):
Run as a service.
"""
images_decode = [base64_to_cv2(image) for image in images]
results = self.object_detection(images_decode, **kwargs)
results = self.object_detection(images=images_decode, **kwargs)
return results
@runnable
......
......@@ -77,7 +77,7 @@ def clip_bbox(bbox, img_width, img_height):
ymin = max(min(bbox[1], img_height), 0.)
xmax = max(min(bbox[2], img_width), 0.)
ymax = max(min(bbox[3], img_height), 0.)
return xmin, ymin, xmax, ymax
return float(xmin), float(ymin), float(xmax), float(ymax)
def load_label_info(file_path):
......@@ -163,7 +163,7 @@ def postprocess(paths,
bbox[3] = bbox[3] * org_img_height
dt = {}
dt['label'] = label_names[category_id]
dt['confidence'] = confidence
dt['confidence'] = float(confidence)
dt['left'], dt['top'], dt['right'], dt['bottom'] = clip_bbox(
bbox, org_img_width, org_img_height)
output_i['data'].append(dt)
......
......@@ -180,6 +180,15 @@ class YOLOv3DarkNet53Coco2017(hub.Module):
confidence (float): The confidence of detection result.
save_path (str, optional): The path to save output images.
"""
if use_gpu:
try:
_places = os.environ["CUDA_VISIBLE_DEVICES"]
int(_places[0])
except:
raise RuntimeError(
"Attempt to use GPU for prediction, but environment variable CUDA_VISIBLE_DEVICES was not set correctly."
)
paths = paths if paths else list()
if data and 'image' in data:
paths += data['image']
......@@ -239,7 +248,7 @@ class YOLOv3DarkNet53Coco2017(hub.Module):
Run as a service.
"""
images_decode = [base64_to_cv2(image) for image in images]
results = self.object_detection(images_decode, **kwargs)
results = self.object_detection(images=images_decode, **kwargs)
return results
@runnable
......
......@@ -80,7 +80,7 @@ def clip_bbox(bbox, img_width, img_height):
ymin = max(min(bbox[1], img_height), 0.)
xmax = max(min(bbox[2], img_width), 0.)
ymax = max(min(bbox[3], img_height), 0.)
return xmin, ymin, xmax, ymax
return float(xmin), float(ymin), float(xmax), float(ymax)
def load_label_info(file_path):
......@@ -167,7 +167,7 @@ def postprocess(paths,
bbox = row[2:]
dt = {}
dt['label'] = label_names[category_id]
dt['confidence'] = confidence
dt['confidence'] = float(confidence)
dt['left'], dt['top'], dt['right'], dt['bottom'] = clip_bbox(
bbox, org_img_width, org_img_height)
output_i['data'].append(dt)
......
......@@ -193,6 +193,15 @@ class YOLOv3DarkNet53Pedestrian(hub.Module):
confidence (float): The confidence of detection result.
save_path (str, optional): The path to save output images.
"""
if use_gpu:
try:
_places = os.environ["CUDA_VISIBLE_DEVICES"]
int(_places[0])
except:
raise RuntimeError(
"Attempt to use GPU for prediction, but environment variable CUDA_VISIBLE_DEVICES was not set correctly."
)
paths = paths if paths else list()
data_reader = partial(reader, paths, images)
batch_reader = fluid.io.batch(data_reader, batch_size=batch_size)
......@@ -249,7 +258,7 @@ class YOLOv3DarkNet53Pedestrian(hub.Module):
Run as a service.
"""
images_decode = [base64_to_cv2(image) for image in images]
results = self.object_detection(images_decode, **kwargs)
results = self.object_detection(images=images_decode, **kwargs)
return results
@runnable
......
......@@ -80,7 +80,7 @@ def clip_bbox(bbox, img_width, img_height):
ymin = max(min(bbox[1], img_height), 0.)
xmax = max(min(bbox[2], img_width), 0.)
ymax = max(min(bbox[3], img_height), 0.)
return xmin, ymin, xmax, ymax
return float(xmin), float(ymin), float(xmax), float(ymax)
def load_label_info(file_path):
......@@ -167,7 +167,7 @@ def postprocess(paths,
bbox = row[2:]
dt = {}
dt['label'] = label_names[category_id]
dt['confidence'] = confidence
dt['confidence'] = float(confidence)
dt['left'], dt['top'], dt['right'], dt['bottom'] = clip_bbox(
bbox, org_img_width, org_img_height)
output_i['data'].append(dt)
......
......@@ -193,6 +193,15 @@ class YOLOv3DarkNet53Vehicles(hub.Module):
confidence (float): The confidence of detection result.
save_path (str, optional): The path to save output images.
"""
if use_gpu:
try:
_places = os.environ["CUDA_VISIBLE_DEVICES"]
int(_places[0])
except:
raise RuntimeError(
"Attempt to use GPU for prediction, but environment variable CUDA_VISIBLE_DEVICES was not set correctly."
)
paths = paths if paths else list()
data_reader = partial(reader, paths, images)
batch_reader = fluid.io.batch(data_reader, batch_size=batch_size)
......@@ -249,7 +258,7 @@ class YOLOv3DarkNet53Vehicles(hub.Module):
Run as a service.
"""
images_decode = [base64_to_cv2(image) for image in images]
results = self.object_detection(images_decode, **kwargs)
results = self.object_detection(images=images_decode, **kwargs)
return results
@runnable
......
......@@ -80,7 +80,7 @@ def clip_bbox(bbox, img_width, img_height):
ymin = max(min(bbox[1], img_height), 0.)
xmax = max(min(bbox[2], img_width), 0.)
ymax = max(min(bbox[3], img_height), 0.)
return xmin, ymin, xmax, ymax
return float(xmin), float(ymin), float(xmax), float(ymax)
def load_label_info(file_path):
......@@ -167,7 +167,7 @@ def postprocess(paths,
bbox = row[2:]
dt = {}
dt['label'] = label_names[category_id]
dt['confidence'] = confidence
dt['confidence'] = float(confidence)
dt['left'], dt['top'], dt['right'], dt['bottom'] = clip_bbox(
bbox, org_img_width, org_img_height)
output_i['data'].append(dt)
......
......@@ -183,6 +183,15 @@ class YOLOv3MobileNetV1Coco2017(hub.Module):
confidence (float): The confidence of detection result.
save_path (str, optional): The path to save output images.
"""
if use_gpu:
try:
_places = os.environ["CUDA_VISIBLE_DEVICES"]
int(_places[0])
except:
raise RuntimeError(
"Attempt to use GPU for prediction, but environment variable CUDA_VISIBLE_DEVICES was not set correctly."
)
paths = paths if paths else list()
data_reader = partial(reader, paths, images)
batch_reader = fluid.io.batch(data_reader, batch_size=batch_size)
......@@ -239,7 +248,7 @@ class YOLOv3MobileNetV1Coco2017(hub.Module):
Run as a service.
"""
images_decode = [base64_to_cv2(image) for image in images]
results = self.face_detection(images_decode, **kwargs)
results = self.object_detection(images=images_decode, **kwargs)
return results
@runnable
......
......@@ -80,7 +80,7 @@ def clip_bbox(bbox, img_width, img_height):
ymin = max(min(bbox[1], img_height), 0.)
xmax = max(min(bbox[2], img_width), 0.)
ymax = max(min(bbox[3], img_height), 0.)
return xmin, ymin, xmax, ymax
return float(xmin), float(ymin), float(xmax), float(ymax)
def load_label_info(file_path):
......@@ -167,7 +167,7 @@ def postprocess(paths,
bbox = row[2:]
dt = {}
dt['label'] = label_names[category_id]
dt['confidence'] = confidence
dt['confidence'] = float(confidence)
dt['left'], dt['top'], dt['right'], dt['bottom'] = clip_bbox(
bbox, org_img_width, org_img_height)
output_i['data'].append(dt)
......
......@@ -185,6 +185,15 @@ class YOLOv3DarkNet53Coco2017(hub.Module):
confidence (float): The confidence of detection result.
save_path (str, optional): The path to save output images.
"""
if use_gpu:
try:
_places = os.environ["CUDA_VISIBLE_DEVICES"]
int(_places[0])
except:
raise RuntimeError(
"Attempt to use GPU for prediction, but environment variable CUDA_VISIBLE_DEVICES was not set correctly."
)
paths = paths if paths else list()
data_reader = partial(reader, paths, images)
batch_reader = fluid.io.batch(data_reader, batch_size=batch_size)
......@@ -241,7 +250,7 @@ class YOLOv3DarkNet53Coco2017(hub.Module):
Run as a service.
"""
images_decode = [base64_to_cv2(image) for image in images]
results = self.object_detection(images_decode, **kwargs)
results = self.object_detection(images=images_decode, **kwargs)
return results
@runnable
......
......@@ -80,7 +80,7 @@ def clip_bbox(bbox, img_width, img_height):
ymin = max(min(bbox[1], img_height), 0.)
xmax = max(min(bbox[2], img_width), 0.)
ymax = max(min(bbox[3], img_height), 0.)
return xmin, ymin, xmax, ymax
return float(xmin), float(ymin), float(xmax), float(ymax)
def load_label_info(file_path):
......@@ -167,7 +167,7 @@ def postprocess(paths,
bbox = row[2:]
dt = {}
dt['label'] = label_names[category_id]
dt['confidence'] = confidence
dt['confidence'] = float(confidence)
dt['left'], dt['top'], dt['right'], dt['bottom'] = clip_bbox(
bbox, org_img_width, org_img_height)
output_i['data'].append(dt)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册