AKSDeploymentTutorial/Tensorflow/03_TestLocally.ipynb

387 строки
712 KiB
Plaintext
Исходник Постоянная ссылка Обычный вид История

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Test web application locally\n",
"This notebook pulls some images and tests them against the local web app running inside the Docker container we made previously."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from testing_utilities import to_img, img_url_to_json, plot_predictions\n",
"import requests\n",
"\n",
"%matplotlib inline\n",
"%load_ext autoreload\n",
"%autoreload 2\n",
"%load_ext dotenv\n",
"%dotenv"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'caia/tfresnet-gpu'"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"image_name = os.getenv('docker_login') + os.getenv('image_repo')\n",
"image_name "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the Docker conatainer in the background and open port 80. Notice we are using nvidia-docker and not docker"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"%%bash --bg -s \"$image_name\"\n",
"nvidia-docker run -p 80:80 $1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Wait a few seconds for the application to spin up and then check that everything works"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.9.0"
]
}
],
"source": [
"!curl 'http://0.0.0.0:80/version'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Pull an image of a Lynx to test our local web app with"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"IMAGEURL = \"https://upload.wikimedia.org/wikipedia/commons/thumb/6/68/Lynx_lynx_poing.jpg/220px-Lynx_lynx_poing.jpg\""
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"headers = {'content-type': 'application/json'}"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'{\"input\": {\"image\": \"\\\\\"iVBORw0KGgoAAAANSUhEUgAAAOAAAADgCAIAAACVT/22AAABJGlDQ1BJQ0MgUHJvZmlsZQAAeJxjY'"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"jsonimg = img_url_to_json(IMAGEURL)\n",
"jsonimg[:100] # Example of json string"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.image.AxesImage at 0x7f2f41039e48>"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAQUAAAD8CAYAAAB+fLH0AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJzsvVmMbed15/db3/ftvc9UdWoeb9WdSV4OlkjRoqihbdmyLTuJ1YnTmYDkIUH6yQ8Buh8yPTjwU4AEQZCgG3CADtxB0u4HeWwbdqx4EClLMklRIkVe8l7euebxzMPe35CHb5+6l063TXVbMRu4Cyicc6r22fucb69vDf/1X6skhMBjeSyP5bFMRP1Nf4DH8lgey8dLHhuFx/JYHsuH5LFReCyP5bF8SB4bhcfyWB7Lh+SxUXgsj+WxfEgeG4XH8lgey4fkh2YUROTLIvK+iHwgIv/lD+s6j+WxPJa/XpEfBk9BRDRwA/gpYAt4DfgPQwjv/rVf7LE8lsfy1yo/rEjh08AHIYTbIYQc+DXgKz+kaz2Wx/JY/hrF/JDOuw48eOT1FvDSv+jgStWExnTKJGoRBOTRI+KLQOBhZCOIgIhAiH/7/0gIxMMDiCDx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pn/xftk1NWzzXR0iNoH6MFb/BexbRHE9cuxA3mAwTxiPJx/bUr0zlH8Ko0rSAqKq0vRoiXErMR8JoQojGAgI9mBg8xLQsB6wKFdRQWVBjhbUEQh8dCKFDiS2MME8Mf1ztGKwSBYMArgngsghbFdKNOr9VlfNLlZz//U0xlM7zx+uvMr61yf2+PpFKlyAuO949
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plt.imshow(to_img(IMAGEURL))"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 4.56 ms, sys: 420 µs, total: 4.98 ms\n",
"Wall time: 2.01 s\n"
]
},
{
"data": {
"text/plain": [
"{'result': [{'image': [['n02127052 lynx, catamount', 0.9974517226219177],\n",
" ['n02128385 leopard, Panthera pardus', 0.0015077460557222366],\n",
" ['n02128757 snow leopard, ounce, Panthera uncia', 0.0005164783797226846]]},\n",
" 'Computed in 2004.67 ms']}"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%time r = requests.post('http://0.0.0.0:80/score', data=jsonimg, headers=headers)\n",
"r.json()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's try a few more images"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"images = ('https://upload.wikimedia.org/wikipedia/commons/thumb/6/68/Lynx_lynx_poing.jpg/220px-Lynx_lynx_poing.jpg',\n",
" 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Roadster_2.5_windmills_trimmed.jpg',\n",
" 'http://www.worldshipsociety.org/wp-content/themes/construct/lib/scripts/timthumb/thumb.php?src=http://www.worldshipsociety.org/wp-content/uploads/2013/04/stock-photo-5495905-cruise-ship.jpg&w=570&h=370&zc=1&q=100',\n",
" 'http://yourshot.nationalgeographic.com/u/ss/fQYSUbVfts-T7pS2VP2wnKyN8wxywmXtY0-FwsgxpiZv_E9ZfPsNV5B0ER8-bOdruvNfMD5EbP4SznWz4PYn/',\n",
" 'https://cdn.arstechnica.net/wp-content/uploads/2012/04/bohol_tarsier_wiki-4f88309-intro.jpg',\n",
" 'http://i.telegraph.co.uk/multimedia/archive/03233/BIRDS-ROBIN_3233998b.jpg')"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"url='http://0.0.0.0:80/score'\n",
"results = [requests.post(url, data=img_url_to_json(img), headers=headers) for img in images]"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/anaconda/envs/AKSDeployment/lib/python3.5/site-packages/matplotlib/cbook/deprecation.py:107: MatplotlibDeprecationWarning: Passing one of 'on', 'true', 'off', 'false' as a boolean is deprecated; use an actual boolean (True/False) instead.\n",
" warnings.warn(message, mplDeprecation, stacklevel=1)\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAoUAAAH+CAYAAADqJHRLAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJzsvVmMZcl55/f7Is659+bNPauy9qWrq7vJZjdFNsVVJEVJQy0jezQeSzPWk+3x8mL7wYDHfjUM28AY8MyjAUMW4HkQMCNZ0mBge2RACzWiSLUobs1mV69VXV1LVlVW7pl3Oyfi80Ms59ysbkksQzNi+X6FrHvvOSfixPrFP74tRFWZ0YxmNKMZzWhGM5rR/7/J/JsuwIxmNKMZzWhGM5rRjP7N0wwUzmhGM5rRjGY0oxnNaAYKZzSjGc1oRjOa0YxmNAOFM5rRjGY0oxnNaEYzYgYKZzSjGc1oRjOa0YxmxAwUzmhGM5rRjGY0oxnNiBkonNGMZjSjGc1oRjOaETNQOKMZ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8taup6/CXqK5rxuNxlhR63+wAUUK7eJ83FDaqnp1LdX/yQCFE8CKN2UFmaHL8IaC1AGTzhfQvLmRiGjMNkciUkLC5aJLRyiICjSa/PN5I7S6ZQU6VLTLwVOb83ub21PdH6p7L0hSoDfxSaabKHdOaY2XJZcjt0SSQ9/nL6ZnOt93kKXHKL5VTJC0woV2n6tzKIy0sJqHO1IetnkttK7FO4U+wJv0RNS3xL4+R3DpAWLi8gveKc0odN5vOe5wPG3HnNfNdJS5K2gK5JLl
"text/plain": [
"<Figure size 864x648 with 12 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plot_predictions(images, results)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next lets quickly check what the request response performance is for the locally running Docker container."
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"image_data = list(map(img_url_to_json, images)) # Retrieve the images and data"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"timer_results = list()\n",
"for img in image_data:\n",
" res=%timeit -r 1 -o -q requests.post(url, data=img, headers=headers)\n",
" timer_results.append(res.best)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"[0.055485543329268694,\n",
" 0.05390993170440197,\n",
" 0.054554368183016774,\n",
" 0.05410102056339383,\n",
" 0.05501371566206217,\n",
" 0.05426212977617979]"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"timer_results"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Average time taken: 54.55 ms\n"
]
}
],
"source": [
"print('Average time taken: {0:4.2f} ms'.format(10**3 * np.mean(timer_results)))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Stop our Docker container"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"bcd44f05bea5\n"
]
}
],
"source": [
"%%bash\n",
"docker stop $(docker ps -q)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2018-03-31 20:47:28 +03:00
"We can move onto [deploying our web application on AKS](04_DeployOnAKS.ipynb)"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
2018-07-13 20:45:03 +03:00
"display_name": "Python [conda env:AKSDeployment]",
"language": "python",
2018-07-13 20:45:03 +03:00
"name": "conda-env-AKSDeployment-py"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
2018-07-13 20:45:03 +03:00
"version": "3.5.5"
}
},
"nbformat": 4,
"nbformat_minor": 1
}