[update] images-sample
Browse files
data/images_5k.tar.gz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:34abe889037a8b8640821de4e444ee0313448af8fb2d709e68bb30e5c373e547
|
| 3 |
+
size 656457088
|
notebooks/.ipynb_checkpoints/Test-checkpoint.ipynb
CHANGED
|
@@ -1,6 +1,209 @@
|
|
| 1 |
{
|
| 2 |
-
"cells": [
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
"nbformat": 4,
|
| 5 |
"nbformat_minor": 5
|
| 6 |
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"id": "a25ac442",
|
| 6 |
+
"metadata": {},
|
| 7 |
+
"source": [
|
| 8 |
+
"## Performance HuggingFace Dataset vs Dataset Loader"
|
| 9 |
+
]
|
| 10 |
+
},
|
| 11 |
+
{
|
| 12 |
+
"cell_type": "markdown",
|
| 13 |
+
"id": "3da127dc",
|
| 14 |
+
"metadata": {},
|
| 15 |
+
"source": [
|
| 16 |
+
"## Hugging Face Dataset"
|
| 17 |
+
]
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"cell_type": "code",
|
| 21 |
+
"execution_count": 34,
|
| 22 |
+
"id": "aef315bf",
|
| 23 |
+
"metadata": {},
|
| 24 |
+
"outputs": [],
|
| 25 |
+
"source": [
|
| 26 |
+
"from datasets import load_dataset\n",
|
| 27 |
+
"import torch\n",
|
| 28 |
+
"import glob"
|
| 29 |
+
]
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"cell_type": "code",
|
| 33 |
+
"execution_count": 63,
|
| 34 |
+
"id": "c0ed6498",
|
| 35 |
+
"metadata": {},
|
| 36 |
+
"outputs": [
|
| 37 |
+
{
|
| 38 |
+
"name": "stderr",
|
| 39 |
+
"output_type": "stream",
|
| 40 |
+
"text": [
|
| 41 |
+
"Found cached dataset ava (/home/william/.cache/huggingface/datasets/will33am___ava/default/1.0.0/723cc8bd5959ef1cd88b7d51648a8bc7fd98c9d8ddb768cb8c8ebaade1b82306)\n"
|
| 42 |
+
]
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"name": "stdout",
|
| 46 |
+
"output_type": "stream",
|
| 47 |
+
"text": [
|
| 48 |
+
"CPU times: user 211 ms, sys: 11.8 ms, total: 223 ms\n",
|
| 49 |
+
"Wall time: 852 ms\n"
|
| 50 |
+
]
|
| 51 |
+
}
|
| 52 |
+
],
|
| 53 |
+
"source": [
|
| 54 |
+
"%%time\n",
|
| 55 |
+
"ds = load_dataset(\"will33am/AVA\",split = 'train')\n",
|
| 56 |
+
"ds = ds.remove_columns([\"rating_counts\",\"text_tag_0\",\"text_tag_1\"])"
|
| 57 |
+
]
|
| 58 |
+
},
|
| 59 |
+
{
|
| 60 |
+
"cell_type": "code",
|
| 61 |
+
"execution_count": 66,
|
| 62 |
+
"id": "c51e48dd",
|
| 63 |
+
"metadata": {},
|
| 64 |
+
"outputs": [
|
| 65 |
+
{
|
| 66 |
+
"name": "stdout",
|
| 67 |
+
"output_type": "stream",
|
| 68 |
+
"text": [
|
| 69 |
+
"CPU times: user 7.3 ms, sys: 644 µs, total: 7.94 ms\n",
|
| 70 |
+
"Wall time: 6.24 ms\n"
|
| 71 |
+
]
|
| 72 |
+
}
|
| 73 |
+
],
|
| 74 |
+
"source": [
|
| 75 |
+
"%%time\n",
|
| 76 |
+
"image = ds[0]['image']"
|
| 77 |
+
]
|
| 78 |
+
},
|
| 79 |
+
{
|
| 80 |
+
"cell_type": "markdown",
|
| 81 |
+
"id": "25b4bd86",
|
| 82 |
+
"metadata": {},
|
| 83 |
+
"source": [
|
| 84 |
+
"## Pytorch Dataset"
|
| 85 |
+
]
|
| 86 |
+
},
|
| 87 |
+
{
|
| 88 |
+
"cell_type": "code",
|
| 89 |
+
"execution_count": 30,
|
| 90 |
+
"id": "07480450",
|
| 91 |
+
"metadata": {},
|
| 92 |
+
"outputs": [],
|
| 93 |
+
"source": [
|
| 94 |
+
"from PIL import Image\n",
|
| 95 |
+
"class Datasets(torch.utils.data.Dataset):\n",
|
| 96 |
+
" def __init__(self,files):\n",
|
| 97 |
+
" self.files = files\n",
|
| 98 |
+
" def __getitem__(self,idx):\n",
|
| 99 |
+
" return Image.open(self.files[idx])\n",
|
| 100 |
+
" \n",
|
| 101 |
+
" def __len__(self):\n",
|
| 102 |
+
" return len(self.files)"
|
| 103 |
+
]
|
| 104 |
+
},
|
| 105 |
+
{
|
| 106 |
+
"cell_type": "code",
|
| 107 |
+
"execution_count": 31,
|
| 108 |
+
"id": "7dcb29a3",
|
| 109 |
+
"metadata": {},
|
| 110 |
+
"outputs": [],
|
| 111 |
+
"source": [
|
| 112 |
+
"files = glob.glob(\"../../AVA_src/images/images/*.jpg\")\n",
|
| 113 |
+
"dataset = Datasets(files)"
|
| 114 |
+
]
|
| 115 |
+
},
|
| 116 |
+
{
|
| 117 |
+
"cell_type": "code",
|
| 118 |
+
"execution_count": 53,
|
| 119 |
+
"id": "43c33afc",
|
| 120 |
+
"metadata": {},
|
| 121 |
+
"outputs": [
|
| 122 |
+
{
|
| 123 |
+
"name": "stdout",
|
| 124 |
+
"output_type": "stream",
|
| 125 |
+
"text": [
|
| 126 |
+
"CPU times: user 1.21 ms, sys: 0 ns, total: 1.21 ms\n",
|
| 127 |
+
"Wall time: 656 µs\n"
|
| 128 |
+
]
|
| 129 |
+
}
|
| 130 |
+
],
|
| 131 |
+
"source": [
|
| 132 |
+
"%%time\n",
|
| 133 |
+
"image = dataset[0]"
|
| 134 |
+
]
|
| 135 |
+
},
|
| 136 |
+
{
|
| 137 |
+
"cell_type": "code",
|
| 138 |
+
"execution_count": 58,
|
| 139 |
+
"id": "771fe113",
|
| 140 |
+
"metadata": {},
|
| 141 |
+
"outputs": [
|
| 142 |
+
{
|
| 143 |
+
"data": {
|
| 144 |
+
"text/plain": [
|
| 145 |
+
"10.731707317073171"
|
| 146 |
+
]
|
| 147 |
+
},
|
| 148 |
+
"execution_count": 58,
|
| 149 |
+
"metadata": {},
|
| 150 |
+
"output_type": "execute_result"
|
| 151 |
+
}
|
| 152 |
+
],
|
| 153 |
+
"source": [
|
| 154 |
+
"# 10 veces mas rapido acceder a un elemento\n",
|
| 155 |
+
"(7.04e-3)/(656 * 1e-6 )"
|
| 156 |
+
]
|
| 157 |
+
}
|
| 158 |
+
],
|
| 159 |
+
"metadata": {
|
| 160 |
+
"kernelspec": {
|
| 161 |
+
"display_name": "huggingface",
|
| 162 |
+
"language": "python",
|
| 163 |
+
"name": "huggingface"
|
| 164 |
+
},
|
| 165 |
+
"language_info": {
|
| 166 |
+
"codemirror_mode": {
|
| 167 |
+
"name": "ipython",
|
| 168 |
+
"version": 3
|
| 169 |
+
},
|
| 170 |
+
"file_extension": ".py",
|
| 171 |
+
"mimetype": "text/x-python",
|
| 172 |
+
"name": "python",
|
| 173 |
+
"nbconvert_exporter": "python",
|
| 174 |
+
"pygments_lexer": "ipython3",
|
| 175 |
+
"version": "3.8.15"
|
| 176 |
+
},
|
| 177 |
+
"varInspector": {
|
| 178 |
+
"cols": {
|
| 179 |
+
"lenName": 16,
|
| 180 |
+
"lenType": 16,
|
| 181 |
+
"lenVar": 40
|
| 182 |
+
},
|
| 183 |
+
"kernels_config": {
|
| 184 |
+
"python": {
|
| 185 |
+
"delete_cmd_postfix": "",
|
| 186 |
+
"delete_cmd_prefix": "del ",
|
| 187 |
+
"library": "var_list.py",
|
| 188 |
+
"varRefreshCmd": "print(var_dic_list())"
|
| 189 |
+
},
|
| 190 |
+
"r": {
|
| 191 |
+
"delete_cmd_postfix": ") ",
|
| 192 |
+
"delete_cmd_prefix": "rm(",
|
| 193 |
+
"library": "var_list.r",
|
| 194 |
+
"varRefreshCmd": "cat(var_dic_list()) "
|
| 195 |
+
}
|
| 196 |
+
},
|
| 197 |
+
"types_to_exclude": [
|
| 198 |
+
"module",
|
| 199 |
+
"function",
|
| 200 |
+
"builtin_function_or_method",
|
| 201 |
+
"instance",
|
| 202 |
+
"_Feature"
|
| 203 |
+
],
|
| 204 |
+
"window_display": false
|
| 205 |
+
}
|
| 206 |
+
},
|
| 207 |
"nbformat": 4,
|
| 208 |
"nbformat_minor": 5
|
| 209 |
}
|
notebooks/Test.ipynb
CHANGED
|
@@ -1,138 +1,159 @@
|
|
| 1 |
{
|
| 2 |
"cells": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
{
|
| 4 |
"cell_type": "code",
|
| 5 |
-
"execution_count":
|
| 6 |
"id": "aef315bf",
|
| 7 |
"metadata": {},
|
| 8 |
"outputs": [],
|
| 9 |
"source": [
|
| 10 |
-
"from datasets import load_dataset"
|
|
|
|
|
|
|
| 11 |
]
|
| 12 |
},
|
| 13 |
{
|
| 14 |
"cell_type": "code",
|
| 15 |
-
"execution_count":
|
| 16 |
"id": "c0ed6498",
|
| 17 |
"metadata": {},
|
| 18 |
"outputs": [
|
| 19 |
{
|
| 20 |
-
"
|
| 21 |
-
"application/vnd.jupyter.widget-view+json": {
|
| 22 |
-
"model_id": "cd5f00716a7c42bd9962e71e5585e952",
|
| 23 |
-
"version_major": 2,
|
| 24 |
-
"version_minor": 0
|
| 25 |
-
},
|
| 26 |
-
"text/plain": [
|
| 27 |
-
"Downloading builder script: 0%| | 0.00/2.17k [00:00<?, ?B/s]"
|
| 28 |
-
]
|
| 29 |
-
},
|
| 30 |
-
"metadata": {},
|
| 31 |
-
"output_type": "display_data"
|
| 32 |
-
},
|
| 33 |
-
{
|
| 34 |
-
"name": "stdout",
|
| 35 |
"output_type": "stream",
|
| 36 |
"text": [
|
| 37 |
-
"
|
| 38 |
]
|
| 39 |
},
|
| 40 |
{
|
| 41 |
-
"
|
| 42 |
-
"application/vnd.jupyter.widget-view+json": {
|
| 43 |
-
"model_id": "40ff2d92e7a24fe4a1c169bb467e5dbc",
|
| 44 |
-
"version_major": 2,
|
| 45 |
-
"version_minor": 0
|
| 46 |
-
},
|
| 47 |
-
"text/plain": [
|
| 48 |
-
"Downloading data files: 0%| | 0/1 [00:00<?, ?it/s]"
|
| 49 |
-
]
|
| 50 |
-
},
|
| 51 |
-
"metadata": {},
|
| 52 |
-
"output_type": "display_data"
|
| 53 |
-
},
|
| 54 |
-
{
|
| 55 |
-
"name": "stderr",
|
| 56 |
"output_type": "stream",
|
| 57 |
"text": [
|
| 58 |
-
"
|
|
|
|
| 59 |
]
|
| 60 |
-
}
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
},
|
| 75 |
-
{
|
| 76 |
-
"data": {
|
| 77 |
-
"application/vnd.jupyter.widget-view+json": {
|
| 78 |
-
"model_id": "5133a8f32d5a44829a7e2e1df96b3216",
|
| 79 |
-
"version_major": 2,
|
| 80 |
-
"version_minor": 0
|
| 81 |
-
},
|
| 82 |
-
"text/plain": [
|
| 83 |
-
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 84 |
-
]
|
| 85 |
-
},
|
| 86 |
-
"metadata": {},
|
| 87 |
-
"output_type": "display_data"
|
| 88 |
-
},
|
| 89 |
{
|
| 90 |
-
"name": "
|
| 91 |
"output_type": "stream",
|
| 92 |
"text": [
|
| 93 |
-
"\n",
|
| 94 |
-
"
|
| 95 |
]
|
| 96 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
{
|
| 98 |
-
"
|
| 99 |
-
"
|
| 100 |
-
"
|
| 101 |
-
|
| 102 |
-
"\
|
| 103 |
-
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
|
| 104 |
-
"File \u001b[0;32m/opt/conda/envs/hugginface/lib/python3.8/site-packages/datasets/builder.py:1587\u001b[0m, in \u001b[0;36mGeneratorBasedBuilder._prepare_split_single\u001b[0;34m(self, gen_kwargs, fpath, file_format, max_shard_size, split_info, check_duplicate_keys, job_id)\u001b[0m\n\u001b[1;32m 1578\u001b[0m writer \u001b[38;5;241m=\u001b[39m writer_class(\n\u001b[1;32m 1579\u001b[0m features\u001b[38;5;241m=\u001b[39mwriter\u001b[38;5;241m.\u001b[39m_features,\n\u001b[1;32m 1580\u001b[0m path\u001b[38;5;241m=\u001b[39mfpath\u001b[38;5;241m.\u001b[39mreplace(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mSSSSS\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mshard_id\u001b[38;5;132;01m:\u001b[39;00m\u001b[38;5;124m05d\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\u001b[38;5;241m.\u001b[39mreplace(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mJJJJJ\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mjob_id\u001b[38;5;132;01m:\u001b[39;00m\u001b[38;5;124m05d\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m),\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 1585\u001b[0m embed_local_files\u001b[38;5;241m=\u001b[39membed_local_files,\n\u001b[1;32m 1586\u001b[0m )\n\u001b[0;32m-> 1587\u001b[0m example \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minfo\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfeatures\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mencode_example\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrecord\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39minfo\u001b[38;5;241m.\u001b[39mfeatures \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;28;01melse\u001b[39;00m record\n\u001b[1;32m 1588\u001b[0m writer\u001b[38;5;241m.\u001b[39mwrite(example, key)\n",
|
| 105 |
-
"File \u001b[0;32m/opt/conda/envs/hugginface/lib/python3.8/site-packages/datasets/features/features.py:1800\u001b[0m, in \u001b[0;36mFeatures.encode_example\u001b[0;34m(self, example)\u001b[0m\n\u001b[1;32m 1799\u001b[0m example \u001b[38;5;241m=\u001b[39m cast_to_python_objects(example)\n\u001b[0;32m-> 1800\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mencode_nested_example\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mexample\u001b[49m\u001b[43m)\u001b[49m\n",
|
| 106 |
-
"File \u001b[0;32m/opt/conda/envs/hugginface/lib/python3.8/site-packages/datasets/features/features.py:1202\u001b[0m, in \u001b[0;36mencode_nested_example\u001b[0;34m(schema, obj, level)\u001b[0m\n\u001b[1;32m 1200\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mGot None but expected a dictionary instead\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 1201\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m (\n\u001b[0;32m-> 1202\u001b[0m {\n\u001b[1;32m 1203\u001b[0m k: encode_nested_example(sub_schema, sub_obj, level\u001b[38;5;241m=\u001b[39mlevel \u001b[38;5;241m+\u001b[39m \u001b[38;5;241m1\u001b[39m)\n\u001b[1;32m 1204\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m k, (sub_schema, sub_obj) \u001b[38;5;129;01min\u001b[39;00m zip_dict(schema, obj)\n\u001b[1;32m 1205\u001b[0m }\n\u001b[1;32m 1206\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m obj \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 1207\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 1208\u001b[0m )\n\u001b[1;32m 1210\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(schema, (\u001b[38;5;28mlist\u001b[39m, \u001b[38;5;28mtuple\u001b[39m)):\n",
|
| 107 |
-
"File \u001b[0;32m/opt/conda/envs/hugginface/lib/python3.8/site-packages/datasets/features/features.py:1202\u001b[0m, in \u001b[0;36m<dictcomp>\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 1200\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mGot None but expected a dictionary instead\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 1201\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m (\n\u001b[0;32m-> 1202\u001b[0m {\n\u001b[1;32m 1203\u001b[0m k: encode_nested_example(sub_schema, sub_obj, level\u001b[38;5;241m=\u001b[39mlevel \u001b[38;5;241m+\u001b[39m \u001b[38;5;241m1\u001b[39m)\n\u001b[1;32m 1204\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m k, (sub_schema, sub_obj) \u001b[38;5;129;01min\u001b[39;00m zip_dict(schema, obj)\n\u001b[1;32m 1205\u001b[0m }\n\u001b[1;32m 1206\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m obj \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 1207\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 1208\u001b[0m )\n\u001b[1;32m 1210\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(schema, (\u001b[38;5;28mlist\u001b[39m, \u001b[38;5;28mtuple\u001b[39m)):\n",
|
| 108 |
-
"File \u001b[0;32m/opt/conda/envs/hugginface/lib/python3.8/site-packages/datasets/utils/py_utils.py:302\u001b[0m, in \u001b[0;36mzip_dict\u001b[0;34m(*dicts)\u001b[0m\n\u001b[1;32m 300\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m key \u001b[38;5;129;01min\u001b[39;00m unique_values(itertools\u001b[38;5;241m.\u001b[39mchain(\u001b[38;5;241m*\u001b[39mdicts)): \u001b[38;5;66;03m# set merge all keys\u001b[39;00m\n\u001b[1;32m 301\u001b[0m \u001b[38;5;66;03m# Will raise KeyError if the dict don't have the same keys\u001b[39;00m\n\u001b[0;32m--> 302\u001b[0m \u001b[38;5;28;01myield\u001b[39;00m key, \u001b[38;5;28;43mtuple\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43md\u001b[49m\u001b[43m[\u001b[49m\u001b[43mkey\u001b[49m\u001b[43m]\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43md\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mdicts\u001b[49m\u001b[43m)\u001b[49m\n",
|
| 109 |
-
"File \u001b[0;32m/opt/conda/envs/hugginface/lib/python3.8/site-packages/datasets/utils/py_utils.py:302\u001b[0m, in \u001b[0;36m<genexpr>\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 300\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m key \u001b[38;5;129;01min\u001b[39;00m unique_values(itertools\u001b[38;5;241m.\u001b[39mchain(\u001b[38;5;241m*\u001b[39mdicts)): \u001b[38;5;66;03m# set merge all keys\u001b[39;00m\n\u001b[1;32m 301\u001b[0m \u001b[38;5;66;03m# Will raise KeyError if the dict don't have the same keys\u001b[39;00m\n\u001b[0;32m--> 302\u001b[0m \u001b[38;5;28;01myield\u001b[39;00m key, \u001b[38;5;28mtuple\u001b[39m(\u001b[43md\u001b[49m\u001b[43m[\u001b[49m\u001b[43mkey\u001b[49m\u001b[43m]\u001b[49m \u001b[38;5;28;01mfor\u001b[39;00m d \u001b[38;5;129;01min\u001b[39;00m dicts)\n",
|
| 110 |
-
"\u001b[0;31mKeyError\u001b[0m: 'text_tag_0'",
|
| 111 |
-
"\nThe above exception was the direct cause of the following exception:\n",
|
| 112 |
-
"\u001b[0;31mDatasetGenerationError\u001b[0m Traceback (most recent call last)",
|
| 113 |
-
"File \u001b[0;32m<timed exec>:1\u001b[0m\n",
|
| 114 |
-
"File \u001b[0;32m/opt/conda/envs/hugginface/lib/python3.8/site-packages/datasets/load.py:1757\u001b[0m, in \u001b[0;36mload_dataset\u001b[0;34m(path, name, data_dir, data_files, split, cache_dir, features, download_config, download_mode, ignore_verifications, keep_in_memory, save_infos, revision, use_auth_token, task, streaming, num_proc, **config_kwargs)\u001b[0m\n\u001b[1;32m 1754\u001b[0m try_from_hf_gcs \u001b[38;5;241m=\u001b[39m path \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m _PACKAGED_DATASETS_MODULES\n\u001b[1;32m 1756\u001b[0m \u001b[38;5;66;03m# Download and prepare data\u001b[39;00m\n\u001b[0;32m-> 1757\u001b[0m \u001b[43mbuilder_instance\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdownload_and_prepare\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1758\u001b[0m \u001b[43m \u001b[49m\u001b[43mdownload_config\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mdownload_config\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1759\u001b[0m \u001b[43m \u001b[49m\u001b[43mdownload_mode\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mdownload_mode\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1760\u001b[0m \u001b[43m \u001b[49m\u001b[43mignore_verifications\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mignore_verifications\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1761\u001b[0m \u001b[43m \u001b[49m\u001b[43mtry_from_hf_gcs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtry_from_hf_gcs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1762\u001b[0m \u001b[43m \u001b[49m\u001b[43mnum_proc\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mnum_proc\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1763\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1765\u001b[0m \u001b[38;5;66;03m# Build dataset for splits\u001b[39;00m\n\u001b[1;32m 1766\u001b[0m keep_in_memory \u001b[38;5;241m=\u001b[39m (\n\u001b[1;32m 1767\u001b[0m keep_in_memory \u001b[38;5;28;01mif\u001b[39;00m keep_in_memory \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;28;01melse\u001b[39;00m is_small_dataset(builder_instance\u001b[38;5;241m.\u001b[39minfo\u001b[38;5;241m.\u001b[39mdataset_size)\n\u001b[1;32m 1768\u001b[0m )\n",
|
| 115 |
-
"File \u001b[0;32m/opt/conda/envs/hugginface/lib/python3.8/site-packages/datasets/builder.py:860\u001b[0m, in \u001b[0;36mDatasetBuilder.download_and_prepare\u001b[0;34m(self, output_dir, download_config, download_mode, ignore_verifications, try_from_hf_gcs, dl_manager, base_path, use_auth_token, file_format, max_shard_size, num_proc, storage_options, **download_and_prepare_kwargs)\u001b[0m\n\u001b[1;32m 858\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m num_proc \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 859\u001b[0m prepare_split_kwargs[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mnum_proc\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m num_proc\n\u001b[0;32m--> 860\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_download_and_prepare\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 861\u001b[0m \u001b[43m \u001b[49m\u001b[43mdl_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mdl_manager\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 862\u001b[0m \u001b[43m \u001b[49m\u001b[43mverify_infos\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mverify_infos\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 863\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mprepare_split_kwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 864\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mdownload_and_prepare_kwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 865\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 866\u001b[0m \u001b[38;5;66;03m# Sync info\u001b[39;00m\n\u001b[1;32m 867\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39minfo\u001b[38;5;241m.\u001b[39mdataset_size \u001b[38;5;241m=\u001b[39m \u001b[38;5;28msum\u001b[39m(split\u001b[38;5;241m.\u001b[39mnum_bytes \u001b[38;5;28;01mfor\u001b[39;00m split \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39minfo\u001b[38;5;241m.\u001b[39msplits\u001b[38;5;241m.\u001b[39mvalues())\n",
|
| 116 |
-
"File \u001b[0;32m/opt/conda/envs/hugginface/lib/python3.8/site-packages/datasets/builder.py:1611\u001b[0m, in \u001b[0;36mGeneratorBasedBuilder._download_and_prepare\u001b[0;34m(self, dl_manager, verify_infos, **prepare_splits_kwargs)\u001b[0m\n\u001b[1;32m 1610\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_download_and_prepare\u001b[39m(\u001b[38;5;28mself\u001b[39m, dl_manager, verify_infos, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mprepare_splits_kwargs):\n\u001b[0;32m-> 1611\u001b[0m \u001b[38;5;28;43msuper\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_download_and_prepare\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1612\u001b[0m \u001b[43m \u001b[49m\u001b[43mdl_manager\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mverify_infos\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcheck_duplicate_keys\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mverify_infos\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mprepare_splits_kwargs\u001b[49m\n\u001b[1;32m 1613\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n",
|
| 117 |
-
"File \u001b[0;32m/opt/conda/envs/hugginface/lib/python3.8/site-packages/datasets/builder.py:953\u001b[0m, in \u001b[0;36mDatasetBuilder._download_and_prepare\u001b[0;34m(self, dl_manager, verify_infos, **prepare_split_kwargs)\u001b[0m\n\u001b[1;32m 949\u001b[0m split_dict\u001b[38;5;241m.\u001b[39madd(split_generator\u001b[38;5;241m.\u001b[39msplit_info)\n\u001b[1;32m 951\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m 952\u001b[0m \u001b[38;5;66;03m# Prepare split will record examples associated to the split\u001b[39;00m\n\u001b[0;32m--> 953\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_prepare_split\u001b[49m\u001b[43m(\u001b[49m\u001b[43msplit_generator\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mprepare_split_kwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 954\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mOSError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m 955\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mOSError\u001b[39;00m(\n\u001b[1;32m 956\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mCannot find data file. \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 957\u001b[0m \u001b[38;5;241m+\u001b[39m (\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmanual_download_instructions \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 958\u001b[0m \u001b[38;5;241m+\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mOriginal error:\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 959\u001b[0m \u001b[38;5;241m+\u001b[39m \u001b[38;5;28mstr\u001b[39m(e)\n\u001b[1;32m 960\u001b[0m ) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28mNone\u001b[39m\n",
|
| 118 |
-
"File \u001b[0;32m/opt/conda/envs/hugginface/lib/python3.8/site-packages/datasets/builder.py:1449\u001b[0m, in \u001b[0;36mGeneratorBasedBuilder._prepare_split\u001b[0;34m(self, split_generator, check_duplicate_keys, file_format, num_proc, max_shard_size)\u001b[0m\n\u001b[1;32m 1447\u001b[0m gen_kwargs \u001b[38;5;241m=\u001b[39m split_generator\u001b[38;5;241m.\u001b[39mgen_kwargs\n\u001b[1;32m 1448\u001b[0m job_id \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0\u001b[39m\n\u001b[0;32m-> 1449\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m job_id, done, content \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_prepare_split_single(\n\u001b[1;32m 1450\u001b[0m gen_kwargs\u001b[38;5;241m=\u001b[39mgen_kwargs, job_id\u001b[38;5;241m=\u001b[39mjob_id, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39m_prepare_split_args\n\u001b[1;32m 1451\u001b[0m ):\n\u001b[1;32m 1452\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m done:\n\u001b[1;32m 1453\u001b[0m result \u001b[38;5;241m=\u001b[39m content\n",
|
| 119 |
-
"File \u001b[0;32m/opt/conda/envs/hugginface/lib/python3.8/site-packages/datasets/builder.py:1606\u001b[0m, in \u001b[0;36mGeneratorBasedBuilder._prepare_split_single\u001b[0;34m(self, gen_kwargs, fpath, file_format, max_shard_size, split_info, check_duplicate_keys, job_id)\u001b[0m\n\u001b[1;32m 1604\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(e, SchemaInferenceError) \u001b[38;5;129;01mand\u001b[39;00m e\u001b[38;5;241m.\u001b[39m__context__ \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 1605\u001b[0m e \u001b[38;5;241m=\u001b[39m e\u001b[38;5;241m.\u001b[39m__context__\n\u001b[0;32m-> 1606\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m DatasetGenerationError(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAn error occurred while generating the dataset\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01me\u001b[39;00m\n\u001b[1;32m 1608\u001b[0m \u001b[38;5;28;01myield\u001b[39;00m job_id, \u001b[38;5;28;01mTrue\u001b[39;00m, (total_num_examples, total_num_bytes, writer\u001b[38;5;241m.\u001b[39m_features, num_shards, shard_lengths)\n",
|
| 120 |
-
"\u001b[0;31mDatasetGenerationError\u001b[0m: An error occurred while generating the dataset"
|
| 121 |
]
|
| 122 |
}
|
| 123 |
],
|
| 124 |
"source": [
|
| 125 |
"%%time\n",
|
| 126 |
-
"
|
| 127 |
]
|
| 128 |
},
|
| 129 |
{
|
| 130 |
"cell_type": "code",
|
| 131 |
-
"execution_count":
|
| 132 |
-
"id": "
|
| 133 |
"metadata": {},
|
| 134 |
-
"outputs": [
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
}
|
| 137 |
],
|
| 138 |
"metadata": {
|
|
|
|
| 1 |
{
|
| 2 |
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"id": "a25ac442",
|
| 6 |
+
"metadata": {},
|
| 7 |
+
"source": [
|
| 8 |
+
"## Performance HuggingFace Dataset vs Dataset Loader"
|
| 9 |
+
]
|
| 10 |
+
},
|
| 11 |
+
{
|
| 12 |
+
"cell_type": "markdown",
|
| 13 |
+
"id": "3da127dc",
|
| 14 |
+
"metadata": {},
|
| 15 |
+
"source": [
|
| 16 |
+
"## Hugging Face Dataset"
|
| 17 |
+
]
|
| 18 |
+
},
|
| 19 |
{
|
| 20 |
"cell_type": "code",
|
| 21 |
+
"execution_count": 34,
|
| 22 |
"id": "aef315bf",
|
| 23 |
"metadata": {},
|
| 24 |
"outputs": [],
|
| 25 |
"source": [
|
| 26 |
+
"from datasets import load_dataset\n",
|
| 27 |
+
"import torch\n",
|
| 28 |
+
"import glob"
|
| 29 |
]
|
| 30 |
},
|
| 31 |
{
|
| 32 |
"cell_type": "code",
|
| 33 |
+
"execution_count": 63,
|
| 34 |
"id": "c0ed6498",
|
| 35 |
"metadata": {},
|
| 36 |
"outputs": [
|
| 37 |
{
|
| 38 |
+
"name": "stderr",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
"output_type": "stream",
|
| 40 |
"text": [
|
| 41 |
+
"Found cached dataset ava (/home/william/.cache/huggingface/datasets/will33am___ava/default/1.0.0/723cc8bd5959ef1cd88b7d51648a8bc7fd98c9d8ddb768cb8c8ebaade1b82306)\n"
|
| 42 |
]
|
| 43 |
},
|
| 44 |
{
|
| 45 |
+
"name": "stdout",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
"output_type": "stream",
|
| 47 |
"text": [
|
| 48 |
+
"CPU times: user 211 ms, sys: 11.8 ms, total: 223 ms\n",
|
| 49 |
+
"Wall time: 852 ms\n"
|
| 50 |
]
|
| 51 |
+
}
|
| 52 |
+
],
|
| 53 |
+
"source": [
|
| 54 |
+
"%%time\n",
|
| 55 |
+
"ds = load_dataset(\"will33am/AVA\",split = 'train')\n",
|
| 56 |
+
"ds = ds.remove_columns([\"rating_counts\",\"text_tag_0\",\"text_tag_1\"])"
|
| 57 |
+
]
|
| 58 |
+
},
|
| 59 |
+
{
|
| 60 |
+
"cell_type": "code",
|
| 61 |
+
"execution_count": 66,
|
| 62 |
+
"id": "c51e48dd",
|
| 63 |
+
"metadata": {},
|
| 64 |
+
"outputs": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
{
|
| 66 |
+
"name": "stdout",
|
| 67 |
"output_type": "stream",
|
| 68 |
"text": [
|
| 69 |
+
"CPU times: user 7.3 ms, sys: 644 µs, total: 7.94 ms\n",
|
| 70 |
+
"Wall time: 6.24 ms\n"
|
| 71 |
]
|
| 72 |
+
}
|
| 73 |
+
],
|
| 74 |
+
"source": [
|
| 75 |
+
"%%time\n",
|
| 76 |
+
"image = ds[0]['image']"
|
| 77 |
+
]
|
| 78 |
+
},
|
| 79 |
+
{
|
| 80 |
+
"cell_type": "markdown",
|
| 81 |
+
"id": "25b4bd86",
|
| 82 |
+
"metadata": {},
|
| 83 |
+
"source": [
|
| 84 |
+
"## Pytorch Dataset"
|
| 85 |
+
]
|
| 86 |
+
},
|
| 87 |
+
{
|
| 88 |
+
"cell_type": "code",
|
| 89 |
+
"execution_count": 30,
|
| 90 |
+
"id": "07480450",
|
| 91 |
+
"metadata": {},
|
| 92 |
+
"outputs": [],
|
| 93 |
+
"source": [
|
| 94 |
+
"from PIL import Image\n",
|
| 95 |
+
"class Datasets(torch.utils.data.Dataset):\n",
|
| 96 |
+
" def __init__(self,files):\n",
|
| 97 |
+
" self.files = files\n",
|
| 98 |
+
" def __getitem__(self,idx):\n",
|
| 99 |
+
" return Image.open(self.files[idx])\n",
|
| 100 |
+
" \n",
|
| 101 |
+
" def __len__(self):\n",
|
| 102 |
+
" return len(self.files)"
|
| 103 |
+
]
|
| 104 |
+
},
|
| 105 |
+
{
|
| 106 |
+
"cell_type": "code",
|
| 107 |
+
"execution_count": 31,
|
| 108 |
+
"id": "7dcb29a3",
|
| 109 |
+
"metadata": {},
|
| 110 |
+
"outputs": [],
|
| 111 |
+
"source": [
|
| 112 |
+
"files = glob.glob(\"../../AVA_src/images/images/*.jpg\")\n",
|
| 113 |
+
"dataset = Datasets(files)"
|
| 114 |
+
]
|
| 115 |
+
},
|
| 116 |
+
{
|
| 117 |
+
"cell_type": "code",
|
| 118 |
+
"execution_count": 53,
|
| 119 |
+
"id": "43c33afc",
|
| 120 |
+
"metadata": {},
|
| 121 |
+
"outputs": [
|
| 122 |
{
|
| 123 |
+
"name": "stdout",
|
| 124 |
+
"output_type": "stream",
|
| 125 |
+
"text": [
|
| 126 |
+
"CPU times: user 1.21 ms, sys: 0 ns, total: 1.21 ms\n",
|
| 127 |
+
"Wall time: 656 µs\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
]
|
| 129 |
}
|
| 130 |
],
|
| 131 |
"source": [
|
| 132 |
"%%time\n",
|
| 133 |
+
"image = dataset[0]"
|
| 134 |
]
|
| 135 |
},
|
| 136 |
{
|
| 137 |
"cell_type": "code",
|
| 138 |
+
"execution_count": 58,
|
| 139 |
+
"id": "771fe113",
|
| 140 |
"metadata": {},
|
| 141 |
+
"outputs": [
|
| 142 |
+
{
|
| 143 |
+
"data": {
|
| 144 |
+
"text/plain": [
|
| 145 |
+
"10.731707317073171"
|
| 146 |
+
]
|
| 147 |
+
},
|
| 148 |
+
"execution_count": 58,
|
| 149 |
+
"metadata": {},
|
| 150 |
+
"output_type": "execute_result"
|
| 151 |
+
}
|
| 152 |
+
],
|
| 153 |
+
"source": [
|
| 154 |
+
"# 10 veces mas rapido acceder a un elemento\n",
|
| 155 |
+
"(7.04e-3)/(656 * 1e-6 )"
|
| 156 |
+
]
|
| 157 |
}
|
| 158 |
],
|
| 159 |
"metadata": {
|
scripts/.ipynb_checkpoints/create_sample_dataset-checkpoint.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from os import makedirs
|
| 2 |
+
from os import listdir
|
| 3 |
+
from os.path import join
|
| 4 |
+
from shutil import copy
|
| 5 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 6 |
+
|
| 7 |
+
NUM_FILES = 5000
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
# +
|
| 11 |
+
|
| 12 |
+
# copy a file from source to destination
|
| 13 |
+
def copy_file(src_path, dest_dir):
|
| 14 |
+
# copy source file to dest file
|
| 15 |
+
dest_path = copy(src_path, dest_dir)
|
| 16 |
+
# report progress
|
| 17 |
+
print(f'.copied {src_path} to {dest_path}')
|
| 18 |
+
|
| 19 |
+
def main(src='../../AVA_src/images/images/', dest='../../AVA_src/images_5k/'):
|
| 20 |
+
# create the destination directory if needed
|
| 21 |
+
makedirs(dest, exist_ok=True)
|
| 22 |
+
# create full paths for all files we wish to copy
|
| 23 |
+
files = [join(src,name) for name in listdir(src)][:NUM_FILES]
|
| 24 |
+
print("Files: ",files)
|
| 25 |
+
# create the thread pool
|
| 26 |
+
with ThreadPoolExecutor(10) as exe:
|
| 27 |
+
# submit all copy tasks
|
| 28 |
+
_ = [exe.submit(copy_file, path, dest) for path in files]
|
| 29 |
+
|
| 30 |
+
if __name__ == '__main__':
|
| 31 |
+
main()
|
scripts/create_sample_dataset.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from os import makedirs
|
| 2 |
+
from os import listdir
|
| 3 |
+
from os.path import join
|
| 4 |
+
from shutil import copy
|
| 5 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 6 |
+
|
| 7 |
+
NUM_FILES = 5000
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
# +
|
| 11 |
+
|
| 12 |
+
# copy a file from source to destination
|
| 13 |
+
def copy_file(src_path, dest_dir):
|
| 14 |
+
# copy source file to dest file
|
| 15 |
+
dest_path = copy(src_path, dest_dir)
|
| 16 |
+
# report progress
|
| 17 |
+
print(f'.copied {src_path} to {dest_path}')
|
| 18 |
+
|
| 19 |
+
def main(src='../../AVA_src/images/images/', dest='../../AVA_src/images_5k/'):
|
| 20 |
+
# create the destination directory if needed
|
| 21 |
+
makedirs(dest, exist_ok=True)
|
| 22 |
+
# create full paths for all files we wish to copy
|
| 23 |
+
files = [join(src,name) for name in listdir(src)][:NUM_FILES]
|
| 24 |
+
print("Files: ",files)
|
| 25 |
+
# create the thread pool
|
| 26 |
+
with ThreadPoolExecutor(10) as exe:
|
| 27 |
+
# submit all copy tasks
|
| 28 |
+
_ = [exe.submit(copy_file, path, dest) for path in files]
|
| 29 |
+
|
| 30 |
+
if __name__ == '__main__':
|
| 31 |
+
main()
|