This repository has been archived by the owner on Jun 7, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into config-version-update
# Conflicts: # .ps_project/config.yaml
- Loading branch information
Showing
6 changed files
with
256 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,3 +102,5 @@ venv.bak/ | |
|
||
# mypy | ||
.mypy_cache/ | ||
|
||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from random import randint\n", | ||
"try:\n", | ||
" import matplotlib.pyplot as plt\n", | ||
"except ImportError:\n", | ||
" print('Matplotlib not detected - images plotting not available')\n", | ||
"\n", | ||
"plotting = True\n", | ||
"try:\n", | ||
" from matplotlib import image as mpimage\n", | ||
"except ImportError:\n", | ||
" from PIL import Image as pilimage\n", | ||
" plotting = False\n", | ||
"\n", | ||
"import requests\n", | ||
"import tensorflow as tf\n", | ||
"\n", | ||
"def get_image_from_drive(path):\n", | ||
" # Load the image\n", | ||
" try:\n", | ||
" image = pilimage.open(path)\n", | ||
" except ImportError:\n", | ||
" image = mpimage.open(path)\n", | ||
" except Exception:\n", | ||
" raise\n", | ||
" return image\n", | ||
"\n", | ||
"def get_random_image_from_dataset(image_index=randint(0, 9999)):\n", | ||
" (x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()\n", | ||
" return x_test[image_index]\n", | ||
"\n", | ||
"def show_selected_image(image):\n", | ||
" fig = plt.figure()\n", | ||
" plt.subplot(1, 1, 1)\n", | ||
" plt.tight_layout()\n", | ||
" plt.imshow(image, cmap='gray', interpolation='none')\n", | ||
" plt.xticks([])\n", | ||
" plt.yticks([])\n", | ||
" plt.show()\n", | ||
" \n", | ||
"def get_random_image_from_dataset(image_index=randint(0, 9999)):\n", | ||
" (x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()\n", | ||
" return x_test[image_index]\n", | ||
"\n", | ||
"\n", | ||
"def show_selected_image(image):\n", | ||
" fig = plt.figure()\n", | ||
" plt.subplot(1, 1, 1)\n", | ||
" plt.tight_layout()\n", | ||
" plt.imshow(image, cmap='gray', interpolation='none')\n", | ||
" plt.xticks([])\n", | ||
" plt.yticks([])\n", | ||
" plt.show()\n", | ||
"\n", | ||
"\n", | ||
"def make_vector(image):\n", | ||
" vector = []\n", | ||
" for item in image.tolist():\n", | ||
" vector.extend(item)\n", | ||
" return vector\n", | ||
"\n", | ||
"\n", | ||
"def make_prediction_request(image, prediction_url):\n", | ||
" vector = make_vector(image)\n", | ||
" json = {\n", | ||
" \"inputs\": [vector]\n", | ||
" }\n", | ||
" response = requests.post(prediction_url, json=json)\n", | ||
"\n", | ||
" print(response.status_code)\n", | ||
" print(response.text)\n", | ||
"\n", | ||
"image = get_random_image_from_dataset()\n", | ||
"\n", | ||
"show_selected_image(image)\n", | ||
"make_prediction_request(image, 'http://127.0.0.1:8501/v1/models/mnist:predict')" | ||
] | ||
} | ||
], | ||
"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.5.2" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.