Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
4d82efa0
P
PaddleHub
项目概览
PaddlePaddle
/
PaddleHub
1 年多 前同步成功
通知
283
Star
12117
Fork
2091
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
200
列表
看板
标记
里程碑
合并请求
4
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleHub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
200
Issue
200
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
4d82efa0
编写于
4月 30, 2020
作者:
W
wuzewu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix typo
上级
569a9d39
变更
35
隐藏空白更改
内联
并排
Showing
35 changed file
with
339 addition
and
44 deletion
+339
-44
hub_module/modules/image/classification/efficientnetb0_small_imagenet/module.py
...ge/classification/efficientnetb0_small_imagenet/module.py
+13
-4
hub_module/modules/image/classification/fix_resnext101_32x48d_wsl_imagenet/module.py
...assification/fix_resnext101_32x48d_wsl_imagenet/module.py
+9
-0
hub_module/modules/image/classification/mobilenet_v2_animals/module.py
...dules/image/classification/mobilenet_v2_animals/module.py
+9
-0
hub_module/modules/image/classification/mobilenet_v2_dishes/module.py
...odules/image/classification/mobilenet_v2_dishes/module.py
+9
-0
hub_module/modules/image/classification/mobilenet_v2_imagenet_ssld/module.py
...image/classification/mobilenet_v2_imagenet_ssld/module.py
+9
-0
hub_module/modules/image/classification/mobilenet_v3_large_imagenet_ssld/module.py
...classification/mobilenet_v3_large_imagenet_ssld/module.py
+9
-0
hub_module/modules/image/classification/mobilenet_v3_small_imagenet_ssld/module.py
...classification/mobilenet_v3_small_imagenet_ssld/module.py
+9
-0
hub_module/modules/image/classification/resnet18_vd_imagenet/module.py
...dules/image/classification/resnet18_vd_imagenet/module.py
+9
-0
hub_module/modules/image/classification/resnet50_vd_animals/module.py
...odules/image/classification/resnet50_vd_animals/module.py
+9
-0
hub_module/modules/image/classification/resnet50_vd_dishes/module.py
...modules/image/classification/resnet50_vd_dishes/module.py
+9
-0
hub_module/modules/image/classification/resnet50_vd_imagenet_ssld/module.py
.../image/classification/resnet50_vd_imagenet_ssld/module.py
+9
-0
hub_module/modules/image/classification/resnet50_vd_wildanimals/module.py
...es/image/classification/resnet50_vd_wildanimals/module.py
+9
-0
hub_module/modules/image/classification/se_resnet18_vd_imagenet/module.py
...es/image/classification/se_resnet18_vd_imagenet/module.py
+9
-0
hub_module/modules/image/object_detection/faster_rcnn_resnet50_coco2017/module.py
.../object_detection/faster_rcnn_resnet50_coco2017/module.py
+33
-2
hub_module/modules/image/object_detection/faster_rcnn_resnet50_coco2017/processor.py
...ject_detection/faster_rcnn_resnet50_coco2017/processor.py
+2
-2
hub_module/modules/image/object_detection/faster_rcnn_resnet50_fpn_coco2017/module.py
...ect_detection/faster_rcnn_resnet50_fpn_coco2017/module.py
+35
-3
hub_module/modules/image/object_detection/faster_rcnn_resnet50_fpn_coco2017/processor.py
..._detection/faster_rcnn_resnet50_fpn_coco2017/processor.py
+2
-2
hub_module/modules/image/object_detection/retinanet_resnet50_fpn_coco2017/module.py
...bject_detection/retinanet_resnet50_fpn_coco2017/module.py
+57
-5
hub_module/modules/image/object_detection/retinanet_resnet50_fpn_coco2017/processor.py
...ct_detection/retinanet_resnet50_fpn_coco2017/processor.py
+2
-2
hub_module/modules/image/object_detection/ssd_mobilenet_v1_pascal/module.py
.../image/object_detection/ssd_mobilenet_v1_pascal/module.py
+10
-1
hub_module/modules/image/object_detection/ssd_mobilenet_v1_pascal/processor.py
...age/object_detection/ssd_mobilenet_v1_pascal/processor.py
+2
-2
hub_module/modules/image/object_detection/ssd_vgg16_300_coco2017/module.py
...s/image/object_detection/ssd_vgg16_300_coco2017/module.py
+1
-1
hub_module/modules/image/object_detection/ssd_vgg16_300_coco2017/processor.py
...mage/object_detection/ssd_vgg16_300_coco2017/processor.py
+2
-2
hub_module/modules/image/object_detection/ssd_vgg16_512_coco2017/module.py
...s/image/object_detection/ssd_vgg16_512_coco2017/module.py
+10
-1
hub_module/modules/image/object_detection/ssd_vgg16_512_coco2017/processor.py
...mage/object_detection/ssd_vgg16_512_coco2017/processor.py
+2
-2
hub_module/modules/image/object_detection/yolov3_darknet53_coco2017/module.py
...mage/object_detection/yolov3_darknet53_coco2017/module.py
+10
-1
hub_module/modules/image/object_detection/yolov3_darknet53_coco2017/processor.py
...e/object_detection/yolov3_darknet53_coco2017/processor.py
+2
-2
hub_module/modules/image/object_detection/yolov3_darknet53_pedestrian/module.py
...ge/object_detection/yolov3_darknet53_pedestrian/module.py
+10
-1
hub_module/modules/image/object_detection/yolov3_darknet53_pedestrian/processor.py
...object_detection/yolov3_darknet53_pedestrian/processor.py
+2
-2
hub_module/modules/image/object_detection/yolov3_darknet53_vehicles/module.py
...mage/object_detection/yolov3_darknet53_vehicles/module.py
+10
-1
hub_module/modules/image/object_detection/yolov3_darknet53_vehicles/processor.py
...e/object_detection/yolov3_darknet53_vehicles/processor.py
+2
-2
hub_module/modules/image/object_detection/yolov3_mobilenet_v1_coco2017/module.py
...e/object_detection/yolov3_mobilenet_v1_coco2017/module.py
+10
-1
hub_module/modules/image/object_detection/yolov3_mobilenet_v1_coco2017/processor.py
...bject_detection/yolov3_mobilenet_v1_coco2017/processor.py
+2
-2
hub_module/modules/image/object_detection/yolov3_resnet34_coco2017/module.py
...image/object_detection/yolov3_resnet34_coco2017/module.py
+10
-1
hub_module/modules/image/object_detection/yolov3_resnet34_coco2017/processor.py
...ge/object_detection/yolov3_resnet34_coco2017/processor.py
+2
-2
未找到文件。
hub_module/modules/image/classification/efficientnetb0_small_imagenet/module.py
浏览文件 @
4d82efa0
...
...
@@ -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
ResNet18vd
ImageNet
(
hub
.
Module
):
class
EfficientNetB0
ImageNet
(
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
)
...
...
hub_module/modules/image/classification/fix_resnext101_32x48d_wsl_imagenet/module.py
浏览文件 @
4d82efa0
...
...
@@ -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
...
...
hub_module/modules/image/classification/mobilenet_v2_animals/module.py
浏览文件 @
4d82efa0
...
...
@@ -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
)
...
...
hub_module/modules/image/classification/mobilenet_v2_dishes/module.py
浏览文件 @
4d82efa0
...
...
@@ -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
)
...
...
hub_module/modules/image/classification/mobilenet_v2_imagenet_ssld/module.py
浏览文件 @
4d82efa0
...
...
@@ -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
)
...
...
hub_module/modules/image/classification/mobilenet_v3_large_imagenet_ssld/module.py
浏览文件 @
4d82efa0
...
...
@@ -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
)
...
...
hub_module/modules/image/classification/mobilenet_v3_small_imagenet_ssld/module.py
浏览文件 @
4d82efa0
...
...
@@ -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
)
...
...
hub_module/modules/image/classification/resnet18_vd_imagenet/module.py
浏览文件 @
4d82efa0
...
...
@@ -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
...
...
hub_module/modules/image/classification/resnet50_vd_animals/module.py
浏览文件 @
4d82efa0
...
...
@@ -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
)
...
...
hub_module/modules/image/classification/resnet50_vd_dishes/module.py
浏览文件 @
4d82efa0
...
...
@@ -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
)
...
...
hub_module/modules/image/classification/resnet50_vd_imagenet_ssld/module.py
浏览文件 @
4d82efa0
...
...
@@ -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
)
...
...
hub_module/modules/image/classification/resnet50_vd_wildanimals/module.py
浏览文件 @
4d82efa0
...
...
@@ -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
)
...
...
hub_module/modules/image/classification/se_resnet18_vd_imagenet/module.py
浏览文件 @
4d82efa0
...
...
@@ -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
...
...
hub_module/modules/image/object_detection/faster_rcnn_resnet50_coco2017/module.py
浏览文件 @
4d82efa0
...
...
@@ -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
...
...
hub_module/modules/image/object_detection/faster_rcnn_resnet50_coco2017/processor.py
浏览文件 @
4d82efa0
...
...
@@ -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
)
...
...
hub_module/modules/image/object_detection/faster_rcnn_resnet50_fpn_coco2017/module.py
浏览文件 @
4d82efa0
...
...
@@ -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
...
...
hub_module/modules/image/object_detection/faster_rcnn_resnet50_fpn_coco2017/processor.py
浏览文件 @
4d82efa0
...
...
@@ -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
)
...
...
hub_module/modules/image/object_detection/retinanet_resnet50_fpn_coco2017/module.py
浏览文件 @
4d82efa0
...
...
@@ -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
...
...
hub_module/modules/image/object_detection/retinanet_resnet50_fpn_coco2017/processor.py
浏览文件 @
4d82efa0
...
...
@@ -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
)
...
...
hub_module/modules/image/object_detection/ssd_mobilenet_v1_pascal/module.py
浏览文件 @
4d82efa0
...
...
@@ -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
...
...
hub_module/modules/image/object_detection/ssd_mobilenet_v1_pascal/processor.py
浏览文件 @
4d82efa0
...
...
@@ -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
)
...
...
hub_module/modules/image/object_detection/ssd_vgg16_300_coco2017/module.py
浏览文件 @
4d82efa0
...
...
@@ -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
...
...
hub_module/modules/image/object_detection/ssd_vgg16_300_coco2017/processor.py
浏览文件 @
4d82efa0
...
...
@@ -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
)
...
...
hub_module/modules/image/object_detection/ssd_vgg16_512_coco2017/module.py
浏览文件 @
4d82efa0
...
...
@@ -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
...
...
hub_module/modules/image/object_detection/ssd_vgg16_512_coco2017/processor.py
浏览文件 @
4d82efa0
...
...
@@ -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
)
...
...
hub_module/modules/image/object_detection/yolov3_darknet53_coco2017/module.py
浏览文件 @
4d82efa0
...
...
@@ -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
...
...
hub_module/modules/image/object_detection/yolov3_darknet53_coco2017/processor.py
浏览文件 @
4d82efa0
...
...
@@ -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
)
...
...
hub_module/modules/image/object_detection/yolov3_darknet53_pedestrian/module.py
浏览文件 @
4d82efa0
...
...
@@ -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
...
...
hub_module/modules/image/object_detection/yolov3_darknet53_pedestrian/processor.py
浏览文件 @
4d82efa0
...
...
@@ -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
)
...
...
hub_module/modules/image/object_detection/yolov3_darknet53_vehicles/module.py
浏览文件 @
4d82efa0
...
...
@@ -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
...
...
hub_module/modules/image/object_detection/yolov3_darknet53_vehicles/processor.py
浏览文件 @
4d82efa0
...
...
@@ -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
)
...
...
hub_module/modules/image/object_detection/yolov3_mobilenet_v1_coco2017/module.py
浏览文件 @
4d82efa0
...
...
@@ -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
...
...
hub_module/modules/image/object_detection/yolov3_mobilenet_v1_coco2017/processor.py
浏览文件 @
4d82efa0
...
...
@@ -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
)
...
...
hub_module/modules/image/object_detection/yolov3_resnet34_coco2017/module.py
浏览文件 @
4d82efa0
...
...
@@ -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
...
...
hub_module/modules/image/object_detection/yolov3_resnet34_coco2017/processor.py
浏览文件 @
4d82efa0
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录