Skip to content

Instantly share code, notes, and snippets.

@aymericdelab
Created October 8, 2019 10:54
Show Gist options
  • Save aymericdelab/a49ba6fa5bee2c5de731873d3d1d09b5 to your computer and use it in GitHub Desktop.
Save aymericdelab/a49ba6fa5bee2c5de731873d3d1d09b5 to your computer and use it in GitHub Desktop.
send a request to azure instance where model is deployed
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 95,
"metadata": {},
"outputs": [],
"source": [
"import cv2\n",
"import requests\n",
"\n",
"def get_founder(image_directory):\n",
"\n",
" image=cv2.imread(image_directory)\n",
" gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)\n",
" faceCascade = cv2.CascadeClassifier(cv2.data.haarcascades + \"haarcascade_frontalface_default.xml\")\n",
" faces = faceCascade.detectMultiScale(\n",
" gray,\n",
" scaleFactor=1.1,\n",
" minNeighbors=4,\n",
" minSize=(100, 100)\n",
" ) \n",
" \n",
" try:\n",
" if faces.shape[0]>1:\n",
" return print('too many faces on the picture')\n",
" \n",
" except:\n",
" return print('no face detected in the picture')\n",
" \n",
" for (x, y, w, h) in faces:\n",
" crop_img = gray[y:y+h, x:x+w]\n",
" resized_img=cv2.resize(crop_img,(28,28))\n",
"\n",
" # send a random row from the test set to score\n",
" input_data = \"{\\\"data\\\": [\" + str(resized_img.tolist()) + \"]}\"\n",
"\n",
" headers = {'Content-Type':'application/json', 'Authorization': 'Bearer ' + key1}\n",
"\n",
" resp = requests.post(service.scoring_uri, input_data, headers=headers)\n",
"\n",
" #print(\"input data:\", input_data)\n",
" return print(\"prediction:\", resp.text)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "azure",
"language": "python",
"name": "azure"
},
"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.9"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment