1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Prepare CSV URL for LFPW"
]
},
{
"cell_type": "code",
"execution_count": 17,
"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",
"import hashlib\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 Image Download"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"fp_in_train = '/data_store/datasets/people/lfpw/downloads/kbvt_lfpw_v1_train.csv'\n",
"fp_in_test = '/data_store/datasets/people/lfpw/downloads/kbvt_lfpw_v1_test.csv'\n",
"fp_out = '/data_store/datasets/people/lfpw/downloads/urls.csv'"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"df_train = pd.read_csv(fp_in_train, sep='\\t')\n",
"df_test = pd.read_csv(fp_in_test, sep='\\t')\n",
"df = pd.concat([df_test, df_train], sort=False)\n",
"records = df.to_dict('records')"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
"urlmaps = []\n",
"for record in records:\n",
" url = record['imgurl']\n",
" ext = Path(url).suffix.lower()\n",
" if ext == '.jpeg':\n",
" ext = '.jpg'\n",
" if ext != '':\n",
" ext = '.jpg'\n",
" sha256 = hashlib.sha256(str.encode(url)).hexdigest()\n",
" filepath = sha256 + ext\n",
" urlmaps.append({'url':url, 'filepath':filepath})"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"df_urls = pd.DataFrame.from_dict(urlmaps)\n",
"df_urls.to_csv(fp_out, index=False)"
]
}
],
"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
}
|