Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
2bf8d446
P
PaddleHub
项目概览
PaddlePaddle
/
PaddleHub
大约 1 年 前同步成功
通知
282
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看板
提交
2bf8d446
编写于
10月 09, 2020
作者:
H
haoyuying
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
revise get_label_infos from yolov3
上级
2f8ff8e6
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
15 addition
and
16 deletion
+15
-16
demo/detection/yolov3_darknet53_pascalvoc/train.py
demo/detection/yolov3_darknet53_pascalvoc/train.py
+1
-3
hub_module/modules/image/object_detection/yolov3_darknet53_pascalvoc/module.py
...age/object_detection/yolov3_darknet53_pascalvoc/module.py
+2
-11
paddlehub/module/cv_module.py
paddlehub/module/cv_module.py
+1
-1
paddlehub/process/functional.py
paddlehub/process/functional.py
+11
-0
paddlehub/process/transforms.py
paddlehub/process/transforms.py
+0
-1
未找到文件。
demo/detection/yolov3_darknet53_pascalvoc/train.py
浏览文件 @
2bf8d446
...
@@ -5,7 +5,6 @@ from paddlehub.finetune.trainer import Trainer
...
@@ -5,7 +5,6 @@ from paddlehub.finetune.trainer import Trainer
from
paddlehub.datasets.pascalvoc
import
DetectionData
from
paddlehub.datasets.pascalvoc
import
DetectionData
import
paddlehub.process.detect_transforms
as
T
import
paddlehub.process.detect_transforms
as
T
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
place
=
paddle
.
CUDAPlace
(
0
)
paddle
.
disable_static
()
paddle
.
disable_static
()
transform
=
T
.
Compose
([
transform
=
T
.
Compose
([
...
@@ -20,7 +19,6 @@ if __name__ == "__main__":
...
@@ -20,7 +19,6 @@ if __name__ == "__main__":
train_reader
=
DetectionData
(
transform
)
train_reader
=
DetectionData
(
transform
)
model
=
hub
.
Module
(
name
=
'yolov3_darknet53_pascalvoc'
)
model
=
hub
.
Module
(
name
=
'yolov3_darknet53_pascalvoc'
)
model
.
train
()
optimizer
=
paddle
.
optimizer
.
Adam
(
learning_rate
=
0.0001
,
parameters
=
model
.
parameters
())
optimizer
=
paddle
.
optimizer
.
Adam
(
learning_rate
=
0.0001
,
parameters
=
model
.
parameters
())
trainer
=
Trainer
(
model
,
optimizer
,
checkpoint_dir
=
'test_ckpt_img_
cls
'
)
trainer
=
Trainer
(
model
,
optimizer
,
checkpoint_dir
=
'test_ckpt_img_
det
'
)
trainer
.
train
(
train_reader
,
epochs
=
5
,
batch_size
=
4
,
eval_dataset
=
train_reader
,
log_interval
=
1
,
save_interval
=
1
)
trainer
.
train
(
train_reader
,
epochs
=
5
,
batch_size
=
4
,
eval_dataset
=
train_reader
,
log_interval
=
1
,
save_interval
=
1
)
hub_module/modules/image/object_detection/yolov3_darknet53_pascalvoc/module.py
浏览文件 @
2bf8d446
...
@@ -5,7 +5,6 @@ import paddle.nn as nn
...
@@ -5,7 +5,6 @@ import paddle.nn as nn
import
paddle.nn.functional
as
F
import
paddle.nn.functional
as
F
from
paddle.nn.initializer
import
Normal
,
Constant
from
paddle.nn.initializer
import
Normal
,
Constant
from
paddle.regularizer
import
L2Decay
from
paddle.regularizer
import
L2Decay
from
pycocotools.coco
import
COCO
from
paddlehub.module.cv_module
import
Yolov3Module
from
paddlehub.module.cv_module
import
Yolov3Module
import
paddlehub.process.detect_transforms
as
T
import
paddlehub.process.detect_transforms
as
T
from
paddlehub.module.module
import
moduleinfo
from
paddlehub.module.module
import
moduleinfo
...
@@ -274,10 +273,10 @@ class YOLOv3(nn.Layer):
...
@@ -274,10 +273,10 @@ class YOLOv3(nn.Layer):
print
(
"load custom checkpoint success"
)
print
(
"load custom checkpoint success"
)
else
:
else
:
checkpoint
=
os
.
path
.
join
(
self
.
directory
,
'yolov3_
70000
.pdparams'
)
checkpoint
=
os
.
path
.
join
(
self
.
directory
,
'yolov3_
darknet53_voc
.pdparams'
)
if
not
os
.
path
.
exists
(
checkpoint
):
if
not
os
.
path
.
exists
(
checkpoint
):
os
.
system
(
os
.
system
(
'wget https://
bj.bcebos.com/paddlehub/model/image/object_detection/yolov3_70000
.pdparams -O '
\
'wget https://
paddlehub.bj.bcebos.com/dygraph/detection/yolov3_darknet53_voc
.pdparams -O '
\
+
checkpoint
)
+
checkpoint
)
model_dict
=
paddle
.
load
(
checkpoint
)[
0
]
model_dict
=
paddle
.
load
(
checkpoint
)[
0
]
self
.
set_dict
(
model_dict
)
self
.
set_dict
(
model_dict
)
...
@@ -302,14 +301,6 @@ class YOLOv3(nn.Layer):
...
@@ -302,14 +301,6 @@ class YOLOv3(nn.Layer):
return
transform
(
img
)
return
transform
(
img
)
def
get_label_infos
(
self
,
file_list
:
str
):
self
.
COCO
=
COCO
(
file_list
)
label_names
=
[]
categories
=
self
.
COCO
.
loadCats
(
self
.
COCO
.
getCatIds
())
for
category
in
categories
:
label_names
.
append
(
category
[
'name'
])
return
label_names
def
forward
(
self
,
inputs
:
paddle
.
Tensor
):
def
forward
(
self
,
inputs
:
paddle
.
Tensor
):
outputs
=
[]
outputs
=
[]
blocks
=
self
.
block
(
inputs
)
blocks
=
self
.
block
(
inputs
)
...
...
paddlehub/module/cv_module.py
浏览文件 @
2bf8d446
...
@@ -265,7 +265,7 @@ class Yolov3Module(RunModule, ImageServing):
...
@@ -265,7 +265,7 @@ class Yolov3Module(RunModule, ImageServing):
im
=
self
.
transform
(
imgpath
)
im
=
self
.
transform
(
imgpath
)
h
,
w
,
c
=
Func
.
img_shape
(
imgpath
)
h
,
w
,
c
=
Func
.
img_shape
(
imgpath
)
im_shape
=
paddle
.
to_tensor
(
np
.
array
([[
h
,
w
]]).
astype
(
'int32'
))
im_shape
=
paddle
.
to_tensor
(
np
.
array
([[
h
,
w
]]).
astype
(
'int32'
))
label_names
=
self
.
get_label_infos
(
filelist
)
label_names
=
Func
.
get_label_infos
(
filelist
)
img_data
=
paddle
.
to_tensor
(
np
.
array
([
im
]).
astype
(
'float32'
))
img_data
=
paddle
.
to_tensor
(
np
.
array
([
im
]).
astype
(
'float32'
))
outputs
=
self
(
img_data
)
outputs
=
self
(
img_data
)
...
...
paddlehub/process/functional.py
浏览文件 @
2bf8d446
...
@@ -17,6 +17,7 @@ import cv2
...
@@ -17,6 +17,7 @@ import cv2
import
paddle
import
paddle
import
matplotlib
import
matplotlib
import
numpy
as
np
import
numpy
as
np
from
pycocotools.coco
import
COCO
from
PIL
import
Image
,
ImageEnhance
from
PIL
import
Image
,
ImageEnhance
from
matplotlib
import
pyplot
as
plt
from
matplotlib
import
pyplot
as
plt
...
@@ -235,3 +236,13 @@ def img_shape(img_path: str):
...
@@ -235,3 +236,13 @@ def img_shape(img_path: str):
im
=
cv2
.
cvtColor
(
im
,
cv2
.
COLOR_BGR2RGB
)
im
=
cv2
.
cvtColor
(
im
,
cv2
.
COLOR_BGR2RGB
)
h
,
w
,
c
=
im
.
shape
h
,
w
,
c
=
im
.
shape
return
h
,
w
,
c
return
h
,
w
,
c
def
get_label_infos
(
file_list
:
str
):
"""Get label names by corresponding category ids."""
map_label
=
COCO
(
file_list
)
label_names
=
[]
categories
=
map_label
.
loadCats
(
map_label
.
getCatIds
())
for
category
in
categories
:
label_names
.
append
(
category
[
'name'
])
return
label_names
paddlehub/process/transforms.py
浏览文件 @
2bf8d446
...
@@ -20,7 +20,6 @@ from collections import OrderedDict
...
@@ -20,7 +20,6 @@ from collections import OrderedDict
import
cv2
import
cv2
import
numpy
as
np
import
numpy
as
np
import
matplotlib
from
PIL
import
Image
,
ImageEnhance
from
PIL
import
Image
,
ImageEnhance
from
paddlehub.process.functional
import
*
from
paddlehub.process.functional
import
*
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录