summaryrefslogtreecommitdiff
path: root/megapixels/notebooks/datasets/helen
diff options
context:
space:
mode:
authoradamhrv <adam@ahprojects.com>2019-05-29 15:24:30 +0200
committeradamhrv <adam@ahprojects.com>2019-05-29 15:24:30 +0200
commit5b916111ee1a012650a586ec07bc9150d66020bc (patch)
tree128092857e6a9b6d67877e55e05da4f99ea2f5eb /megapixels/notebooks/datasets/helen
parentf5141a7b48ee569089b07428bc75cb84a55c4834 (diff)
add MSC nbs and cli cmds
Diffstat (limited to 'megapixels/notebooks/datasets/helen')
-rw-r--r--megapixels/notebooks/datasets/helen/prepare_flickr_api.ipynb162
1 files changed, 162 insertions, 0 deletions
diff --git a/megapixels/notebooks/datasets/helen/prepare_flickr_api.ipynb b/megapixels/notebooks/datasets/helen/prepare_flickr_api.ipynb
new file mode 100644
index 00000000..311d3462
--- /dev/null
+++ b/megapixels/notebooks/datasets/helen/prepare_flickr_api.ipynb
@@ -0,0 +1,162 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# HELEN Prepare Flickr API"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "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 h5py\n",
+ "from scipy import misc\n",
+ "from io import BytesIO\n",
+ "from base64 import b64decode\n",
+ "\n",
+ "from PIL import Image, ImageDraw\n",
+ "%matplotlib inline\n",
+ "import matplotlib.pyplot as plt\n",
+ "import scipy.io as sio\n",
+ "import h5py\n",
+ "import numpy as np\n",
+ "import pandas as pd\n",
+ "import sys\n",
+ "sys.path.append('/work/megapixels_dev/megapixels/')\n",
+ "from app.utils import file_utils"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 16,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "fp_in = '/data_store/datasets/people/helen/research/flickr_photo_ids.txt'\n",
+ "fp_out = '/data_store/datasets/people/helen/research/helen_flickr_meta.csv'"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "photo_id_list = file_utils.load_text(fp_in)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "items = [{'photo_id': x.split('_')[0]} for x in photo_id_list]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df = pd.DataFrame.from_dict(items)\n",
+ "df.to_csv(fp_out, index=False)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Load Flickr API Dump\n",
+ "\n",
+ "- and create Flickr meta"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "fp_api_dump = '/data_store/datasets/people/helen/research/helen_flickr_api_dump.csv'\n",
+ "df = pd.read_csv(fp_api_dump)\n",
+ "#records = df.to_dict('records')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "groups = df.groupby('nsid')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "results = []\n",
+ "for nsid, group in groups:\n",
+ " obj = {\n",
+ " 'nsid': nsid,\n",
+ " 'count': len(group)\n",
+ " }\n",
+ " results.append(obj)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "pd.DataFrame.from_dict(results).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
+}