Skip to content
Permalink
Browse files

FlatImages.ipynb

  • Loading branch information...
danlester committed Jul 12, 2019
1 parent 04d8595 commit f2fd1127f2a4c0c35a47f9474d69f28afa591ecf
Showing with 188 additions and 0 deletions.
  1. +188 −0 Example/FlatImages.ipynb
@@ -0,0 +1,188 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from jupyter_innotater import *\n",
"import numpy as np, os, cv2\n",
"foodfns = sorted(os.listdir('./foods/'))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Images as Numpy Array (H, W, 3)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(300, 400, 3)"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"classes = ['vegetable', 'biscuit', 'fruit']\n",
"foods = [cv2.imread('./foods/'+f) for f in foodfns]\n",
"targets = [0] * len(foodfns)\n",
"\n",
"foods[0].shape"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "1c703c14a7ac46c1a6f2c644fb646026",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Innotater(children=(HBox(children=(VBox(children=(ImagePad(value=b'\\x89PNG\\r\\n\\x1a\\n\\x00\\x00\\x00\\rIHDR\\x00\\x00…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"w2 = Innotater(\n",
" ImageInnotation(foods, name='Food'), \n",
" MultiClassInnotation(targets, name='FoodType', classes=classes, desc='Food Type')\n",
")\n",
"display(w2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Greyscale Images as Numpy array (H,W)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"# Flatten to greyscale\n",
"foods_flat = [f.mean(axis=2).astype('int') for f in foods]"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(300, 400)"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"foods_flat[0].shape"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"242"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"foods[0].max()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ad55b5a2b6b84f39b575f6387ca430e9",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Innotater(children=(HBox(children=(VBox(children=(ImagePad(value=b'\\x89PNG\\r\\n\\x1a\\n\\x00\\x00\\x00\\rIHDR\\x00\\x00…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"w2f = Innotater(\n",
" ImageInnotation(foods_flat, name='Food'), \n",
" MultiClassInnotation(targets, name='FoodType', classes=classes, desc='Food Type')\n",
")\n",
"display(w2f)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"hide_input": false,
"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.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

0 comments on commit f2fd112

Please sign in to comment.
You can’t perform that action at this time.