Skip to content

Instantly share code, notes, and snippets.

@mogwai
Last active June 24, 2020 23:54
Show Gist options
  • Save mogwai/97fb9310409f9a602475598354fb5479 to your computer and use it in GitHub Desktop.
Save mogwai/97fb9310409f9a602475598354fb5479 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from fastai.vision import *"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"p = untar_data(URLs.MNIST)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"class MemoryImageList(ImageList):\n",
" _map = {}\n",
" def open(self, i):\n",
" item = self._map.get(str(i))\n",
" if isinstance(item, Image):\n",
" return item\n",
" item = super().open(i)\n",
" self._map[str(i)] = item\n",
" return item"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: left;\">\n",
" <th>epoch</th>\n",
" <th>train_loss</th>\n",
" <th>valid_loss</th>\n",
" <th>accuracy</th>\n",
" <th>time</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>0.644401</td>\n",
" <td>0.465631</td>\n",
" <td>0.849500</td>\n",
" <td>00:11</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>0.323800</td>\n",
" <td>0.243660</td>\n",
" <td>0.922250</td>\n",
" <td>00:11</td>\n",
" </tr>\n",
" <tr>\n",
" <td>2</td>\n",
" <td>0.261255</td>\n",
" <td>0.216338</td>\n",
" <td>0.930250</td>\n",
" <td>00:16</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"data = MemoryImageList.from_folder(p/'training').split_by_rand_pct(.2, seed=1).label_from_folder().databunch(bs=128).normalize(imagenet_stats)\n",
"learn = cnn_learner(data, models.resnet18, metrics=accuracy)\n",
"learn.fit_one_cycle(3)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: left;\">\n",
" <th>epoch</th>\n",
" <th>train_loss</th>\n",
" <th>valid_loss</th>\n",
" <th>accuracy</th>\n",
" <th>time</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>0.660670</td>\n",
" <td>0.458675</td>\n",
" <td>0.852833</td>\n",
" <td>00:15</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>0.318554</td>\n",
" <td>0.245979</td>\n",
" <td>0.921667</td>\n",
" <td>00:15</td>\n",
" </tr>\n",
" <tr>\n",
" <td>2</td>\n",
" <td>0.260065</td>\n",
" <td>0.218972</td>\n",
" <td>0.929917</td>\n",
" <td>00:16</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"data = ImageList.from_folder(p/'training').split_by_rand_pct(.2, seed=1).label_from_folder().databunch(bs=128).normalize(imagenet_stats)\n",
"learn = cnn_learner(data, models.resnet18, metrics=accuracy)\n",
"learn.fit_one_cycle(3)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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"
},
"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": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment