File size: 4,252 Bytes
a4597a8 8b4081b a4597a8 8b4081b a4597a8 8b4081b a4597a8 8b4081b a4597a8 7c26d90 8b4081b 7d758e3 8b4081b 7d758e3 7c26d90 8b4081b 68ca385 8b4081b 68ca385 8b4081b 68ca385 8b4081b 68ca385 8b4081b 68ca385 8b4081b 68ca385 8b4081b 68ca385 a4597a8 296bff8 8b4081b a4597a8 8b4081b a4597a8 8b4081b a4597a8 |
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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
{
"cells": [
{
"cell_type": "markdown",
"id": "a25ac442",
"metadata": {},
"source": [
"## Performance HuggingFace Dataset vs Dataset Loader"
]
},
{
"cell_type": "markdown",
"id": "3da127dc",
"metadata": {},
"source": [
"## Hugging Face Dataset"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "aef315bf",
"metadata": {},
"outputs": [],
"source": [
"from datasets import load_dataset\n",
"import torch\n",
"import glob"
]
},
{
"cell_type": "code",
"execution_count": 63,
"id": "c0ed6498",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Found cached dataset ava (/home/william/.cache/huggingface/datasets/will33am___ava/default/1.0.0/723cc8bd5959ef1cd88b7d51648a8bc7fd98c9d8ddb768cb8c8ebaade1b82306)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 211 ms, sys: 11.8 ms, total: 223 ms\n",
"Wall time: 852 ms\n"
]
}
],
"source": [
"%%time\n",
"ds = load_dataset(\"will33am/AVA\",split = 'train')\n",
"ds = ds.remove_columns([\"rating_counts\",\"text_tag_0\",\"text_tag_1\"])"
]
},
{
"cell_type": "code",
"execution_count": 66,
"id": "c51e48dd",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 7.3 ms, sys: 644 µs, total: 7.94 ms\n",
"Wall time: 6.24 ms\n"
]
}
],
"source": [
"%%time\n",
"image = ds[0]['image']"
]
},
{
"cell_type": "markdown",
"id": "25b4bd86",
"metadata": {},
"source": [
"## Pytorch Dataset"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "07480450",
"metadata": {},
"outputs": [],
"source": [
"from PIL import Image\n",
"class Datasets(torch.utils.data.Dataset):\n",
" def __init__(self,files):\n",
" self.files = files\n",
" def __getitem__(self,idx):\n",
" return Image.open(self.files[idx])\n",
" \n",
" def __len__(self):\n",
" return len(self.files)"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "7dcb29a3",
"metadata": {},
"outputs": [],
"source": [
"files = glob.glob(\"../../AVA_src/images/images/*.jpg\")\n",
"dataset = Datasets(files)"
]
},
{
"cell_type": "code",
"execution_count": 53,
"id": "43c33afc",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 1.21 ms, sys: 0 ns, total: 1.21 ms\n",
"Wall time: 656 µs\n"
]
}
],
"source": [
"%%time\n",
"image = dataset[0]"
]
},
{
"cell_type": "code",
"execution_count": 58,
"id": "771fe113",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10.731707317073171"
]
},
"execution_count": 58,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 10 veces mas rapido acceder a un elemento\n",
"(7.04e-3)/(656 * 1e-6 )"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "huggingface",
"language": "python",
"name": "huggingface"
},
"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.8.15"
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|