diff options
| author | adamhrv <adam@ahprojects.com> | 2019-05-29 15:24:30 +0200 |
|---|---|---|
| committer | adamhrv <adam@ahprojects.com> | 2019-05-29 15:24:30 +0200 |
| commit | 5b916111ee1a012650a586ec07bc9150d66020bc (patch) | |
| tree | 128092857e6a9b6d67877e55e05da4f99ea2f5eb /megapixels/notebooks/datasets/adience | |
| parent | f5141a7b48ee569089b07428bc75cb84a55c4834 (diff) | |
add MSC nbs and cli cmds
Diffstat (limited to 'megapixels/notebooks/datasets/adience')
| -rw-r--r-- | megapixels/notebooks/datasets/adience/flickr_metadata_cleanup.ipynb | 169 | ||||
| -rw-r--r-- | megapixels/notebooks/datasets/adience/prepare_flickr_api.ipynb | 188 |
2 files changed, 357 insertions, 0 deletions
diff --git a/megapixels/notebooks/datasets/adience/flickr_metadata_cleanup.ipynb b/megapixels/notebooks/datasets/adience/flickr_metadata_cleanup.ipynb new file mode 100644 index 00000000..69aaced4 --- /dev/null +++ b/megapixels/notebooks/datasets/adience/flickr_metadata_cleanup.ipynb @@ -0,0 +1,169 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Adience Flickr Metadata Cleanup" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "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", + "\n", + "import sys\n", + "sys.path.append('/work/megapixels_dev/megapixels')\n", + "from app.utils import file_utils" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Load CSV" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [], + "source": [ + "fp_in_files = '/data_store_hdd/datasets/people/adience/research/adience_flickr_api_queries.csv'\n", + "fp_in_nsid_urls = '/data_store_hdd/datasets/people/adience/research/adience_flickr_nsid_url.csv'\n", + "fp_in_nsid_profiles = '/data_store_hdd/datasets/people/adience/research/adience_flickr_nsid_profile.csv'\n", + "fp_out = '/data_store_hdd/datasets/people/adience/research/adience_flickr_meta.csv'" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Create metadata csv output\n", + "\n", + "|nsid|path_alias|count|" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [], + "source": [ + "# files\n", + "df_files = pd.read_csv(fp_in_files)\n", + "df_files.fillna('', inplace=True)\n", + "files = df_files.to_dict('records')\n", + "\n", + "# nsid urls\n", + "df_urls = pd.read_csv(fp_in_nsid_urls)\n", + "df_urls.fillna('', inplace=True)\n", + "urls = df_urls.to_dict('records')\n", + "\n", + "# nsid profiles\n", + "df_profiles = pd.read_csv(fp_in_nsid_profiles)\n", + "df_profiles.fillna('', inplace=True)\n", + "profiles = df_profiles.to_dict('records')" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [], + "source": [ + "# create nsid lookup table\n", + "alias_lookup = {}\n", + "for url_meta in urls:\n", + " alias_lookup[url_meta['nsid']] = str(Path(url_meta['url']).stem)" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [], + "source": [ + "nsid_groups = df_files.groupby('nsid')" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Skipping: 10693681@N00\n", + "Skipping: 10743505@N04\n", + "Skipping: 113728563@N05\n", + "Skipping: 7648211@N03\n" + ] + } + ], + "source": [ + "items = []\n", + "for nsid, nsid_group in nsid_groups:\n", + " if nsid not in alias_lookup.keys():\n", + " print(f'Skipping: {nsid}')\n", + " continue\n", + " path_alias = alias_lookup[nsid]\n", + " obj = {'nsid': nsid, 'path_alias': path_alias, 'count': len(nsid_group)}\n", + " items.append(obj)" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [], + "source": [ + "df_out = pd.DataFrame.from_dict(items)\n", + "df_out.to_csv(fp_out, index=False)" + ] + }, + { + "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 +} diff --git a/megapixels/notebooks/datasets/adience/prepare_flickr_api.ipynb b/megapixels/notebooks/datasets/adience/prepare_flickr_api.ipynb new file mode 100644 index 00000000..a35c3b24 --- /dev/null +++ b/megapixels/notebooks/datasets/adience/prepare_flickr_api.ipynb @@ -0,0 +1,188 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Prepare Flickr API Batch CSV" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "%reload_ext autoreload\n", + "%autoreload 2\n", + "\n", + "import os\n", + "from os.path import join\n", + "from glob import glob, iglob\n", + "from pathlib import Path\n", + "from tqdm import tqdm_notebook as tqdm\n", + "\n", + "import pandas as pd" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create CSV for API" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "| filepath | query | count |\n", + "|:---|:---|:---|\n", + "| 12234 | 12234@123| 10 |" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "fp_in_dir = '/data_store/datasets/people/adience/dataset/'\n", + "fp_out_queries = '/data_store/datasets/people/adience/research/adience_flickr_api_queries.csv'" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "9\n" + ] + } + ], + "source": [ + "fp_files = glob(join(fp_in_dir, '*.txt'))\n", + "print(len(fp_files))" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [], + "source": [ + "df_images = pd.DataFrame()\n", + "for fp_file in fp_files:\n", + " df = pd.read_csv(fp_file, delimiter='\\t')\n", + " if 'user_id' in df.keys():\n", + " df = df[['user_id', 'original_image']]\n", + " df_images = dfs.append(df, ignore_index=True) " + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [], + "source": [ + "df_images.drop_duplicates(inplace=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [], + "source": [ + "images = df_images.to_dict('records')" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [], + "source": [ + "for image in images:\n", + " image['photo_id'] = image['original_image'].split('_')[0]\n", + " image['filename'] = f'{image[\"photo_id\"]}.json'" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [], + "source": [ + "df_images = pd.DataFrame.from_dict(images)" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [], + "source": [ + "df_images.drop(columns=['original_image'], inplace=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10804\n" + ] + } + ], + "source": [ + "print(len(df_images))" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [], + "source": [ + "df_images.to_csv(fp_out_queries, index=False)" + ] + }, + { + "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 +} |
