Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
Opencv Zoo
提交
7b32a55b
O
Opencv Zoo
项目概览
张重言
/
Opencv Zoo
10 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Opencv Zoo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
7b32a55b
编写于
12月 04, 2022
作者:
Y
Yuantao Feng
提交者:
GitHub
12月 04, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Merge pull request #111 from remove-YoloX-dot-py
Delete YoloX.py (#111): - Remove the legacy to save git conflicts
上级
99a0b2f5
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
0 addition
and
89 deletion
+0
-89
models/object_detection_yolox/YoloX.py
models/object_detection_yolox/YoloX.py
+0
-89
未找到文件。
models/object_detection_yolox/YoloX.py
已删除
100644 → 0
浏览文件 @
99a0b2f5
import
numpy
as
np
import
cv2
class
YoloX
:
def
__init__
(
self
,
modelPath
,
confThreshold
=
0.35
,
nmsThreshold
=
0.5
,
objThreshold
=
0.5
,
backendId
=
0
,
targetId
=
0
):
self
.
num_classes
=
80
self
.
net
=
cv2
.
dnn
.
readNet
(
modelPath
)
self
.
input_size
=
(
640
,
640
)
self
.
mean
=
np
.
array
([
0.485
,
0.456
,
0.406
],
dtype
=
np
.
float32
).
reshape
(
1
,
1
,
3
)
self
.
std
=
np
.
array
([
0.229
,
0.224
,
0.225
],
dtype
=
np
.
float32
).
reshape
(
1
,
1
,
3
)
self
.
strides
=
[
8
,
16
,
32
]
self
.
confThreshold
=
confThreshold
self
.
nmsThreshold
=
nmsThreshold
self
.
objThreshold
=
objThreshold
self
.
backendId
=
backendId
self
.
targetId
=
targetId
self
.
net
.
setPreferableBackend
(
self
.
backendId
)
self
.
net
.
setPreferableTarget
(
self
.
targetId
)
self
.
generateAnchors
()
@
property
def
name
(
self
):
return
self
.
__class__
.
__name__
def
setBackend
(
self
,
backenId
):
self
.
backendId
=
backendId
self
.
net
.
setPreferableBackend
(
self
.
backendId
)
def
setTarget
(
self
,
targetId
):
self
.
targetId
=
targetId
self
.
net
.
setPreferableTarget
(
self
.
targetId
)
def
preprocess
(
self
,
img
):
blob
=
np
.
transpose
(
img
,
(
2
,
0
,
1
))
return
blob
[
np
.
newaxis
,
:,
:,
:]
def
infer
(
self
,
srcimg
):
input_blob
=
self
.
preprocess
(
srcimg
)
self
.
net
.
setInput
(
input_blob
)
outs
=
self
.
net
.
forward
(
self
.
net
.
getUnconnectedOutLayersNames
())
predictions
=
self
.
postprocess
(
outs
[
0
])
return
predictions
def
postprocess
(
self
,
outputs
):
dets
=
outputs
[
0
]
dets
[:,
:
2
]
=
(
dets
[:,
:
2
]
+
self
.
grids
)
*
self
.
expanded_strides
dets
[:,
2
:
4
]
=
np
.
exp
(
dets
[:,
2
:
4
])
*
self
.
expanded_strides
# get boxes
boxes
=
dets
[:,
:
4
]
boxes_xyxy
=
np
.
ones_like
(
boxes
)
boxes_xyxy
[:,
0
]
=
boxes
[:,
0
]
-
boxes
[:,
2
]
/
2.
boxes_xyxy
[:,
1
]
=
boxes
[:,
1
]
-
boxes
[:,
3
]
/
2.
boxes_xyxy
[:,
2
]
=
boxes
[:,
0
]
+
boxes
[:,
2
]
/
2.
boxes_xyxy
[:,
3
]
=
boxes
[:,
1
]
+
boxes
[:,
3
]
/
2.
# get scores and class indices
scores
=
dets
[:,
4
:
5
]
*
dets
[:,
5
:]
max_scores
=
np
.
amax
(
scores
,
axis
=
1
)
max_scores_idx
=
np
.
argmax
(
scores
,
axis
=
1
)
# batched-nms, TODO: replace with cv2.dnn.NMSBoxesBatched when OpenCV 4.7.0 is released
max_coord
=
boxes_xyxy
.
max
()
offsets
=
max_scores_idx
*
(
max_coord
+
1
)
boxes_for_nms
=
boxes_xyxy
+
offsets
[:,
None
]
keep
=
cv2
.
dnn
.
NMSBoxes
(
boxes_for_nms
.
tolist
(),
max_scores
.
tolist
(),
self
.
confThreshold
,
self
.
nmsThreshold
)
candidates
=
np
.
concatenate
([
boxes_xyxy
,
max_scores
[:,
None
],
max_scores_idx
[:,
None
]],
axis
=
1
)
return
candidates
[
keep
]
def
generateAnchors
(
self
):
self
.
grids
=
[]
self
.
expanded_strides
=
[]
hsizes
=
[
self
.
input_size
[
0
]
//
stride
for
stride
in
self
.
strides
]
wsizes
=
[
self
.
input_size
[
1
]
//
stride
for
stride
in
self
.
strides
]
for
hsize
,
wsize
,
stride
in
zip
(
hsizes
,
wsizes
,
self
.
strides
):
xv
,
yv
=
np
.
meshgrid
(
np
.
arange
(
hsize
),
np
.
arange
(
wsize
))
grid
=
np
.
stack
((
xv
,
yv
),
2
).
reshape
(
1
,
-
1
,
2
)
self
.
grids
.
append
(
grid
)
shape
=
grid
.
shape
[:
2
]
self
.
expanded_strides
.
append
(
np
.
full
((
*
shape
,
1
),
stride
))
self
.
grids
=
np
.
concatenate
(
self
.
grids
,
1
)
self
.
expanded_strides
=
np
.
concatenate
(
self
.
expanded_strides
,
1
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录