Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
stacked_hourglasses
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wudiao
stacked_hourglasses
Commits
86b64e4e
Commit
86b64e4e
authored
Oct 09, 2021
by
baihe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated
parent
fa59fd22
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
44 additions
and
34 deletions
+44
-34
.gitignore
+2
-1
.idea/pytorch_stacked_hourglass-master.iml
+1
-1
DetectorLoader.py
+2
-2
data/MPII/dp.py
+6
-6
handler.py
+22
-13
mymodels/layers.py
+0
-0
mymodels/posenet.py
+1
-1
mymodels/yolo-tiny-onecls/best-model.pth
+0
-0
mymodels/yolo-tiny-onecls/yolov3-tiny-onecls.cfg
+0
-0
myutils/constant.py
+0
-0
myutils/group.py
+0
-0
myutils/img.py
+0
-0
myutils/misc.py
+0
-0
myutils/posture.py
+0
-0
task/pose.py
+3
-3
test.py
+7
-7
No files found.
.gitignore
View file @
86b64e4e
...
@@ -11,5 +11,5 @@ _ext
...
@@ -11,5 +11,5 @@ _ext
tmp
tmp
*.o*
*.o*
*~
*~
.idea
.idea
/
.DS_Store
.DS_Store
\ No newline at end of file
.idea/pytorch_stacked_hourglass-master.iml
View file @
86b64e4e
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
<component
name=
"PyNamespacePackagesService"
>
<component
name=
"PyNamespacePackagesService"
>
<option
name=
"namespacePackageFolders"
>
<option
name=
"namespacePackageFolders"
>
<list>
<list>
<option
value=
"$MODULE_DIR$/models"
/>
<option
value=
"$MODULE_DIR$/m
ym
odels"
/>
</list>
</list>
</option>
</option>
</component>
</component>
...
...
DetectorLoader.py
View file @
86b64e4e
...
@@ -22,8 +22,8 @@ class TinyYOLOv3_onecls(object):
...
@@ -22,8 +22,8 @@ class TinyYOLOv3_onecls(object):
"""
"""
def
__init__
(
self
,
def
__init__
(
self
,
input_size
=
416
,
input_size
=
416
,
config_file
=
'models/yolo-tiny-onecls/yolov3-tiny-onecls.cfg'
,
config_file
=
'm
ym
odels/yolo-tiny-onecls/yolov3-tiny-onecls.cfg'
,
weight_file
=
'models/yolo-tiny-onecls/best-model.pth'
,
weight_file
=
'm
ym
odels/yolo-tiny-onecls/best-model.pth'
,
nms
=
0.2
,
nms
=
0.2
,
conf_thres
=
0.45
,
conf_thres
=
0.45
,
device
=
'cuda'
):
device
=
'cuda'
):
...
...
data/MPII/dp.py
View file @
86b64e4e
...
@@ -4,7 +4,7 @@ import os
...
@@ -4,7 +4,7 @@ import os
import
torch
import
torch
import
numpy
as
np
import
numpy
as
np
import
torch.utils.data
import
torch.utils.data
import
utils.img
import
my
utils.img
class
GenerateHeatmap
():
class
GenerateHeatmap
():
def
__init__
(
self
,
output_res
,
num_parts
):
def
__init__
(
self
,
output_res
,
num_parts
):
...
@@ -64,10 +64,10 @@ class Dataset(torch.utils.data.Dataset):
...
@@ -64,10 +64,10 @@ class Dataset(torch.utils.data.Dataset):
s
=
ds
.
get_scale
(
idx
)
s
=
ds
.
get_scale
(
idx
)
normalize
=
ds
.
get_normalized
(
idx
)
normalize
=
ds
.
get_normalized
(
idx
)
cropped
=
utils
.
img
.
crop
(
orig_img
,
c
,
s
,
(
self
.
input_res
,
self
.
input_res
))
cropped
=
my
utils
.
img
.
crop
(
orig_img
,
c
,
s
,
(
self
.
input_res
,
self
.
input_res
))
for
i
in
range
(
np
.
shape
(
orig_keypoints
)[
1
]):
for
i
in
range
(
np
.
shape
(
orig_keypoints
)[
1
]):
if
orig_keypoints
[
0
,
i
,
0
]
>
0
:
if
orig_keypoints
[
0
,
i
,
0
]
>
0
:
orig_keypoints
[
0
,
i
,:
2
]
=
utils
.
img
.
transform
(
orig_keypoints
[
0
,
i
,:
2
],
c
,
s
,
(
self
.
input_res
,
self
.
input_res
))
orig_keypoints
[
0
,
i
,:
2
]
=
my
utils
.
img
.
transform
(
orig_keypoints
[
0
,
i
,:
2
],
c
,
s
,
(
self
.
input_res
,
self
.
input_res
))
keypoints
=
np
.
copy
(
orig_keypoints
)
keypoints
=
np
.
copy
(
orig_keypoints
)
## augmentation -- to be done to cropped image
## augmentation -- to be done to cropped image
...
@@ -81,11 +81,11 @@ class Dataset(torch.utils.data.Dataset):
...
@@ -81,11 +81,11 @@ class Dataset(torch.utils.data.Dataset):
aug_scale
=
np
.
random
.
random
()
*
(
1.25
-
0.75
)
+
0.75
aug_scale
=
np
.
random
.
random
()
*
(
1.25
-
0.75
)
+
0.75
scale
*=
aug_scale
scale
*=
aug_scale
mat_mask
=
utils
.
img
.
get_transform
(
center
,
scale
,
(
self
.
output_res
,
self
.
output_res
),
aug_rot
)[:
2
]
mat_mask
=
my
utils
.
img
.
get_transform
(
center
,
scale
,
(
self
.
output_res
,
self
.
output_res
),
aug_rot
)[:
2
]
mat
=
utils
.
img
.
get_transform
(
center
,
scale
,
(
self
.
input_res
,
self
.
input_res
),
aug_rot
)[:
2
]
mat
=
my
utils
.
img
.
get_transform
(
center
,
scale
,
(
self
.
input_res
,
self
.
input_res
),
aug_rot
)[:
2
]
inp
=
cv2
.
warpAffine
(
cropped
,
mat
,
(
self
.
input_res
,
self
.
input_res
))
.
astype
(
np
.
float32
)
/
255
inp
=
cv2
.
warpAffine
(
cropped
,
mat
,
(
self
.
input_res
,
self
.
input_res
))
.
astype
(
np
.
float32
)
/
255
keypoints
[:,:,
0
:
2
]
=
utils
.
img
.
kpt_affine
(
keypoints
[:,:,
0
:
2
],
mat_mask
)
keypoints
[:,:,
0
:
2
]
=
my
utils
.
img
.
kpt_affine
(
keypoints
[:,:,
0
:
2
],
mat_mask
)
if
np
.
random
.
randint
(
2
)
==
0
:
if
np
.
random
.
randint
(
2
)
==
0
:
inp
=
self
.
preprocess
(
inp
)
inp
=
self
.
preprocess
(
inp
)
inp
=
inp
[:,
::
-
1
]
inp
=
inp
[:,
::
-
1
]
...
...
handler.py
View file @
86b64e4e
...
@@ -2,9 +2,9 @@ import cv2
...
@@ -2,9 +2,9 @@ import cv2
import
torch
import
torch
import
data.MPII.ref
as
ds
import
data.MPII.ref
as
ds
import
utils.img
import
my
utils.img
from
utils.group
import
HeatmapParser
from
my
utils.group
import
HeatmapParser
from
utils.posture
import
*
from
my
utils.posture
import
*
# 歪头的斜率阈值
# 歪头的斜率阈值
CROOKED_HEAD_THRE
=
8
CROOKED_HEAD_THRE
=
8
...
@@ -105,13 +105,13 @@ def post_process(det, mat_, trainval, c=None, s=None, resolution=None):
...
@@ -105,13 +105,13 @@ def post_process(det, mat_, trainval, c=None, s=None, resolution=None):
cropped_preds
=
parser
.
parse
(
np
.
float32
([
det
]))[
0
]
cropped_preds
=
parser
.
parse
(
np
.
float32
([
det
]))[
0
]
if
len
(
cropped_preds
)
>
0
:
if
len
(
cropped_preds
)
>
0
:
cropped_preds
[:,
:,
:
2
]
=
utils
.
img
.
kpt_affine
(
cropped_preds
[:,
:,
:
2
]
*
4
,
mat
)
# size 1x16x3
cropped_preds
[:,
:,
:
2
]
=
my
utils
.
img
.
kpt_affine
(
cropped_preds
[:,
:,
:
2
]
*
4
,
mat
)
# size 1x16x3
preds
=
np
.
copy
(
cropped_preds
)
preds
=
np
.
copy
(
cropped_preds
)
##for inverting predictions from input res on cropped to original image
##for inverting predictions from input res on cropped to original image
if
trainval
!=
'cropped'
:
if
trainval
!=
'cropped'
:
for
j
in
range
(
preds
.
shape
[
1
]):
for
j
in
range
(
preds
.
shape
[
1
]):
preds
[
0
,
j
,
:
2
]
=
utils
.
img
.
transform
(
preds
[
0
,
j
,
:
2
],
c
,
s
,
resolution
,
invert
=
1
)
preds
[
0
,
j
,
:
2
]
=
my
utils
.
img
.
transform
(
preds
[
0
,
j
,
:
2
],
c
,
s
,
resolution
,
invert
=
1
)
return
preds
return
preds
...
@@ -130,7 +130,7 @@ def inference(img, func, config, c, s):
...
@@ -130,7 +130,7 @@ def inference(img, func, config, c, s):
res
=
(
config
[
'train'
][
'input_res'
],
config
[
'train'
][
'input_res'
])
res
=
(
config
[
'train'
][
'input_res'
],
config
[
'train'
][
'input_res'
])
# [[1,0,0],[0,1,0]]
# [[1,0,0],[0,1,0]]
mat_
=
utils
.
img
.
get_transform
(
center
,
scale
,
res
)[:
2
]
mat_
=
my
utils
.
img
.
get_transform
(
center
,
scale
,
res
)[:
2
]
inp
=
img
/
255
inp
=
img
/
255
def
array2dict
(
tmp
):
def
array2dict
(
tmp
):
...
@@ -190,17 +190,26 @@ if __name__ == '__main__':
...
@@ -190,17 +190,26 @@ if __name__ == '__main__':
input_res
=
256
input_res
=
256
orig_img
=
cv2
.
imread
(
image_path
)
orig_img
=
cv2
.
imread
(
image_path
)
orig_img_reverse
=
cv2
.
imread
(
image_path
)[:,:,::
-
1
]
orig_img_reverse
=
cv2
.
imread
(
image_path
)[:,:,::
-
1
]
shape
=
orig_img_reverse
.
shape
[
0
:
2
]
shape
=
orig_img_reverse
.
shape
[
0
:
2
]
# 这里需要使用yolo检测图片中的人体矩形区域,返回矩形的中心和矩形较长边的边长/200
# 这里需要使用yolo检测图片中的人体矩形区域,返回矩形的中心和矩形较长边的边长/200
# 这里要起一个yolo5的服务。因为yolo5的模型的相对路径已经定死了,无法直接引入到项目中。除非通过命令行的方式
# 这里要起一个yolo5的服务。因为yolo5的模型的相对路径已经定死了,无法直接引入到项目中。除非通过命令行的方式
import
requests
# import requests
DETECTION_URL
=
"http://localhost:5000/v1/object-detection/yolov5s"
# DETECTION_URL = "http://localhost:5000/v1/object-detection/yolov5s"
image_data
=
open
(
image_path
,
"rb"
)
.
read
()
# image_data = open(image_path, "rb").read()
response
=
requests
.
post
(
DETECTION_URL
,
files
=
{
"image"
:
image_data
})
.
json
()
# response = requests.post(DETECTION_URL, files={"image": image_data}).json()
# for box in response:
# if box['class']!=0:
# continue
# else:
# c = [(box['xmax']+box['xmin'])/2,(box['ymax']+box['ymin'])/2]
# s = max((box['xmax']-box['xmin'])/200,(box['ymax']-box['ymin'])/200)+1
# Model
model
=
torch
.
hub
.
load
(
'ultralytics/yolov5'
,
'yolov5s'
)
response
=
model
(
image_path
)
.
pandas
()
.
xyxy
[
0
]
.
to_dict
(
orient
=
'records'
)
for
box
in
response
:
for
box
in
response
:
if
box
[
'class'
]
!=
0
:
if
box
[
'class'
]
!=
0
:
continue
continue
...
@@ -211,7 +220,7 @@ if __name__ == '__main__':
...
@@ -211,7 +220,7 @@ if __name__ == '__main__':
# # 矩形中心坐标点
# # 矩形中心坐标点
# # 缩放比例 实验结果:720*1280的图片,人物占据大部分的情况下,7比较好。
# # 缩放比例 实验结果:720*1280的图片,人物占据大部分的情况下,7比较好。
# s = 7
# s = 7
im
=
utils
.
img
.
crop
(
orig_img_reverse
,
c
,
s
,(
input_res
,
input_res
))
im
=
my
utils
.
img
.
crop
(
orig_img_reverse
,
c
,
s
,(
input_res
,
input_res
))
pred
=
do
(
im
,
c
,
s
)
pred
=
do
(
im
,
c
,
s
)
...
...
models/layers.py
→
m
ym
odels/layers.py
View file @
86b64e4e
File moved
models/posenet.py
→
m
ym
odels/posenet.py
View file @
86b64e4e
import
torch
import
torch
from
torch
import
nn
from
torch
import
nn
from
models.layers
import
Conv
,
Hourglass
,
Pool
,
Residual
from
m
ym
odels.layers
import
Conv
,
Hourglass
,
Pool
,
Residual
from
task.loss
import
HeatmapLoss
from
task.loss
import
HeatmapLoss
class
UnFlatten
(
nn
.
Module
):
class
UnFlatten
(
nn
.
Module
):
...
...
models/yolo-tiny-onecls/best-model.pth
→
m
ym
odels/yolo-tiny-onecls/best-model.pth
View file @
86b64e4e
File moved
models/yolo-tiny-onecls/yolov3-tiny-onecls.cfg
→
m
ym
odels/yolo-tiny-onecls/yolov3-tiny-onecls.cfg
View file @
86b64e4e
File moved
utils/constant.py
→
my
utils/constant.py
View file @
86b64e4e
File moved
utils/group.py
→
my
utils/group.py
View file @
86b64e4e
File moved
utils/img.py
→
my
utils/img.py
View file @
86b64e4e
File moved
utils/misc.py
→
my
utils/misc.py
View file @
86b64e4e
File moved
utils/posture.py
→
my
utils/posture.py
View file @
86b64e4e
File moved
task/pose.py
View file @
86b64e4e
...
@@ -7,11 +7,11 @@ import numpy as np
...
@@ -7,11 +7,11 @@ import numpy as np
from
torch
import
nn
from
torch
import
nn
import
os
import
os
from
torch.nn
import
DataParallel
from
torch.nn
import
DataParallel
from
utils.misc
import
make_input
,
make_output
,
importNet
from
my
utils.misc
import
make_input
,
make_output
,
importNet
__config__
=
{
__config__
=
{
'data_provider'
:
'data.MPII.dp'
,
'data_provider'
:
'data.MPII.dp'
,
'network'
:
'models.posenet.PoseNet'
,
'network'
:
'm
ym
odels.posenet.PoseNet'
,
'inference'
:
{
'inference'
:
{
'nstack'
:
8
,
'nstack'
:
8
,
'inp_dim'
:
256
,
'inp_dim'
:
256
,
...
@@ -80,7 +80,7 @@ def make_network(configs):
...
@@ -80,7 +80,7 @@ def make_network(configs):
## creating new posenet
## creating new posenet
print
(
configs
[
'network'
])
print
(
configs
[
'network'
])
configs
[
'network'
]
=
"models.posenet.PoseNet"
configs
[
'network'
]
=
"m
ym
odels.posenet.PoseNet"
PoseNet
=
importNet
(
configs
[
'network'
])
PoseNet
=
importNet
(
configs
[
'network'
])
poseNet
=
PoseNet
(
**
config
)
poseNet
=
PoseNet
(
**
config
)
# forward_net = DataParallel(poseNet.cuda())
# forward_net = DataParallel(poseNet.cuda())
...
...
test.py
View file @
86b64e4e
...
@@ -6,8 +6,8 @@ import numpy as np
...
@@ -6,8 +6,8 @@ import numpy as np
import
h5py
import
h5py
import
copy
import
copy
from
utils.group
import
HeatmapParser
from
my
utils.group
import
HeatmapParser
import
utils.img
import
my
utils.img
import
data.MPII.ref
as
ds
import
data.MPII.ref
as
ds
parser
=
HeatmapParser
()
parser
=
HeatmapParser
()
...
@@ -18,13 +18,13 @@ def post_process(det, mat_, trainval, c=None, s=None, resolution=None):
...
@@ -18,13 +18,13 @@ def post_process(det, mat_, trainval, c=None, s=None, resolution=None):
cropped_preds
=
parser
.
parse
(
np
.
float32
([
det
]))[
0
]
cropped_preds
=
parser
.
parse
(
np
.
float32
([
det
]))[
0
]
if
len
(
cropped_preds
)
>
0
:
if
len
(
cropped_preds
)
>
0
:
cropped_preds
[:,:,:
2
]
=
utils
.
img
.
kpt_affine
(
cropped_preds
[:,:,:
2
]
*
4
,
mat
)
#size 1x16x3
cropped_preds
[:,:,:
2
]
=
my
utils
.
img
.
kpt_affine
(
cropped_preds
[:,:,:
2
]
*
4
,
mat
)
#size 1x16x3
preds
=
np
.
copy
(
cropped_preds
)
preds
=
np
.
copy
(
cropped_preds
)
##for inverting predictions from input res on cropped to original image
##for inverting predictions from input res on cropped to original image
if
trainval
!=
'cropped'
:
if
trainval
!=
'cropped'
:
for
j
in
range
(
preds
.
shape
[
1
]):
for
j
in
range
(
preds
.
shape
[
1
]):
preds
[
0
,
j
,:
2
]
=
utils
.
img
.
transform
(
preds
[
0
,
j
,:
2
],
c
,
s
,
resolution
,
invert
=
1
)
preds
[
0
,
j
,:
2
]
=
my
utils
.
img
.
transform
(
preds
[
0
,
j
,:
2
],
c
,
s
,
resolution
,
invert
=
1
)
return
preds
return
preds
def
inference
(
img
,
func
,
config
,
c
,
s
):
def
inference
(
img
,
func
,
config
,
c
,
s
):
...
@@ -38,7 +38,7 @@ def inference(img, func, config, c, s):
...
@@ -38,7 +38,7 @@ def inference(img, func, config, c, s):
scale
=
max
(
height
,
width
)
/
200
scale
=
max
(
height
,
width
)
/
200
res
=
(
config
[
'train'
][
'input_res'
],
config
[
'train'
][
'input_res'
])
res
=
(
config
[
'train'
][
'input_res'
],
config
[
'train'
][
'input_res'
])
mat_
=
utils
.
img
.
get_transform
(
center
,
scale
,
res
)[:
2
]
mat_
=
my
utils
.
img
.
get_transform
(
center
,
scale
,
res
)[:
2
]
inp
=
img
/
255
inp
=
img
/
255
def
array2dict
(
tmp
):
def
array2dict
(
tmp
):
...
@@ -158,7 +158,7 @@ def get_img(config, num_eval=2958, num_train=300):
...
@@ -158,7 +158,7 @@ def get_img(config, num_eval=2958, num_train=300):
orig_img
=
cv2
.
imread
(
path_t
)[:,:,::
-
1
]
orig_img
=
cv2
.
imread
(
path_t
)[:,:,::
-
1
]
c
=
train_f
[
'center'
][
i
]
c
=
train_f
[
'center'
][
i
]
s
=
train_f
[
'scale'
][
i
]
s
=
train_f
[
'scale'
][
i
]
im
=
utils
.
img
.
crop
(
orig_img
,
c
,
s
,
(
input_res
,
input_res
))
im
=
my
utils
.
img
.
crop
(
orig_img
,
c
,
s
,
(
input_res
,
input_res
))
## kp
## kp
kp
=
train_f
[
'part'
][
i
]
kp
=
train_f
[
'part'
][
i
]
...
@@ -182,7 +182,7 @@ def get_img(config, num_eval=2958, num_train=300):
...
@@ -182,7 +182,7 @@ def get_img(config, num_eval=2958, num_train=300):
orig_img
=
cv2
.
imread
(
path_t
)[:,:,::
-
1
]
orig_img
=
cv2
.
imread
(
path_t
)[:,:,::
-
1
]
c
=
val_f
[
'center'
][
i
]
c
=
val_f
[
'center'
][
i
]
s
=
val_f
[
'scale'
][
i
]
s
=
val_f
[
'scale'
][
i
]
im
=
utils
.
img
.
crop
(
orig_img
,
c
,
s
,
(
input_res
,
input_res
))
im
=
my
utils
.
img
.
crop
(
orig_img
,
c
,
s
,
(
input_res
,
input_res
))
## kp
## kp
kp
=
val_f
[
'part'
][
i
]
kp
=
val_f
[
'part'
][
i
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment