Skip to content

Instantly share code, notes, and snippets.

@Z30G0D
Last active February 7, 2018 10:55
Show Gist options
  • Save Z30G0D/ac0fe3f4ecba5a604841f57c0b04498f to your computer and use it in GitHub Desktop.
Save Z30G0D/ac0fe3f4ecba5a604841f57c0b04498f to your computer and use it in GitHub Desktop.
Elipse detector
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Elipse detector through DL neural network\n",
"## Hey, this is my solution for the task.<br>\n",
"First we are going to build are dataset according to the guidelines given.\n",
"<br>\n",
"1)Each image have one elipse or no elipse at all\n",
"<br>\n",
"2)Each elipse should have a random center, random axes, random color and random rotation angle.<br>\n",
"3) image background - white\n",
"\n",
"Let's import the relevant directories"
]
},
{
"cell_type": "code",
"execution_count": 167,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3.3.1\n"
]
}
],
"source": [
"import numpy as np\n",
"import tensorflow as tf\n",
"import cv2\n",
"from matplotlib import pyplot as plt\n",
"import pandas as pd\n",
"from PIL import Image \n",
"\n",
"from skimage import color\n",
"print( cv2.__version__ )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Ok, let's try out the opencv since I have never used this library before,let's create a nice random elipse"
]
},
{
"cell_type": "code",
"execution_count": 168,
"metadata": {},
"outputs": [],
"source": [
"img = np.full((64,64,3), 255, dtype=np.uint8)\n",
"center_x = np.random.randint(10,54)\n",
"center_y = np.random.randint(10,54)\n",
"major_axis = np.random.randint(1,9)\n",
"minor_axis= np.random.randint(1,9)\n",
"angle = np.random.randint(0,360)\n",
"B = np.random.randint(0,254)\n",
"G = np.random.randint(0,254)\n",
"R = np.random.randint(0,254)\n",
"a = cv2.ellipse(img, (center_x, center_y), (major_axis, minor_axis), angle, 0, 360, (B, G, R), -1)"
]
},
{
"cell_type": "code",
"execution_count": 169,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(64, 64, 3)"
]
},
"execution_count": 169,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image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PvHNYlOXkdxmm8PtcAn0lyBLif8e7+3TPIQVUd66bHgYcZfxhO+3VZ1aXsT8c0i/8EsKn7xvZc4LOML9E9K1O/PHiSML4V2aGq+uqssiQZJVnXPX438AnGXyI9Ctw8rRxVtbOqNlTVRsbvh7+vqs9NO0eS9yR538nHwCeBg0z5dalpXsp+6C9NlnxJ8SngJ4yPJ/90iuv9BvAK8D+MP1W3Mz6W3A8c7qbnTyHHbzHebf0h8HT371PTzgL8JvBUl+Mg8Gfd+AeBx4EXgG8CvzrF1+ha4JFZ5OjW90z379mT780ZvUc2A/Pda/N3wHlD5PDMPalBnrknNcjiSw2y+FKDLL7UIIsvNcjiSw2y+FKDLL7UoP8FhvxQOnPr5ZsAAAAASUVORK5CYII=\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x2b681825630>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plt.imshow(a)\n",
"a.shape\n",
"#plt.title('my picture')\n",
"#plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Ok,nice shape!<br> \n",
"We will now create the next_batch function, the function will create a batch composed of images of (batch_size) elipses and (batch_size) empty images (returned as images).<br>\n",
"On top of that it will return a label of [batch_size*2, 3] array. Ever image will have the first two numbers as center of the elipse and the third number is 1 or 0 (1 for elipse exists,0 for no elipse)"
]
},
{
"cell_type": "code",
"execution_count": 170,
"metadata": {},
"outputs": [],
"source": [
"def next_batch(batch_size):\n",
" elipse = np.ndarray(shape=(batch_size,64,64,3), dtype=np.uint8)\n",
" labels = np.ndarray(shape=(batch_size,2), dtype=np.uint8)\n",
" for j in range(batch_size):\n",
" img = np.full((64,64,3), 255, dtype=np.uint8)\n",
" center_x = np.random.randint(10,54)\n",
" center_y = np.random.randint(10,54)\n",
" center = np.array([center_x, center_y])\n",
" major_axis = np.random.randint(1,9)\n",
" minor_axis=np.random.randint(1,9)\n",
" angle = np.random.randint(0,360)\n",
" B = np.random.randint(0,255)\n",
" G = np.random.randint(0,255)\n",
" R = np.random.randint(0,255)\n",
" my_elipse = cv2.ellipse(img, (center_x, center_y), (major_axis, minor_axis), angle, 0, 360, (B, G, R), -1)\n",
" elipse[j,:,:,:] = my_elipse\n",
" labels[j,:] = center\n",
" no_elipse = np.full((batch_size ,64,64,3), 255, dtype=np.uint8) # image of 64x64 with white background\n",
" no_elipse_labels = np.zeros(shape=(batch_size,2), dtype=np.uint8)\n",
" # classification labels\n",
" class_elipse_labels = np.ones(shape=(batch_size,1), dtype=np.uint8)\n",
" class_no_elipse_labels = np.zeros(shape=(batch_size,1), dtype=np.uint8)\n",
" class_labels = np.concatenate([class_elipse_labels, class_no_elipse_labels])\n",
" labels = np.concatenate([labels,no_elipse_labels])\n",
" labels = np.concatenate([labels, class_labels], axis=1)\n",
" return np.concatenate([elipse,no_elipse]), labels"
]
},
{
"cell_type": "code",
"execution_count": 171,
"metadata": {},
"outputs": [],
"source": [
"batch_size = 64\n",
"images, labels = next_batch(batch_size)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's check that everything is still in order with our shape."
]
},
{
"cell_type": "code",
"execution_count": 220,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"text/plain": [
"(1, (128, 64, 64, 3), (128, 3))"
]
},
"execution_count": 220,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAP4AAAD8CAYAAABXXhlaAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAADUNJREFUeJzt3W+MHPV9x/H3pzY0af4ICAeyMPSIZKXwoJjoRIioogRC5KYooAgqaFRZlSX3Aa2IGimBVqoaqQ/Ck0AfVFGtQOMHNEAJ1MiKklgOqKpUGY4CicEhJtQFyy4+WqykfZDG5NsHO24vl7Nv725218fv/ZJOuzM3y3zE3m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z3A08BLwN/D/zqGN+jjwK7J5GjW9/z3c8LJ/82J/Q3shmY7d6bfwDOHUUOz9yTGuSZe1KDLL7UIIsvNcjiSw2y+FKDLL7UIIsvNcjiSw36X3U3c19HISNKAAAAAElFTkSuQmCC\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x2b681666198>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plt.imshow(images[62,:,:,:])\n",
"labels[62,2], images.shape, labels.shape"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Great , we have our batch function. the output is a batch of elipses with 3 channels colors!<br>\n",
"It also gives us the center of the elipse (I will focus on these parameters for now, later we will add the axes , orientation... etc...)<br>\n",
"So our data is represented in a way that the CNN can recieve it.\n",
"Let's create an MSE function for measuring accuracy of the centers and other regression variables."
]
},
{
"cell_type": "code",
"execution_count": 173,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.009999999999999974"
]
},
"execution_count": 173,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def MSE(A, B):\n",
" # mean squared eror for accuracy measurment\n",
" return np.sum((((A - B) ** 2).mean(axis=0)))\n",
"#testing\n",
"pred = np.array([[2.0, 0.5], [4.0, 2.0]])\n",
"true = np.array([[2.1, 0.5], [4.1, 2.0]])\n",
"\n",
"MSE(pred, true)"
]
},
{
"cell_type": "code",
"execution_count": 202,
"metadata": {},
"outputs": [],
"source": [
"num_hidden = 64 # hidden nodes\n",
"image_size = 64 #\n",
"num_channels = 3\n",
"alpha = 0.95\n",
"num_labels = 3\n",
"\n",
"graph = tf.Graph()\n",
"\n",
"with graph.as_default():\n",
"\n",
" # Input data.\n",
" tf_train_dataset = tf.placeholder(tf.float32, shape=(batch_size*2, image_size, image_size, num_channels))\n",
" tf_train_labels = tf.placeholder(tf.float32, shape=(batch_size*2, num_labels))\n",
" tf_valid_dataset = tf.placeholder(tf.float32, shape=(batch_size*2, image_size, image_size, num_channels))\n",
" tf_valid_labels = tf.placeholder(tf.float32, shape=(batch_size*2, num_labels))\n",
" tf_test_dataset = tf.placeholder(tf.float32, shape=(batch_size*2, image_size, image_size, num_channels))\n",
" tf_test_labels = tf.placeholder(tf.float32, shape=(batch_size*2, num_labels))\n",
"\n",
"\n",
" #tf_test_labels= tf.Variable(test_labels)\n",
"\n",
" def model(data): \n",
" conv11 = tf.contrib.layers.conv2d(data, num_outputs=1, kernel_size=(1,1),activation_fn=None)\n",
" conv11_2 = tf.contrib.layers.conv2d(tf_train_dataset, num_outputs=1, kernel_size=(1,1),activation_fn=tf.sigmoid)\n",
" drop = tf.nn.dropout(conv11_2, 0.5)\n",
" conv11_2flat = tf.layers.flatten(drop)\n",
" dense1 = tf.layers.dense(conv11_2flat, 128, activation = tf.nn.relu)\n",
" dense2 = tf.layers.dense(dense1, 2)\n",
" return dense2\n",
" def model_class(data):\n",
" data = tf.layers.flatten(data)\n",
" dense1 = tf.layers.dense(data, 128)\n",
" dense2 = tf.layers.dense(dense1, 1, use_bias=True, activation = tf.sigmoid)\n",
" dense2 = tf.transpose(dense2)\n",
" return dense2\n",
"\n",
"\n",
" #Loss definition\n",
" logits = model(tf_train_dataset)\n",
" logits_class = model_class(tf_train_dataset)\n",
" \n",
" loss1 = tf.reduce_mean(tf.reduce_sum((tf_train_labels[:,:2]-logits[:,:2])**2,axis=1)) \n",
" loss2 = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=tf_train_labels[:,2], logits=logits_class))\n",
" loss = (alpha * loss1) + ((1-alpha) * loss2) \n",
" \n",
" #tf_train_labels[:,2]\n",
" #loss = tf.reduce_mean(tf.reduce_sum(tf.square(dense2-tf_train_labels),axis=1))\n",
" \n",
"\n",
" # Optimizer\n",
" optimizer = tf.train.AdamOptimizer(0.001).minimize(loss)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Ok, I used covnet since finding shapes\\ geometrical objects is easier with the kernels .<br> \n",
"To ease on the computations I used 1x1 kernels (rig is slow)<br>\n",
"I introuced dropout at some point since I noticed that when I try to run the algorithm with random batches the loss get stuck, however when I tried to run only one batch two times the loss was extremely low (less than 3), so overfitting was a possibility that dropout could solve.<br>\n",
"MSE was a reasonable choice to make for measuring the distance of the predicted elipse centers.\n",
"The loss function is a **combined** function for linear regression (centers) and classification (existence of an elipse)<br>\n",
"On top of that a simple preprocessing of substracting 255 to the pictures was made to ease on the calculation."
]
},
{
"cell_type": "code",
"execution_count": 203,
"metadata": {
"scrolled": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Initialized weights ,biases and other variables\n",
"Training batch loss at step 0: 1135.208496\n",
"ground truth of elipse center is [20 15]\n",
"Prediction of elipse centers is: [0.0808904 0.3280729]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [9.958152e-07] [0.5]\n",
"Training batch loss at step 200: 604.957092\n",
"ground truth of elipse center is [33 23]\n",
"Prediction of elipse centers is: [16.100878 16.174131]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.17066112]\n",
"Training batch loss at step 400: 559.184814\n",
"ground truth of elipse center is [37 29]\n",
"Prediction of elipse centers is: [19.919153 13.950667]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.06330093]\n",
"Training batch loss at step 600: 446.029877\n",
"ground truth of elipse center is [28 31]\n",
"Prediction of elipse centers is: [18.580053 22.813879]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.03174066]\n",
"Training batch loss at step 800: 375.600220\n",
"ground truth of elipse center is [49 51]\n",
"Prediction of elipse centers is: [25.29518 21.176876]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.0200697]\n",
"Training batch loss at step 1000: 340.447510\n",
"ground truth of elipse center is [48 36]\n",
"Prediction of elipse centers is: [17.457441 13.445083]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.01389]\n",
"Training batch loss at step 1200: 364.598969\n",
"ground truth of elipse center is [14 21]\n",
"Prediction of elipse centers is: [11.320176 23.429508]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00963042]\n",
"Training batch loss at step 1400: 341.791199\n",
"ground truth of elipse center is [38 22]\n",
"Prediction of elipse centers is: [21.456083 17.010618]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00781208]\n",
"Training batch loss at step 1600: 354.979736\n",
"ground truth of elipse center is [35 24]\n",
"Prediction of elipse centers is: [19.11473 14.499574]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00585027]\n",
"Training batch loss at step 1800: 325.959473\n",
"ground truth of elipse center is [43 35]\n",
"Prediction of elipse centers is: [34.682453 29.783108]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00452428]\n",
"Training batch loss at step 2000: 321.717560\n",
"ground truth of elipse center is [18 19]\n",
"Prediction of elipse centers is: [12.9852915 13.807175 ]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00358406]\n",
"Training batch loss at step 2200: 338.153687\n",
"ground truth of elipse center is [22 23]\n",
"Prediction of elipse centers is: [15.766049 15.343813]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00289266]\n",
"Training batch loss at step 2400: 306.907562\n",
"ground truth of elipse center is [46 40]\n",
"Prediction of elipse centers is: [17.937105 16.208633]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00236952]\n",
"Training batch loss at step 2600: 254.915222\n",
"ground truth of elipse center is [37 51]\n",
"Prediction of elipse centers is: [11.558585 16.108685]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00196448]\n",
"Training batch loss at step 2800: 284.820984\n",
"ground truth of elipse center is [33 49]\n",
"Prediction of elipse centers is: [11.169202 15.812482]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00164492]\n",
"Training batch loss at step 3000: 229.029953\n",
"ground truth of elipse center is [35 10]\n",
"Prediction of elipse centers is: [24.167858 6.5323715]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00138881]\n",
"Training batch loss at step 3200: 238.109344\n",
"ground truth of elipse center is [46 49]\n",
"Prediction of elipse centers is: [25.060057 28.917479]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00118267]\n",
"Training batch loss at step 3400: 198.362000\n",
"ground truth of elipse center is [14 45]\n",
"Prediction of elipse centers is: [14.128216 39.66875 ]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00101131]\n",
"Training batch loss at step 3600: 213.622101\n",
"ground truth of elipse center is [52 48]\n",
"Prediction of elipse centers is: [46.310623 44.97024 ]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00086926]\n",
"Training batch loss at step 3800: 211.044418\n",
"ground truth of elipse center is [19 38]\n",
"Prediction of elipse centers is: [10.950496 26.477732]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00119333]\n",
"Training batch loss at step 4000: 209.550873\n",
"ground truth of elipse center is [44 19]\n",
"Prediction of elipse centers is: [23.13212 13.286477]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00102021]\n",
"Training batch loss at step 4200: 160.231964\n",
"ground truth of elipse center is [24 52]\n",
"Prediction of elipse centers is: [13.631756 21.534235]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00087694]\n",
"Training batch loss at step 4400: 196.369736\n",
"ground truth of elipse center is [51 42]\n",
"Prediction of elipse centers is: [55.246384 44.420776]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.0007573]\n",
"Training batch loss at step 4600: 124.935860\n",
"ground truth of elipse center is [19 52]\n",
"Prediction of elipse centers is: [20.346895 50.953804]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00065661]\n",
"Training batch loss at step 4800: 136.666336\n",
"ground truth of elipse center is [12 44]\n",
"Prediction of elipse centers is: [ 4.490696 11.240217]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.0005713]\n",
"Training batch loss at step 5000: 100.241989\n",
"ground truth of elipse center is [11 10]\n",
"Prediction of elipse centers is: [7.378556 7.392456]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00049858]\n",
"Training batch loss at step 5200: 99.682480\n",
"ground truth of elipse center is [20 42]\n",
"Prediction of elipse centers is: [18.957926 38.555458]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00043628]\n",
"Training batch loss at step 5400: 101.742798\n",
"ground truth of elipse center is [31 50]\n",
"Prediction of elipse centers is: [22.139954 31.97844 ]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00038266]\n",
"Training batch loss at step 5600: 75.076210\n",
"ground truth of elipse center is [31 32]\n",
"Prediction of elipse centers is: [18.72623 19.91621]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00060676]\n",
"Training batch loss at step 5800: 61.485603\n",
"ground truth of elipse center is [35 24]\n",
"Prediction of elipse centers is: [37.22521 25.79641]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00052788]\n",
"Training batch loss at step 6000: 72.691299\n",
"ground truth of elipse center is [34 16]\n",
"Prediction of elipse centers is: [34.57235 15.541236]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00046058]\n",
"Training batch loss at step 6200: 138.650787\n",
"ground truth of elipse center is [22 34]\n",
"Prediction of elipse centers is: [28.161592 40.31732 ]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00040288]\n",
"Training batch loss at step 6400: 66.561447\n",
"ground truth of elipse center is [22 31]\n",
"Prediction of elipse centers is: [19.771732 30.636047]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.0003532]\n",
"Training batch loss at step 6600: 65.258423\n",
"ground truth of elipse center is [24 53]\n",
"Prediction of elipse centers is: [18.871302 36.21079 ]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00031026]\n",
"Training batch loss at step 6800: 51.936699\n",
"ground truth of elipse center is [52 19]\n",
"Prediction of elipse centers is: [52.459538 20.034615]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00027302]\n",
"Training batch loss at step 7000: 47.714752\n",
"ground truth of elipse center is [35 37]\n",
"Prediction of elipse centers is: [37.002167 39.279057]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00024064]\n",
"Training batch loss at step 7200: 43.118534\n",
"ground truth of elipse center is [34 35]\n",
"Prediction of elipse centers is: [35.53817 37.669926]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00021239]\n",
"Training batch loss at step 7400: 37.943615\n",
"ground truth of elipse center is [29 35]\n",
"Prediction of elipse centers is: [30.985487 36.21121 ]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00018769]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Training batch loss at step 7600: 61.320473\n",
"ground truth of elipse center is [12 52]\n",
"Prediction of elipse centers is: [ 5.7628064 27.188465 ]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00016646]\n",
"Training batch loss at step 7800: 48.768757\n",
"ground truth of elipse center is [46 41]\n",
"Prediction of elipse centers is: [46.892517 40.826565]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00014738]\n",
"Training batch loss at step 8000: 41.583797\n",
"ground truth of elipse center is [52 27]\n",
"Prediction of elipse centers is: [52.47715 25.537432]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00013062]\n",
"Training batch loss at step 8200: 33.221981\n",
"ground truth of elipse center is [24 13]\n",
"Prediction of elipse centers is: [22.916605 12.6907015]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00011587]\n",
"Training batch loss at step 8400: 66.644966\n",
"ground truth of elipse center is [22 49]\n",
"Prediction of elipse centers is: [23.36266 50.736862]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00010286]\n",
"Training batch loss at step 8600: 34.117908\n",
"ground truth of elipse center is [14 48]\n",
"Prediction of elipse centers is: [13.971957 50.918156]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [9.137698e-05]\n",
"Training batch loss at step 8800: 37.125870\n",
"ground truth of elipse center is [31 36]\n",
"Prediction of elipse centers is: [29.321215 36.34621 ]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [8.12305e-05]\n",
"Training batch loss at step 9000: 30.136745\n",
"ground truth of elipse center is [15 38]\n",
"Prediction of elipse centers is: [ 9.521984 33.286743]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [7.2254064e-05]\n",
"Training batch loss at step 9200: 31.340088\n",
"ground truth of elipse center is [40 50]\n",
"Prediction of elipse centers is: [35.02706 46.22982]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00012061]\n",
"Training batch loss at step 9400: 30.324879\n",
"ground truth of elipse center is [13 37]\n",
"Prediction of elipse centers is: [10.322938 36.267563]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00011007]\n",
"Training batch loss at step 9600: 33.651241\n",
"ground truth of elipse center is [28 49]\n",
"Prediction of elipse centers is: [25.805653 47.486942]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00010037]\n",
"Training batch loss at step 9800: 46.672886\n",
"ground truth of elipse center is [31 42]\n",
"Prediction of elipse centers is: [27.53924 39.963337]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [9.139755e-05]\n",
"Training batch loss at step 10000: 30.845932\n",
"ground truth of elipse center is [12 33]\n",
"Prediction of elipse centers is: [12.538341 30.761631]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [8.310625e-05]\n",
"Training batch loss at step 10200: 24.599640\n",
"ground truth of elipse center is [20 13]\n",
"Prediction of elipse centers is: [19.747599 11.979312]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [7.5468604e-05]\n",
"Training batch loss at step 10400: 31.347137\n",
"ground truth of elipse center is [23 28]\n",
"Prediction of elipse centers is: [25.8761 30.098654]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00012927]\n",
"Training batch loss at step 10600: 50.252300\n",
"ground truth of elipse center is [47 38]\n",
"Prediction of elipse centers is: [45.33091 34.14689]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00011978]\n",
"Training batch loss at step 10800: 30.118805\n",
"ground truth of elipse center is [11 36]\n",
"Prediction of elipse centers is: [11.043513 32.598763]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00013602]\n",
"Training batch loss at step 11000: 31.354855\n",
"ground truth of elipse center is [31 27]\n",
"Prediction of elipse centers is: [33.163963 30.534304]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00012421]\n",
"Training batch loss at step 11200: 38.419762\n",
"ground truth of elipse center is [47 33]\n",
"Prediction of elipse centers is: [45.42203 31.895247]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00011336]\n",
"Training batch loss at step 11400: 27.082306\n",
"ground truth of elipse center is [44 30]\n",
"Prediction of elipse centers is: [47.013344 30.031101]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.0001033]\n",
"Training batch loss at step 11600: 43.867062\n",
"ground truth of elipse center is [31 37]\n",
"Prediction of elipse centers is: [31.028833 35.335865]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [9.398919e-05]\n",
"Training batch loss at step 11800: 24.005356\n",
"ground truth of elipse center is [30 15]\n",
"Prediction of elipse centers is: [32.480133 14.643466]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [8.540586e-05]\n",
"Training batch loss at step 12000: 35.932655\n",
"ground truth of elipse center is [36 24]\n",
"Prediction of elipse centers is: [38.280647 26.889065]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [7.750832e-05]\n",
"Training batch loss at step 12200: 21.892885\n",
"ground truth of elipse center is [28 32]\n",
"Prediction of elipse centers is: [27.767508 34.122196]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [7.025983e-05]\n",
"Training batch loss at step 12400: 55.091328\n",
"ground truth of elipse center is [51 43]\n",
"Prediction of elipse centers is: [57.52341 49.213623]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [6.3621366e-05]\n",
"Training batch loss at step 12600: 23.841171\n",
"ground truth of elipse center is [31 38]\n",
"Prediction of elipse centers is: [32.240154 36.976074]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [5.7553712e-05]\n",
"Training batch loss at step 12800: 23.984703\n",
"ground truth of elipse center is [23 24]\n",
"Prediction of elipse centers is: [18.369171 19.540506]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [5.2039486e-05]\n",
"Training batch loss at step 13000: 28.238060\n",
"ground truth of elipse center is [48 42]\n",
"Prediction of elipse centers is: [45.429646 41.186184]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [0.00011004]\n",
"Training batch loss at step 13200: 29.937130\n",
"ground truth of elipse center is [35 50]\n",
"Prediction of elipse centers is: [35.22209 52.820362]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [9.6058255e-05]\n",
"Training batch loss at step 13400: 26.233276\n",
"ground truth of elipse center is [11 22]\n",
"Prediction of elipse centers is: [12.396035 21.431007]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [8.410472e-05]\n",
"Training batch loss at step 13600: 21.131001\n",
"ground truth of elipse center is [48 28]\n",
"Prediction of elipse centers is: [44.994057 26.309841]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [7.3830044e-05]\n",
"Training batch loss at step 13800: 28.271000\n",
"ground truth of elipse center is [30 42]\n",
"Prediction of elipse centers is: [30.77041 43.487232]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [6.495745e-05]\n",
"Training batch loss at step 14000: 22.753626\n",
"ground truth of elipse center is [12 36]\n",
"Prediction of elipse centers is: [10.933799 33.924667]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [5.7264377e-05]\n",
"Training batch loss at step 14200: 33.681511\n",
"ground truth of elipse center is [38 25]\n",
"Prediction of elipse centers is: [40.127647 24.629503]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [5.0570638e-05]\n",
"Training batch loss at step 14400: 33.589668\n",
"ground truth of elipse center is [39 18]\n",
"Prediction of elipse centers is: [39.12701 18.270031]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [4.472669e-05]\n",
"Training batch loss at step 14600: 25.224037\n",
"ground truth of elipse center is [41 15]\n",
"Prediction of elipse centers is: [43.090637 16.925644]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [3.9613613e-05]\n",
"Training batch loss at step 14800: 28.735344\n",
"ground truth of elipse center is [16 49]\n",
"Prediction of elipse centers is: [19.132483 50.16699 ]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [3.512768e-05]\n",
"Training batch loss at step 15000: 35.948498\n",
"ground truth of elipse center is [14 38]\n",
"Prediction of elipse centers is: [14.004031 36.683784]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [3.1181386e-05]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Training batch loss at step 15200: 31.833857\n",
"ground truth of elipse center is [45 25]\n",
"Prediction of elipse centers is: [47.13451 27.013496]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [2.7707172e-05]\n",
"Training batch loss at step 15400: 26.344971\n",
"ground truth of elipse center is [47 16]\n",
"Prediction of elipse centers is: [45.572334 13.24183 ]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [2.464137e-05]\n",
"Training batch loss at step 15600: 22.483620\n",
"ground truth of elipse center is [12 23]\n",
"Prediction of elipse centers is: [12.205176 23.32051 ]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [2.1931497e-05]\n",
"Training batch loss at step 15800: 28.712206\n",
"ground truth of elipse center is [46 22]\n",
"Prediction of elipse centers is: [43.35241 20.768843]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [1.9533652e-05]\n",
"Training batch loss at step 16000: 32.915497\n",
"ground truth of elipse center is [39 17]\n",
"Prediction of elipse centers is: [40.125454 17.279167]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [1.7408936e-05]\n",
"Training batch loss at step 16200: 24.645157\n",
"ground truth of elipse center is [52 10]\n",
"Prediction of elipse centers is: [51.708317 8.963008]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [1.5524209e-05]\n",
"Training batch loss at step 16400: 19.397820\n",
"ground truth of elipse center is [17 10]\n",
"Prediction of elipse centers is: [16.911585 9.611662]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [1.385052e-05]\n",
"Training batch loss at step 16600: 27.864628\n",
"ground truth of elipse center is [49 46]\n",
"Prediction of elipse centers is: [51.017002 47.79697 ]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [1.2361058e-05]\n",
"Training batch loss at step 16800: 20.923771\n",
"ground truth of elipse center is [51 38]\n",
"Prediction of elipse centers is: [55.409805 40.581722]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [1.1038723e-05]\n",
"Training batch loss at step 17000: 24.168798\n",
"ground truth of elipse center is [20 47]\n",
"Prediction of elipse centers is: [19.006716 46.865982]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [9.861728e-06]\n",
"Training batch loss at step 17200: 37.933208\n",
"ground truth of elipse center is [52 33]\n",
"Prediction of elipse centers is: [48.69968 32.140163]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [8.81338e-06]\n",
"Training batch loss at step 17400: 26.235306\n",
"ground truth of elipse center is [37 14]\n",
"Prediction of elipse centers is: [35.086395 12.4332 ]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [7.8790745e-06]\n",
"Training batch loss at step 17600: 33.031639\n",
"ground truth of elipse center is [39 44]\n",
"Prediction of elipse centers is: [36.4827 44.09507]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [7.0459905e-06]\n",
"Training batch loss at step 17800: 26.836010\n",
"ground truth of elipse center is [35 51]\n",
"Prediction of elipse centers is: [32.589676 47.988346]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [6.30277e-06]\n",
"Training batch loss at step 18000: 23.468313\n",
"ground truth of elipse center is [20 28]\n",
"Prediction of elipse centers is: [22.057592 30.474781]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [5.639403e-06]\n",
"Training batch loss at step 18200: 22.809471\n",
"ground truth of elipse center is [48 27]\n",
"Prediction of elipse centers is: [48.542797 27.800337]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [5.0471394e-06]\n",
"Training batch loss at step 18400: 27.657188\n",
"ground truth of elipse center is [53 19]\n",
"Prediction of elipse centers is: [47.966965 18.797459]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [4.5180977e-06]\n",
"Training batch loss at step 18600: 33.537922\n",
"ground truth of elipse center is [39 23]\n",
"Prediction of elipse centers is: [34.457233 21.872047]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [4.0454047e-06]\n",
"Training batch loss at step 18800: 30.480412\n",
"ground truth of elipse center is [14 22]\n",
"Prediction of elipse centers is: [12.881773 24.234467]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [3.650098e-06]\n",
"Training batch loss at step 19000: 20.770834\n",
"ground truth of elipse center is [50 53]\n",
"Prediction of elipse centers is: [47.233875 48.88958 ]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [3.5225155e-06]\n",
"Training batch loss at step 19200: 22.451576\n",
"ground truth of elipse center is [28 23]\n",
"Prediction of elipse centers is: [28.659601 23.590437]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [3.3912654e-06]\n",
"Training batch loss at step 19400: 19.754253\n",
"ground truth of elipse center is [26 31]\n",
"Prediction of elipse centers is: [25.439629 30.596714]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [3.2569098e-06]\n",
"Training batch loss at step 19600: 19.693523\n",
"ground truth of elipse center is [30 46]\n",
"Prediction of elipse centers is: [26.843578 43.43322 ]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [3.1200273e-06]\n",
"Training batch loss at step 19800: 28.474842\n",
"ground truth of elipse center is [37 14]\n",
"Prediction of elipse centers is: [35.099453 12.817536]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [2.9812825e-06]\n",
"Training batch loss at step 20000: 19.048162\n",
"ground truth of elipse center is [13 31]\n",
"Prediction of elipse centers is: [14.919129 30.299551]\n",
"ground truth if elipse is: 1\n",
"prediction if elipse or not [1.] [2.8413301e-06]\n"
]
}
],
"source": [
"num_steps = 20001\n",
" \n",
"with tf.Session(graph=graph) as session:\n",
" tf.global_variables_initializer().run()\n",
" print('Initialized weights ,biases and other variables')\n",
" for step in range(num_steps):\n",
" batch_data, batch_labels = next_batch(batch_size)\n",
" batch_data = 255-batch_data\n",
" #print(batch_labels[:,:2])\n",
" feed_dict = {tf_train_dataset : batch_data, tf_train_labels : batch_labels}\n",
" _, l, predictions, elipse = session.run( [optimizer, loss, logits, logits_class], feed_dict=feed_dict)\n",
" elipse.shape\n",
" if (step % 200 == 0):\n",
" print('Training batch loss at step %d: %f' % (step, l))\n",
" print('ground truth of elipse center is', batch_labels[2, :2])\n",
" print('Prediction of elipse centers is:', predictions[2,:])\n",
" print('ground truth if elipse is:' ,batch_labels[2, 2])\n",
" print('prediction if elipse or not', elipse[:, 2], elipse[:, 100]) \n",
" test_data, test_label = next_batch(batch_size)\n",
" #preprocessing for image\n",
" test_data = 255-test_data\n",
" feed_dict={tf_train_dataset:test_data, tf_train_labels : test_label}\n",
" predictions, elipse = session.run( [logits, logits_class], feed_dict=feed_dict)\n",
" \n",
" #print('Prediction of elipse is:', elipse[:,2])\n",
" "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Ok, We got loss of 19, I managed to get to a loss of 14 before but couldn't reproduce it.<br>\n",
"Convergence seem to happen around the 10,000 step.<br>\n",
"No epoches here, since this is a random batch (infinite training set).<br>\n",
"batch size is 128 (64 elipses and 64 empty frames), arbitrary size<br>\n",
"Let's look at the results for a random elipse."
]
},
{
"cell_type": "code",
"execution_count": 217,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(array([21.483952, 30.642042], dtype=float32), array([1.], dtype=float32))"
]
},
"execution_count": 217,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAP4AAAD8CAYAAABXXhlaAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAADSRJREFUeJzt3WGMHPV9xvHvUxuaNAkyhANZGHpEslJ4UUx0IkRUUQMhctMo9guIQFFlVZb8hkZEjZRCK1WK1BfhTaCqqkpWoPELGqAk1AhFSSwHVFWqDEeAxOAQE+qCZRcfLShpX6Q1+fXFjqvDPXPru5ldm//3I51mZ27W88i7z87MztxMqgpJbfm1aQeQNHkWX2qQxZcaZPGlBll8qUEWX2qQxZcatKriJ9mc5MUkLyW5o69QkoaVlZ7Ak2QN8FPgRuAw8BRwa1W90F88SUNYu4rnXgO8VFUvAyR5ANgCnLL4F154Yc3Ozq5ikZLeyaFDh3j99dez3HyrKf4lwKuLxg8DH32nJ8zOzjI/P7+KRUp6J3Nzc2PNt5p9/KU+Vf7ffkOSHUnmk8wvLCysYnGS+rK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zk+Nq0cSQ4l+XGSZ5PMd9Om8R6ZyKXsJ1b8JGuAvwZ+D7gSuDXJlRNa/DeAzSdNm8blwY8DX6qqK4Brgdu6/4NJZ/klcH1VXQVsAjYnuRa4C7i7y/EGsH3gHCfczuiS7SdMK8cnqmrTosNn03iPTOZS9lU1kR/gY8D3Fo3fCdw5weXPAvsXjb8IrO8erwdenFSWRRl2AzdOMwvwG8APgY8yOlFk7VKv14DL39C9ma8HHgMypRyHgAtPmjbR1wU4D/gXuu/ehswxyU39S4BXF40f7qZNy1QvD55kFrga2DeNLN3m9bOMLpK6B/gZ8GZVHe9mmdTrcw/wZeBX3fgHp5SjgO8neTrJjm7apF+XiV3KfpLFzxLTmjykkOT9wLeAL1bVz6eRoareqqpNjNa41wBXLDXbkBmSfAY4VlVPL5486Ryd66rqI4x2RW9L8vEJLPNkq7qU/emYZPEPA5cuGt8AHJng8k821uXB+5bkHEalv7+qvj3NLAA1uivSE4y+c1iX5MR1GCfx+lwHfDbJIeABRpv790whB1V1pBseAx5h9GE46ddlVZeyPx2TLP5TwMbuG9tzgVsYXaJ7WiZ+efAkYXQrsgNV9bVpZUkyk2Rd9/i9wCcZfYn0OHDTpHJU1Z1VtaGqZhm9H35QVZ+fdI4k70vygROPgU8B+5nw61KTvJT90F+anPQlxaeBnzLan/yzCS73m8BR4H8YfapuZ7QvuRc42A0vmECO32G02foj4Nnu59OTzgL8NvBMl2M/8Ofd9A8BTwIvAX8P/PoEX6PfBR6bRo5uec91P8+feG9O6T2yCZjvXpt/AM4fIodn7kkN8sw9qUEWX2qQxZcaZPGlBll8qUEWX2qQxZcaZPGlBv0vhYhtJdwRbTIAAAAASUVORK5CYII=\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x2b680154080>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plt.imshow(test_data[62,:,:,:]+255)\n",
"predictions[62, :],elipse[:,62] "
]
},
{
"cell_type": "code",
"execution_count": 219,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(array([ 0.15619636, -0.14755121], dtype=float32), array([0.], dtype=float32))"
]
},
"execution_count": 219,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAP4AAAD8CAYAAABXXhlaAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAADLZJREFUeJzt3X+o3fV9x/Hna4muXX8QrUcJRncthE7/mLFcrMVRVq0l60qTP3QoZYQRyD9uWFbodINBYX/Uf6r7YwxCdb1/uKqzdREpbUOqjMGIXqu20dTGukxDMnPdlHb7o1vse3+cb7bb7MZ7kvv9ntPweT4gnPP93u/h+ybnPs+ve/h+U1VIasuvzHoASdNn+FKDDF9qkOFLDTJ8qUGGLzXI8KUGrSn8JFuTvJTk5SR39jWUpGHlbL/Ak2Qd8CPgJuAI8DRwW1W92N94koawfg23vRZ4uapeAUjyILANOG34F110Uc3Nza1hl5LeyeHDh3njjTey2nZrCf9S4LVly0eAj7zTDebm5lhcXFzDLiW9k/n5+Ym2W8t7/JUeVf7f+4Yku5IsJllcWlpaw+4k9WUt4R8BLlu2vAk4eupGVbW7quaran40Gq1hd5L6spbwnwY2J7kiyfnArcBj/YwlaUhn/R6/qk4k+UPg28A64P6qeqG3ySQNZi0f7lFV3wS+2dMskqbEb+5JDTJ8qUGGLzXI8KUGGb7UIMOXGmT4UoMMX2qQ4UsNMnypQYYvNcjwpQYZvtQgw5caZPhSgwxfapDhSw0yfKlBhi81yPClBhm+1CDDlxpk+FKDDF9qkOFLDVo1/CT3Jzme5MCydRcm2ZvkUHd5wbBjSurTJM/4XwW2nrLuTmBfVW0G9nXLks4Rq4ZfVf8A/Pspq7cBC931BWB7z3NJGtDZvse/pKqOAXSXF/c3kqShDf7hXpJdSRaTLC4tLQ29O0kTONvw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DOI3753rgM0kOAw8yfrl/7wzmoKqOdpfHgUcZPxhO+35Z06Hsz8Q0w38a2Nx9Yns+cCvjQ3TPytQPD54kjE9FdrCqvjyrWZKMkmzorr8b+ATjD5GeAG6e1hxVdVdVbaqqOca/D9+tqs9Oe44k70nyvpPXgU8CB5jy/VLTPJT90B+anPIhxaeAHzF+P/lnU9zv14BjwH8zflTdyfi95D7gUHd54RTm+C3GL1u/DzzX/fvUtGcBfhN4tpvjAPDn3foPAk8BLwN/B/zqFO+j3wYen8Uc3f6e7/69cPJ3c0a/I1uAxe6++XvggiHm8Jt7UoP85p7UIMOXGmT4UoMMX2qQ4UsNMnypQYYvNcjwpQb9D+1sQTigcHaUAAAAAElFTkSuQmCC\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x2b680ed7278>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"elipse[elipse<0.5] = 0 # thresholding the sigmoid\n",
"plt.imshow(test_data[70,:,:,:]+255)\n",
"predictions[70, :],elipse[:,70] "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The predictions were quite okay for our random check, both for an empty picture and a picture with an elipse."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The next step would be to find the major and minor axes, I didn't implement it, but my solution would be to add bigger kernels to capture the entire size of the axes and implement in the same way similar to the centers.<br>\n",
"As for the rotation, this part is a bit tricky since a rotation of 180 and a rotation of 360 are the same.<br>\n",
"A possible solution would be to get the cos and sin of the rotation and angle and get 2 features for one angle.<br>\n",
"That way every angle would be distinct and we could find it in an easier way...\n",
"\n",
"The loss function would still be the same as I depicted in my previous network, adding more MSE and defining the weights (alpha) in a different way.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### As for case with multiple elipses:\n",
"If we add to the labels vectors the parameters of the other elipses and start tuning them we will have a problem. Since all the shapes are random we can have a certain elipse in the right end of the picture , the algorithm will optimize the weights to the rights. But if we have the same shape/ similar shape on the left side the algorithm will learn it and tweak to the left.<br>\n",
"This will cause a problem in finding the elipses.<br>\n",
"A possible solution would be to measure MSE after every epoch for different order of the predictors. Later , flip the predictor vector if needed to \"specialize\" on specific forms."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python (myenv)",
"language": "python",
"name": "myenv"
},
"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.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment