Last active
August 28, 2020 20:02
-
-
Save bedilbek/3937154a784375471e935dc830abf489 to your computer and use it in GitHub Desktop.
GluonCV Human Pose.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "GluonCV Human Pose.ipynb", | |
"provenance": [], | |
"private_outputs": true, | |
"collapsed_sections": [], | |
"authorship_tag": "ABX9TyPBkf+YrdikDI3lgVd0yk+r", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"accelerator": "GPU" | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/bedilbek/3937154a784375471e935dc830abf489/gluoncv-human-pose.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "5VVMsTJ7n1PA", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"!pip install --upgrade mxnet gluoncv" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "vxeVNi_jn-zR", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"from matplotlib import pyplot as plt\n", | |
"from gluoncv import model_zoo, data, utils\n", | |
"from gluoncv.data.transforms.pose import detector_to_alpha_pose, heatmap_to_coord_alpha_pose" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "emN8mtG8pNp1", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"detector = model_zoo.get_model('yolo3_mobilenet1.0_coco', pretrained=True)\n", | |
"pose_net = model_zoo.get_model('alpha_pose_resnet101_v1b_coco', pretrained=True)\n", | |
"\n", | |
"# Note that we can reset the classes of the detector to only include\n", | |
"# human, so that the NMS process is faster.\n", | |
"\n", | |
"detector.reset_class([\"person\"], reuse_weights=['person'])" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "J3UcSuftpW4g", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"im_fname = utils.download('https://github.com/dmlc/web-data/blob/master/' +\n", | |
" 'gluoncv/pose/soccer.png?raw=true',\n", | |
" path='soccer.png')\n", | |
"x, img = data.transforms.presets.yolo.load_test(im_fname, short=512)\n", | |
"print('Shape of pre-processed image:', x.shape)\n", | |
"\n", | |
"class_IDs, scores, bounding_boxs = detector(x)" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "iNHEB1EUpZ1F", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"pose_input, upscale_bbox = detector_to_alpha_pose(img, class_IDs, scores, bounding_boxs)\n", | |
"predicted_heatmap = pose_net(pose_input)\n", | |
"pred_coords, confidence = heatmap_to_coord_alpha_pose(predicted_heatmap, upscale_bbox)" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "GagPXYvBphzF", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"ax = utils.viz.plot_keypoints(img, pred_coords, confidence,\n", | |
" class_IDs, bounding_boxs, scores,\n", | |
" box_thresh=0.5, keypoint_thresh=0.2)\n", | |
"plt.show()" | |
], | |
"execution_count": null, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment