Skip to content

Instantly share code, notes, and snippets.

@trevormunoz
Created July 20, 2018 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save trevormunoz/6fd8df567519cf4f54379259503c98ee to your computer and use it in GitHub Desktop.
Save trevormunoz/6fd8df567519cf4f54379259503c98ee to your computer and use it in GitHub Desktop.
Quick test of Amazon rekognition output
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"from random import randrange\n",
"import webbrowser"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"DATAFILE = '/Users/umd-laptop/Downloads/rekognition-labels-2018-07-19.json'"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"with open(DATAFILE, 'r') as infile:\n",
" LABELS = json.loads(infile.read())"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['Abies',\n",
" 'Acanthaceae',\n",
" 'Accessories',\n",
" 'Adapter',\n",
" 'Adorable',\n",
" 'Adventure',\n",
" 'Aerial View',\n",
" 'Affenpinscher',\n",
" 'Afro Hairstyle',\n",
" 'Agavaceae',\n",
" 'Aircraft',\n",
" 'Aircraft Carrier',\n",
" 'Airedale',\n",
" 'Airfield',\n",
" 'Airmail',\n",
" 'Airplane',\n",
" 'Airport',\n",
" 'Aisle',\n",
" 'Alcohol',\n",
" 'Algae']"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sorted(LABELS.keys())[:20]"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"432"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(LABELS['Document'])"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"def img_picker(key):\n",
" pick = randrange(0, (len(LABELS[key])-1))\n",
" img_addr = 'https://s3.amazonaws.com/{0}'.format(LABELS[key][pick]['image'])\n",
" return img_addr"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"doc_test_image = img_picker(\"Document\")\n",
"person_test_image = img_picker(\"Human\")"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"webbrowser.open(doc_test_image)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"webbrowser.open(person_test_image)"
]
}
],
"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.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment