|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 61, |
| 6 | + "id": "happy-remedy", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [ |
| 9 | + { |
| 10 | + "name": "stdout", |
| 11 | + "output_type": "stream", |
| 12 | + "text": [ |
| 13 | + "Requirement already satisfied: voila in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (0.2.7)\n", |
| 14 | + "Requirement already satisfied: nbclient<0.6,>=0.4.0 in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from voila) (0.5.2)\n", |
| 15 | + "Requirement already satisfied: jupyter-client<7,>=6.1.3 in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from voila) (6.1.7)\n", |
| 16 | + "Requirement already satisfied: jupyter-server<2.0.0,>=0.3.0 in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from voila) (1.4.0)\n", |
| 17 | + "Requirement already satisfied: nbconvert<7,>=6.0.0 in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from voila) (6.0.7)\n", |
| 18 | + "Requirement already satisfied: jupyter-core>=4.6.0 in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from jupyter-client<7,>=6.1.3->voila) (4.7.1)\n", |
| 19 | + "Requirement already satisfied: python-dateutil>=2.1 in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from jupyter-client<7,>=6.1.3->voila) (2.8.1)\n", |
| 20 | + "Requirement already satisfied: pyzmq>=13 in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from jupyter-client<7,>=6.1.3->voila) (20.0.0)\n", |
| 21 | + "Requirement already satisfied: tornado>=4.1 in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from jupyter-client<7,>=6.1.3->voila) (6.1)\n", |
| 22 | + "Requirement already satisfied: traitlets in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from jupyter-client<7,>=6.1.3->voila) (5.0.5)\n", |
| 23 | + "Requirement already satisfied: pywin32>=1.0 in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from jupyter-core>=4.6.0->jupyter-client<7,>=6.1.3->voila) (227)\n", |
| 24 | + "Requirement already satisfied: nbformat in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from jupyter-server<2.0.0,>=0.3.0->voila) (5.1.2)\n", |
| 25 | + "Requirement already satisfied: Send2Trash in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from jupyter-server<2.0.0,>=0.3.0->voila) (1.5.0)\n", |
| 26 | + "Requirement already satisfied: anyio>=2.0.2 in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from jupyter-server<2.0.0,>=0.3.0->voila) (2.1.0)\n", |
| 27 | + "Requirement already satisfied: prometheus-client in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from jupyter-server<2.0.0,>=0.3.0->voila) (0.9.0)\n", |
| 28 | + "Requirement already satisfied: ipython-genutils in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from jupyter-server<2.0.0,>=0.3.0->voila) (0.2.0)\n", |
| 29 | + "Requirement already satisfied: jinja2 in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from jupyter-server<2.0.0,>=0.3.0->voila) (2.11.3)\n", |
| 30 | + "Requirement already satisfied: terminado>=0.8.3 in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from jupyter-server<2.0.0,>=0.3.0->voila) (0.9.2)\n", |
| 31 | + "Requirement already satisfied: typing-extensions in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from anyio>=2.0.2->jupyter-server<2.0.0,>=0.3.0->voila) (3.7.4.3)\n", |
| 32 | + "Requirement already satisfied: sniffio>=1.1 in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from anyio>=2.0.2->jupyter-server<2.0.0,>=0.3.0->voila) (1.2.0)\n", |
| 33 | + "Requirement already satisfied: idna>=2.8 in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from anyio>=2.0.2->jupyter-server<2.0.0,>=0.3.0->voila) (2.10)\n", |
| 34 | + "Requirement already satisfied: async-generator in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from nbclient<0.6,>=0.4.0->voila) (1.10)\n", |
| 35 | + "Requirement already satisfied: nest-asyncio in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from nbclient<0.6,>=0.4.0->voila) (1.5.1)\n", |
| 36 | + "Requirement already satisfied: testpath in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from nbconvert<7,>=6.0.0->voila) (0.4.4)\n", |
| 37 | + "Requirement already satisfied: jupyterlab-pygments in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from nbconvert<7,>=6.0.0->voila) (0.1.2)\n", |
| 38 | + "Requirement already satisfied: bleach in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from nbconvert<7,>=6.0.0->voila) (3.3.0)\n", |
| 39 | + "Requirement already satisfied: entrypoints>=0.2.2 in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from nbconvert<7,>=6.0.0->voila) (0.3)\n", |
| 40 | + "Requirement already satisfied: mistune<2,>=0.8.1 in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from nbconvert<7,>=6.0.0->voila) (0.8.4)\n", |
| 41 | + "Requirement already satisfied: defusedxml in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from nbconvert<7,>=6.0.0->voila) (0.6.0)\n", |
| 42 | + "Requirement already satisfied: pandocfilters>=1.4.1 in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from nbconvert<7,>=6.0.0->voila) (1.4.3)\n", |
| 43 | + "Requirement already satisfied: pygments>=2.4.1 in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from nbconvert<7,>=6.0.0->voila) (2.7.4)\n", |
| 44 | + "Requirement already satisfied: MarkupSafe>=0.23 in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from jinja2->jupyter-server<2.0.0,>=0.3.0->voila) (1.1.1)\n", |
| 45 | + "Requirement already satisfied: jsonschema!=2.5.0,>=2.4 in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from nbformat->jupyter-server<2.0.0,>=0.3.0->voila) (3.0.2)\n", |
| 46 | + "Requirement already satisfied: pyrsistent>=0.14.0 in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from jsonschema!=2.5.0,>=2.4->nbformat->jupyter-server<2.0.0,>=0.3.0->voila) (0.17.3)\n", |
| 47 | + "Requirement already satisfied: setuptools in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from jsonschema!=2.5.0,>=2.4->nbformat->jupyter-server<2.0.0,>=0.3.0->voila) (52.0.0.post20210125)\n", |
| 48 | + "Requirement already satisfied: six>=1.11.0 in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from jsonschema!=2.5.0,>=2.4->nbformat->jupyter-server<2.0.0,>=0.3.0->voila) (1.15.0)\n", |
| 49 | + "Requirement already satisfied: attrs>=17.4.0 in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from jsonschema!=2.5.0,>=2.4->nbformat->jupyter-server<2.0.0,>=0.3.0->voila) (20.3.0)\n", |
| 50 | + "Requirement already satisfied: pywinpty>=0.5 in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from terminado>=0.8.3->jupyter-server<2.0.0,>=0.3.0->voila) (0.5.7)\n", |
| 51 | + "Requirement already satisfied: webencodings in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from bleach->nbconvert<7,>=6.0.0->voila) (0.5.1)\n", |
| 52 | + "Requirement already satisfied: packaging in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from bleach->nbconvert<7,>=6.0.0->voila) (20.9)\n", |
| 53 | + "Requirement already satisfied: pyparsing>=2.0.2 in c:\\users\\victor\\.conda\\envs\\fastai\\lib\\site-packages (from packaging->bleach->nbconvert<7,>=6.0.0->voila) (2.4.7)\n" |
| 54 | + ] |
| 55 | + }, |
| 56 | + { |
| 57 | + "name": "stderr", |
| 58 | + "output_type": "stream", |
| 59 | + "text": [ |
| 60 | + "Enabling: voila\n", |
| 61 | + "- Writing config: C:\\Users\\Victor\\.conda\\envs\\FastAI\\etc\\jupyter\n", |
| 62 | + " - Validating...\n", |
| 63 | + " voila 0.2.7 ok\n" |
| 64 | + ] |
| 65 | + } |
| 66 | + ], |
| 67 | + "source": [ |
| 68 | + "!pip install voila\n", |
| 69 | + "!jupyter serverextension enable --sys-prefix voila\n", |
| 70 | + "import fastbook\n", |
| 71 | + "fastbook.setup_book()\n", |
| 72 | + "from fastbook import *\n", |
| 73 | + "from fastai.vision.widgets import *\n", |
| 74 | + "from fastai import *" |
| 75 | + ] |
| 76 | + }, |
| 77 | + { |
| 78 | + "cell_type": "code", |
| 79 | + "execution_count": 42, |
| 80 | + "id": "front-independence", |
| 81 | + "metadata": {}, |
| 82 | + "outputs": [ |
| 83 | + { |
| 84 | + "data": { |
| 85 | + "text/plain": [ |
| 86 | + "<fastai.learner.Learner at 0x25304955b08>" |
| 87 | + ] |
| 88 | + }, |
| 89 | + "execution_count": 42, |
| 90 | + "metadata": {}, |
| 91 | + "output_type": "execute_result" |
| 92 | + } |
| 93 | + ], |
| 94 | + "source": [ |
| 95 | + "learn_inf = load_learner('./export.pkl')\n", |
| 96 | + "learn_inf" |
| 97 | + ] |
| 98 | + }, |
| 99 | + { |
| 100 | + "cell_type": "code", |
| 101 | + "execution_count": 58, |
| 102 | + "id": "potential-poetry", |
| 103 | + "metadata": {}, |
| 104 | + "outputs": [ |
| 105 | + { |
| 106 | + "data": { |
| 107 | + "application/vnd.jupyter.widget-view+json": { |
| 108 | + "model_id": "a46c0541b0f741ebbb725e007329717e", |
| 109 | + "version_major": 2, |
| 110 | + "version_minor": 0 |
| 111 | + }, |
| 112 | + "text/plain": [ |
| 113 | + "FileUpload(value={}, description='Upload')" |
| 114 | + ] |
| 115 | + }, |
| 116 | + "metadata": {}, |
| 117 | + "output_type": "display_data" |
| 118 | + } |
| 119 | + ], |
| 120 | + "source": [ |
| 121 | + "from fastai import *\n", |
| 122 | + "btn_upload = vision.widgets.FileUpload()\n", |
| 123 | + "out_pl = vision.widgets.Output()\n", |
| 124 | + "btn_run = vision.widgets.Button(description='Clasificar')\n", |
| 125 | + "lbl_prediction_a = widgets.Label()\n", |
| 126 | + "lbl_prediction_b = widgets.Label()\n", |
| 127 | + "btn_upload" |
| 128 | + ] |
| 129 | + }, |
| 130 | + { |
| 131 | + "cell_type": "code", |
| 132 | + "execution_count": 48, |
| 133 | + "id": "infrared-treasury", |
| 134 | + "metadata": {}, |
| 135 | + "outputs": [], |
| 136 | + "source": [ |
| 137 | + "\n", |
| 138 | + "def on_click_classify(change):\n", |
| 139 | + " img = PILImage.create(btn_upload.data[0])\n", |
| 140 | + " out_pl.clear_output()\n", |
| 141 | + " with out_pl: display(img.to_thumb(128,128))\n", |
| 142 | + " res_category,res_idx,res_probs = learn_inf.predict(img)\n", |
| 143 | + " lbl_prediction_a.value = f'Predicción: {res_category}, probabilidad: {(res_probs[res_idx]*100.0):.02f}%' \n", |
| 144 | + " lbl_prediction_b.value = f'Coche: {(res_probs[0]*100.0):.02f}% '\n", |
| 145 | + " lbl_prediction_b.value += f'Estafa: {(res_probs[1]*100.0):.02f}% '\n", |
| 146 | + " lbl_prediction_b.value += f'Gato: {(res_probs[2]*100.0):.02f}% '\n", |
| 147 | + " lbl_prediction_b.value += f'Mapache: {(res_probs[3]*100.0):.02f}% '\n", |
| 148 | + " lbl_prediction_b.value += f'Perro: {(res_probs[4]*100.0):.02f}% ' \n", |
| 149 | + "btn_run.on_click(on_click_classify)" |
| 150 | + ] |
| 151 | + }, |
| 152 | + { |
| 153 | + "cell_type": "code", |
| 154 | + "execution_count": 50, |
| 155 | + "id": "allied-people", |
| 156 | + "metadata": {}, |
| 157 | + "outputs": [ |
| 158 | + { |
| 159 | + "name": "stdout", |
| 160 | + "output_type": "stream", |
| 161 | + "text": [ |
| 162 | + "FileUpload(value={}, description='Upload')\n", |
| 163 | + "Button(description='Clasificar', style=ButtonStyle())\n", |
| 164 | + "Output()\n", |
| 165 | + "Label(value='')\n", |
| 166 | + "Label(value='')\n" |
| 167 | + ] |
| 168 | + }, |
| 169 | + { |
| 170 | + "data": { |
| 171 | + "application/vnd.jupyter.widget-view+json": { |
| 172 | + "model_id": "83695b40705242b6803bf11b55dc7355", |
| 173 | + "version_major": 2, |
| 174 | + "version_minor": 0 |
| 175 | + }, |
| 176 | + "text/plain": [ |
| 177 | + "VBox(children=(Label(value='Selecciona tu cosa'), FileUpload(value={}, description='Upload'), Button(descripti…" |
| 178 | + ] |
| 179 | + }, |
| 180 | + "metadata": {}, |
| 181 | + "output_type": "display_data" |
| 182 | + } |
| 183 | + ], |
| 184 | + "source": [ |
| 185 | + "#hide_output\n", |
| 186 | + "print(btn_upload)\n", |
| 187 | + "print(btn_run)\n", |
| 188 | + "print(out_pl)\n", |
| 189 | + "print(lbl_prediction_a)\n", |
| 190 | + "print(lbl_prediction_b)\n", |
| 191 | + "VBox([widgets.Label('Selecciona tu cosa'), \n", |
| 192 | + " btn_upload, btn_run, out_pl, lbl_prediction_a,lbl_prediction_b])" |
| 193 | + ] |
| 194 | + } |
| 195 | + ], |
| 196 | + "metadata": { |
| 197 | + "kernelspec": { |
| 198 | + "display_name": "Python 3", |
| 199 | + "language": "python", |
| 200 | + "name": "python3" |
| 201 | + }, |
| 202 | + "language_info": { |
| 203 | + "codemirror_mode": { |
| 204 | + "name": "ipython", |
| 205 | + "version": 3 |
| 206 | + }, |
| 207 | + "file_extension": ".py", |
| 208 | + "mimetype": "text/x-python", |
| 209 | + "name": "python", |
| 210 | + "nbconvert_exporter": "python", |
| 211 | + "pygments_lexer": "ipython3", |
| 212 | + "version": "3.7.9" |
| 213 | + } |
| 214 | + }, |
| 215 | + "nbformat": 4, |
| 216 | + "nbformat_minor": 5 |
| 217 | +} |
0 commit comments