Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Human pose estimation models update #1718

Merged
merged 58 commits into from
Nov 26, 2020
Merged
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
4acbc05
add hpe python demo
druzhkov-paul Oct 27, 2020
8844834
add models description
druzhkov-paul Oct 30, 2020
3bd5a5e
fix
druzhkov-paul Oct 30, 2020
1ea0532
fix post-processing
druzhkov-paul Nov 5, 2020
d2553bf
fix net reshape
druzhkov-paul Nov 5, 2020
aa76d7c
add initial AC support and config
druzhkov-paul Nov 5, 2020
cd0563e
fix typo
druzhkov-paul Nov 5, 2020
e62ef4b
update configs
druzhkov-paul Nov 5, 2020
8a43ca8
clean up
druzhkov-paul Nov 5, 2020
af96059
fix padding
druzhkov-paul Nov 5, 2020
629ebc5
rename dataset
druzhkov-paul Nov 6, 2020
fcc343c
remove empty sections in readme
druzhkov-paul Nov 6, 2020
3c6112d
change hpe visualization
druzhkov-paul Nov 6, 2020
18f4dea
style fixes
druzhkov-paul Nov 9, 2020
8ad309b
initial openpose support
druzhkov-paul Nov 9, 2020
396d8d2
optimize grouping
druzhkov-paul Nov 9, 2020
6b5db64
optimize postprocessing
Nov 10, 2020
6e7cb20
add OpenPose AC adapter draft
druzhkov-paul Nov 11, 2020
180ca3c
up
druzhkov-paul Nov 12, 2020
312ec71
add various nms impls to ac adapter
Nov 12, 2020
4384209
add openvino nms to demo model
Nov 12, 2020
7d21e4f
clean up
Nov 13, 2020
da298ff
align decoder in demo and AC
Nov 13, 2020
12e6434
refactor visualization
Nov 13, 2020
5e18824
clean up
Nov 13, 2020
7af051b
add cpp postprocessing support
Nov 13, 2020
59d9bb4
refactor openpose decoder (wip)
Nov 13, 2020
fafd7b2
moved nms out of decoder
Nov 13, 2020
89053cf
refactor openpose related components
Nov 16, 2020
63c56c9
update readme and model.lst for hpe demo
Nov 16, 2020
78fea41
make target size configurable
Nov 16, 2020
c182441
fix trailing spaces
vladimir-dudnik Nov 16, 2020
af6452b
fix trailing spaces
vladimir-dudnik Nov 16, 2020
6f71ddc
revert changes in HumanPoseAdapter
Nov 16, 2020
e009bc0
fix linter comments
Nov 16, 2020
35e3cb2
moved pose estimation adapters to separate modules
Nov 17, 2020
aca1ccc
fixes
druzhkov-paul Nov 17, 2020
cc24fe5
fix GPU inference in demo
Nov 18, 2020
f56b5ed
improve performance of ae decoder
Nov 18, 2020
15bae7b
add license headers
Nov 18, 2020
3f92178
add adapters description to readme
Nov 18, 2020
a37d6e9
handle scipy absence gently
Nov 18, 2020
991a13a
fix models doc pages
Nov 18, 2020
81bc936
fix indent
Nov 18, 2020
2257add
move AC configs
Nov 18, 2020
679b8a4
remove pseudo links
Nov 18, 2020
4946f64
fix typo
Nov 19, 2020
cb1af2e
update arguments description
Nov 19, 2020
86544c2
move image resize to base Model class
Nov 20, 2020
0972357
extend documentation of --tsize arg
Nov 20, 2020
187d39b
support old numpy versions
Nov 20, 2020
230b52e
fix docs
Nov 20, 2020
2116b47
removed cpp postprocessing
Nov 20, 2020
38efe54
add symlinks to AC config files
druzhkov-paul Nov 21, 2020
a980b1e
add demo to the list of all demos in readme
Nov 23, 2020
3d8b5f3
fix readme
Nov 23, 2020
1c0954c
change CLI arg name
Nov 23, 2020
190a85d
fix demo readme...
Nov 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
moved nms out of decoder
  • Loading branch information
Pavel Druzhkov committed Nov 13, 2020
commit fafd7b2311865cf671aab4ee204746435769a605
71 changes: 41 additions & 30 deletions tools/accuracy_checker/accuracy_checker/adapters/pose_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ def get_preds(scores):
return preds


class NMS:
class NMSOpenVINO:
eaidova marked this conversation as resolved.
Show resolved Hide resolved
def __init__(self, kernel):
self.ie = IECore()
self.net = self.compose(kernel)
Expand All @@ -931,6 +931,46 @@ def compose(kernel):
f = ng.impl.Function([ng.result(nms_heatmap, name='nms_heatmaps')], [heatmap], 'nms')
net = IENetwork(ng.impl.Function.to_capsule(f))
return net


class NMSSKImage:
def __init__(self, kernel):
self.kernel = kernel
self.pad = (kernel - 1) // 2

def max_pool(self, x):
from skimage.measure import block_reduce

# Max pooling kernel x kernel with stride 1 x 1.
k = self.kernel
p = self.pad
pooled = np.zeros_like(x)
hmap = np.pad(x, ((0, 0), (0, 0), (p, p), (p, p)))
h, w = x.shape[-2:]
for i in range(k):
si = (h + 2 * p - i) // k
for j in range(k):
sj = (w + 2 * p - j) // k
hmap_slice = hmap[..., i:i + si * k, j:j + sj * k]
pooled[..., i::k, j::k] = block_reduce(hmap_slice, (1, 1, k, k), np.max)
return x

def __call__(self, heatmaps):
pooled = self.max_pool(heatmaps)
return heatmaps * (pooled == heatmaps).astype(heatmaps.dtype)


class NMSPyTorch:
eaidova marked this conversation as resolved.
Show resolved Hide resolved
def __init__(self, kernel, device='cpu'):
self.kernel = kernel
self.pad = (kernel - 1) // 2
self.device = device

def __call__(self, heatmaps):
heatmaps = torch.as_tensor(heatmaps, device=self.device)
maxm = torch.nn.functional.max_pool2d(heatmaps, kernel_size=self.kernel, stride=1, padding=self.pad)
maxm = torch.eq(maxm, heatmaps)
return (heatmaps * maxm).cpu().numpy()


class OpenPoseDecoder:
Expand All @@ -949,35 +989,6 @@ def __init__(self, num_joints, max_points=100, score_threshold=0.1, delta=0.5, o
self.high_res_heatmaps = False
self.high_res_pafs = False

self.nms_kernel = 3
self.nms_ov = NMS(self.nms_kernel)

def nms_skimage(self, heatmaps, kernel):
from skimage.measure import block_reduce

# Max pooling kernel x kernel with stride 1 x 1.
p = (kernel - 1) // 2
pooled = np.zeros(heatmaps.shape, dtype=np.float32)
hmap = np.pad(heatmaps, ((0, 0), (0, 0), (p, p), (p, p)))
h, w = heatmaps.shape[-2:]
for i in range(kernel):
si = (h + 2 * p - i) // kernel
for j in range(kernel):
sj = (w + 2 * p - j) // kernel
pooled[..., i::kernel, j::kernel] = block_reduce(hmap[..., i:i + si * kernel, j:j + sj * kernel], (1, 1, kernel, kernel), np.max)
return heatmaps * (pooled == heatmaps).astype(heatmaps.dtype)

def nms_pytorch(self, heatmaps, kernel, device='cpu'):
heatmaps = torch.as_tensor(heatmaps, device=device)
maxm = torch.nn.functional.max_pool2d(heatmaps, kernel_size=kernel, stride=1, padding=(kernel - 1) // 2)
maxm = torch.eq(maxm, heatmaps).float()
return (heatmaps * maxm).cpu().numpy()

def nms(self, heatmaps):
# return self.nms_ov(heatmaps)
return self.nms_skimage(heatmaps, self.nms_kernel)
# return self.nms_pytorch(heatmaps, self.nms_kernel)

def __call__(self, heatmaps, nms_heatmaps, pafs):
batch_size, _, h, w = heatmaps.shape
assert batch_size == 1, 'Batch size of 1 only supported'
Expand Down