Skip to content

Commit ab1a0b8

Browse files
author
Sven Kreiss
authored
compatibility for OpenPifPaf v0.12.5 (#34)
1 parent c21b52b commit ab1a0b8

File tree

6 files changed

+40
-27
lines changed

6 files changed

+40
-27
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ the browser cache for static assets and autoreload when source files change.
8383
# Citation
8484
8585
```
86+
@article{kreiss2021openpifpaf,
87+
title = {{OpenPifPaf: Composite Fields for Semantic Keypoint Detection and Spatio-Temporal Association}},
88+
author = {Sven Kreiss and Lorenzo Bertoni and Alexandre Alahi},
89+
journal = {arXiv preprint arXiv:2103.02440},
90+
month = {March},
91+
year = {2021}
92+
}
93+
8694
@InProceedings{kreiss2019pifpaf,
8795
author = {Kreiss, Sven and Bertoni, Lorenzo and Alahi, Alexandre},
8896
title = {PifPaf: Composite Fields for Human Pose Estimation},

js/src/visualization.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export class Visualization {
4747

4848
draw(image: Blob, data) {
4949
if (data === null) return;
50+
console.log(data);
5051
const annotations = data.annotations;
5152

5253
// adjust height of output canvas

openpifpafwebdemo/handlers/human_poses.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ async def post(self): # pylint: disable=arguments-differ
3232
if not key.validate(channel_id):
3333
return
3434

35-
annotations = self.application.processor.single_image(image, resize=resize)
36-
await self.finish(json.dumps({'channel': channel_id, 'annotations': annotations}))
35+
out_data = self.application.processor.single_image(image, resize=resize)
36+
out_data['channel'] = channel_id
37+
await self.finish(json.dumps(out_data))
3738

3839
channel_name = 'channel:{}'.format(channel_id)
3940
LOG.info('publishing to %s', channel_name)
40-
self.application.signal.emit(channel_name, annotations)
41+
self.application.signal.emit(channel_name, out_data)
4142

4243
def options(self):
4344
self.set_default_headers()

openpifpafwebdemo/processor.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@
1010
LOG = logging.getLogger(__name__)
1111

1212

13-
class Processor(object):
13+
class Processor:
1414
def __init__(self, width_height, args):
1515
self.width_height = width_height
1616

1717
# load model
18-
model_cpu, _ = openpifpaf.network.factory_from_args(args)
18+
model_cpu, _ = openpifpaf.network.Factory().factory()
1919
self.model = model_cpu.to(args.device)
2020
head_metas = [hn.meta for hn in model_cpu.head_nets]
2121
self.processor = openpifpaf.decoder.factory(head_metas)
2222
self.device = args.device
2323

2424
def single_image(self, image_bytes, *, resize=True):
25+
start = time.perf_counter()
2526
im = PIL.Image.open(io.BytesIO(image_bytes)).convert('RGB')
2627

2728
if resize:
@@ -30,26 +31,29 @@ def single_image(self, image_bytes, *, resize=True):
3031
target_wh = (target_wh[1], target_wh[0])
3132
if im.size[0] != target_wh[0] or im.size[1] != target_wh[1]:
3233
LOG.warning('have to resize image to %s from %s', target_wh, im.size)
33-
im = im.resize(target_wh, PIL.Image.BICUBIC)
34+
im = im.resize(target_wh, PIL.Image.BILINEAR)
3435
width_height = im.size
3536

36-
start = time.time()
3737
preprocess = openpifpaf.transforms.EVAL_TRANSFORM
3838
processed_image = preprocess(im, [], None)[0]
39-
LOG.debug('preprocessing time: %.3f', time.time() - start)
39+
preprocessing_time = time.perf_counter() - start
4040

4141
image_tensors_batch = torch.unsqueeze(processed_image.float(), 0)
4242
pred_anns = self.processor.batch(self.model, image_tensors_batch, device=self.device)[0]
4343

44-
json_data = [(ann
44+
json_anns = [(ann
4545
.rescale((1.0 / width_height[0], 1.0 / width_height[1]))
4646
.json_data(coordinate_digits=5))
4747
for ann in pred_anns]
48-
for d in json_data:
48+
for d in json_anns:
4949
d['keypoints'] = list(zip(
5050
d['keypoints'][0::3],
5151
d['keypoints'][1::3],
5252
d['keypoints'][2::3],
5353
))
54-
d['width_height'] = width_height
55-
return json_data
54+
55+
return {
56+
'annotations': json_anns,
57+
'width_height': width_height,
58+
'preprocessing_ms': round(preprocessing_time * 1000.0, 1),
59+
}

openpifpafwebdemo/server.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
from . import handlers
2222
from .signal import Signal
2323

24+
LOG = logging.getLogger(__name__)
25+
2426

2527
async def grep_static(dest, url='http://127.0.0.1:5000'):
2628
http_client = tornado.httpclient.AsyncHTTPClient()
@@ -40,7 +42,8 @@ def cli():
4042
)
4143

4244
openpifpaf.decoder.cli(parser)
43-
openpifpaf.network.cli(parser)
45+
openpifpaf.logger.cli(parser)
46+
openpifpaf.network.Factory.cli(parser)
4447

4548
parser.add_argument('--disable-cuda', action='store_true',
4649
help='disable CUDA')
@@ -51,8 +54,6 @@ def cli():
5154
help='directory in which to create a static version of this page')
5255
parser.add_argument('--demo-password', default=None,
5356
help='password that allows better performance for a demo')
54-
parser.add_argument('--debug', default=False, action='store_true',
55-
help='debug messages and autoreload')
5657
parser.add_argument('--google-analytics',
5758
help='provide a google analytics id to inject analytics code')
5859

@@ -76,19 +77,17 @@ def cli():
7677

7778
args = parser.parse_args()
7879

79-
# log
80-
logging.basicConfig(level=logging.INFO if not args.debug else logging.DEBUG)
81-
8280
# configure
83-
openpifpaf.network.configure(args)
81+
openpifpaf.logger.configure(args, LOG)
82+
openpifpaf.network.Factory.configure(args)
8483

8584
# config
86-
logging.debug('host=%s, port=%d', args.host, args.port)
87-
logging.debug('Python %s, OpenPifPafWebDemo %s', sys.version, __version__)
85+
LOG.debug('host=%s, port=%d', args.host, args.port)
86+
LOG.debug('Python %s, OpenPifPafWebDemo %s', sys.version, __version__)
8887
if args.host in ('localhost', '127.0.0.1'):
89-
logging.info('Open http://%s:%d in a web browser.', args.host, args.port)
88+
LOG.info('Open http://%s:%d in a web browser.', args.host, args.port)
9089
if args.host != '0.0.0.0':
91-
logging.info('Access is restricted by IP address. Use --host=0.0.0.0 to allow all.')
90+
LOG.info('Access is restricted by IP address. Use --host=0.0.0.0 to allow all.')
9291

9392
# add args.device
9493
args.device = torch.device('cpu')
@@ -109,7 +108,7 @@ def main():
109108
args = cli()
110109
width_height = (int(640 * args.resolution // 16) * 16 + 1,
111110
int(480 * args.resolution // 16) * 16 + 1)
112-
logging.debug('target width and height = %s', width_height)
111+
LOG.debug('target width and height = %s', width_height)
113112
processor_singleton = Processor(width_height, args)
114113

115114
static_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'static')
@@ -123,7 +122,7 @@ def main():
123122
tornado.autoreload.watch('openpifpafwebdemo/static/frontend.js')
124123
tornado.autoreload.watch('openpifpafwebdemo/static/clientside.js')
125124

126-
if args.debug:
125+
if LOG.getEffectiveLevel() == logging.DEBUG:
127126
version = '{}-{}'.format(
128127
__version__,
129128
''.join(random.choices(string.ascii_lowercase + string.digits, k=4))
@@ -185,7 +184,7 @@ def main():
185184
'keyfile': os.path.join(module_dir, 'test', 'test.key'),
186185
}
187186

188-
logging.info('Open https://%s:%d in a web browser.', args.host, args.ssl_port)
187+
LOG.info('Open https://%s:%d in a web browser.', args.host, args.ssl_port)
189188
app.listen(args.ssl_port, ssl_options=ssl_ctx)
190189

191190
try:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
include_package_data=True,
1818

1919
install_requires=[
20-
'openpifpaf>=0.12b2',
20+
'openpifpaf>=0.12.5',
2121
'tornado>=6',
2222
],
2323
extras_require={

0 commit comments

Comments
 (0)