diff options
Diffstat (limited to 'megapixels/notebooks/datasets/leeds_sports_pose')
| -rw-r--r-- | megapixels/notebooks/datasets/leeds_sports_pose/leeds_sports_pose_exif.ipynb | 270 |
1 files changed, 270 insertions, 0 deletions
diff --git a/megapixels/notebooks/datasets/leeds_sports_pose/leeds_sports_pose_exif.ipynb b/megapixels/notebooks/datasets/leeds_sports_pose/leeds_sports_pose_exif.ipynb new file mode 100644 index 00000000..1fc5c795 --- /dev/null +++ b/megapixels/notebooks/datasets/leeds_sports_pose/leeds_sports_pose_exif.ipynb @@ -0,0 +1,270 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Extract EXIF Leeds Sports" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [], + "source": [ + "%reload_ext autoreload\n", + "%autoreload 2\n", + "\n", + "import os\n", + "from os.path import join\n", + "from glob import glob\n", + "from pathlib import Path\n", + "\n", + "from tqdm import tqdm_notebook as tqdm\n", + "import pandas as pd\n", + "import numpy as np\n", + "from PIL import Image\n", + "from pprint import pprint\n", + "\n", + "import sys\n", + "sys.path.append('/work/megapixels_dev/megapixels')\n", + "from app.utils import api_utils, identity_utils" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create CSV for API" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [], + "source": [ + "from PIL import ExifTags\n", + "fp_in = '/data_store_hdd/datasets/people/leeds_sports_pose_extended/images/'" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [], + "source": [ + "files = glob(join(fp_in, '*.jpg'))" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2000\n" + ] + } + ], + "source": [ + "print(len(files))" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": {}, + "outputs": [], + "source": [ + "for fp_im in files:\n", + " im = Image.open(fp_im)\n", + " exif_data = im._getexif()\n", + " if exif_data is not None:\n", + " for k, v in exif_data.items():\n", + " if k in ExifTags.TAGS:\n", + " print(k)" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "None\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "ename": "AttributeError", + "evalue": "'NoneType' object has no attribute 'items'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m<ipython-input-33-1ba2fdff1ff5>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mfor\u001b[0m \u001b[0mk\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mv\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mexif_data\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mk\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mExifTags\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mTAGS\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mAttributeError\u001b[0m: 'NoneType' object has no attribute 'items'" + ] + } + ], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": {}, + "outputs": [], + "source": [ + "import exifread\n", + "fp_im = '/data_store_hdd/datasets/people/ucf_crowd/UCF_CC_50/1.jpg'\n", + "# Open image file for reading (binary mode)\n", + "f = open(fp_im, 'rb')\n", + "\n", + "# Return Exif tags\n", + "tags = exifread.process_file(f)" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{}\n" + ] + } + ], + "source": [ + "print(tags)" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "metadata": {}, + "outputs": [], + "source": [ + "fp_mat = '/data_store_hdd/datasets/people/leeds_sports_pose_extended/joints.mat'\n", + "fp_mat = '/data_store/datasets/people/tinyface/downloads/tinyface/Testing_Set/gallery_match_img_ID_pairs.mat'\n", + "fp_mat = '/data_store_hdd/datasets/people/ucf_crowd/UCF_CC_50/1_ann.mat'" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "metadata": {}, + "outputs": [], + "source": [ + "import scipy.io as sio" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": {}, + "outputs": [], + "source": [ + "mat_deta = sio.loadmat(fp_mat)" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dict_keys(['__header__', '__version__', '__globals__', 'annPoints'])" + ] + }, + "execution_count": 58, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mat_deta.keys()" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[ 2.41103261, 25.1202232 ],\n", + " [ 7.99013974, 20.64353926],\n", + " [ 14.6850683 , 25.67980869],\n", + " ...,\n", + " [108.97197886, 19.80416102],\n", + " [363.37926414, 60.09431646],\n", + " [355.01060344, 61.77307294]])" + ] + }, + "execution_count": 59, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mat_deta['annPoints']" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "megapixels", + "language": "python", + "name": "megapixels" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.8" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} |
