<jupyter_start><jupyter_text>[<NAME>](https://www.svenkreiss.com/), 2019 OpenPifPaf Prediction DemoProgrammatically use OpenPifPaf to run multi-person pose estimation on an image.<jupyter_code># Uncomment when using on Google Colab:
# !pip install --upgrade openpifpaf==0.11.1
%matplotlib inline

import io
import numpy as np
import openpifpaf
import PIL
import requests
import torch

device = torch.device('cpu')
# device = torch.device('cuda')  # if cuda is available

print(openpifpaf.__version__)
print(torch.__version__)<jupyter_output>0.12b2+5.g5d9a208.dirty
1.7.1<jupyter_text>Load an Example Image and Display ItImage credit: "[Learning to surf](https://www.flickr.com/photos/fotologic/6038911779/in/photostream/)" by fotologic which is licensed under [CC-BY-2.0].[CC-BY-2.0]: https://creativecommons.org/licenses/by/2.0/<jupyter_code>image_response = requests.get('https://raw.githubusercontent.com/vita-epfl/openpifpaf/main/docs/coco/000000081988.jpg')
pil_im = PIL.Image.open(io.BytesIO(image_response.content)).convert('RGB')
im = np.asarray(pil_im)

with openpifpaf.show.image_canvas(im) as ax:
  pass<jupyter_output><empty_output><jupyter_text>Load a Trained Neural Network<jupyter_code>net_cpu, _ = openpifpaf.network.Factory(checkpoint='shufflenetv2k16').factory()
net = net_cpu.to(device)

openpifpaf.decoder.utils.CifSeeds.threshold = 0.5
openpifpaf.decoder.utils.nms.Keypoints.keypoint_threshold = 0.2
openpifpaf.decoder.utils.nms.Keypoints.instance_threshold = 0.2
processor = openpifpaf.decoder.factory([hn.meta for hn in net.head_nets])<jupyter_output><empty_output><jupyter_text>Dataset, Dataloader, Visualizer, Prediction<jupyter_code>data = openpifpaf.datasets.PilImageList([pil_im])
loader = torch.utils.data.DataLoader(
  data, batch_size=1, pin_memory=True, 
  collate_fn=openpifpaf.datasets.collate_images_anns_meta)

openpifpaf.show.Canvas.show = True
annotation_painter = openpifpaf.show.AnnotationPainter()

for images_batch, _, __ in loader:
  predictions = processor.batch(net, images_batch, device=device)[0]
  with openpifpaf.show.image_canvas(im) as ax:
    annotation_painter.annotations(ax, predictions)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12154696132596685, 'fraction_numerical': 0.027624309392265192, 'mean_word_length': 6.788530465949821, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '25350', 'license': 'CC-BY-2.0', 'n_tokens_mistral': 858, 'n_tokens_neox': 807, 'n_words': 127, 'path': 'docs/predict.ipynb', 'repo_name': 'adujardin/openpifpaf', 'size': '2177'}