Created
August 22, 2017 12:28
-
-
Save hgaiser/c31926937f87ed3a7d5e63aaf130a2b3 to your computer and use it in GitHub Desktop.
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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 16, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"The autoreload extension is already loaded. To reload it, use:\n", | |
" %reload_ext autoreload\n" | |
] | |
} | |
], | |
"source": [ | |
"%matplotlib inline\n", | |
"%load_ext autoreload\n", | |
"%autoreload 2\n", | |
"\n", | |
"from ipywidgets import IntProgress\n", | |
"from keras_tqdm import TQDMNotebookCallback\n", | |
"\n", | |
"import keras\n", | |
"import keras.preprocessing.image\n", | |
"from keras.applications.imagenet_utils import get_file\n", | |
"\n", | |
"import keras_resnet.models\n", | |
"import keras_retinanet.layers\n", | |
"\n", | |
"import matplotlib.pyplot as plt\n", | |
"import cv2\n", | |
"import numpy as np\n", | |
"import sys\n", | |
"import math\n", | |
"\n", | |
"import tensorflow as tf\n", | |
"\n", | |
"def get_session():\n", | |
" config = tf.ConfigProto()\n", | |
" config.gpu_options.allow_growth = True\n", | |
" return tf.Session(config=config)\n", | |
"\n", | |
"keras.backend.tensorflow_backend.set_session(get_session())\n", | |
"\n", | |
"WEIGHTS_PATH_NO_TOP = 'https://github.com/fchollet/deep-learning-models/releases/download/v0.2/resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5'" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 17, | |
"metadata": { | |
"scrolled": true | |
}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"/usr/lib/python3.6/site-packages/ipykernel/__main__.py:45: UserWarning: Output \"classification_softmax\" missing from loss dictionary. We assume this was done on purpose, and we will not be expecting any data to be passed to \"classification_softmax\" during training.\n", | |
"/usr/lib/python3.6/site-packages/ipykernel/__main__.py:45: UserWarning: Output \"boxes\" missing from loss dictionary. We assume this was done on purpose, and we will not be expecting any data to be passed to \"boxes\" during training.\n", | |
"/usr/lib/python3.6/site-packages/ipykernel/__main__.py:45: UserWarning: Output \"focal_loss_5\" missing from loss dictionary. We assume this was done on purpose, and we will not be expecting any data to be passed to \"focal_loss_5\" during training.\n" | |
] | |
} | |
], | |
"source": [ | |
"def create_model(num_classes=2, num_anchors=9):\n", | |
" image = keras.layers.Input((512, 512, 3))\n", | |
" im_info = keras.layers.Input((3,))\n", | |
" gt_boxes = keras.layers.Input((None, 5))\n", | |
" \n", | |
" resnet = keras_resnet.models.ResNet50(image, include_top=False)\n", | |
" _, _, _, res5 = resnet.outputs\n", | |
"\n", | |
" # predict anchor classes\n", | |
" classification = keras.layers.Conv2D(\n", | |
" filters=num_classes * num_anchors,\n", | |
" kernel_size=(3, 3),\n", | |
" strides=1,\n", | |
" padding='same',\n", | |
" name='pyramid_classification',\n", | |
" #kernel_initializer=keras.initializers.normal(mean=0.0, stddev=0.01, seed=None),\n", | |
" #bias_initializer=keras.initializers.zeros(),\n", | |
" bias_initializer=keras.initializers.constant(-math.log((1 - 0.01) / 0.01)),\n", | |
" kernel_initializer=keras.initializers.zeros(),\n", | |
" )(res5)\n", | |
" \n", | |
" # generate anchors and their labels\n", | |
" labels, _, anchors = keras_retinanet.layers.AnchorTarget(\n", | |
" features_shape=keras.backend.int_shape(classification)[1:3],\n", | |
" stride=32,\n", | |
" anchor_size=128,\n", | |
" name='boxes'\n", | |
" )([im_info, gt_boxes])\n", | |
" \n", | |
" # reshape classification to (-1, num_classes)\n", | |
" classification = keras.layers.Reshape((-1, num_classes), name='classification')(classification)\n", | |
" # compute classification losses\n", | |
" classification = keras.layers.Activation('softmax', name='classification_softmax')(classification)\n", | |
" cls_loss = keras_retinanet.layers.FocalLoss(num_classes=num_classes)([classification, labels])\n", | |
" \n", | |
" return keras.models.Model(inputs=[image, im_info, gt_boxes], outputs=[classification, labels, cls_loss, anchors])\n", | |
"\n", | |
"model = create_model()\n", | |
"\n", | |
"# load imagenet weights\n", | |
"weights_path = get_file('resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5', WEIGHTS_PATH_NO_TOP, cache_subdir='models', md5_hash='a268eb855778b3df3c7506639542a6af')\n", | |
"model.load_weights(weights_path, by_name=True)\n", | |
"\n", | |
"# compile model\n", | |
"model.compile(loss=None, optimizer=keras.optimizers.adam(lr=0.01))\n", | |
"#print(model.summary())" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 18, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAQYAAAD8CAYAAACVSwr3AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAADU1JREFUeJzt3GuopdV9x/HvL46jaU0d7wwz047ivNAXrZHBTDAUa5Ki\nNmR8oWAIOMjAQC9gsJCOLbQE+qL2RRRpMB2qdCxJ1ObCDJLUymho33ibeM/UeCxWDzM4iJekCG2N\n/77Y6yTbWUfPdubsyzHfD2z2WutZ++z/uezfWc+zn2enqpCkYR+ZdgGSZo/BIKljMEjqGAySOgaD\npI7BIKkzlmBIclmS55LMJdk5jueQND5Z7vMYkhwH/AT4LDAPPAp8oap+vKxPJGlsxrFiuAiYq6r/\nrKr/Be4Cto7heSSNyaoxfM11wMtD/XngE+/3gCSefimN36tVdcYoE8cRDFlkrHvhJ9kB7BjD80ta\n3H+NOnEcwTAPbBjqrwcOHjmpqnYBu8AVgzRrxnGM4VFgU5Kzk6wGrgH2juF5JI3Jsq8YqurtJH8C\n3AccB9xRVc8u9/NIGp9lf7vyqIpwV0KahP1VtXmUiZ75KKljMEjqGAySOgaDpI7BIKljMEjqGAyS\nOgaDpI7BIKljMEjqGAySOgaDpI7BIKljMEjqGAySOgaDpI7BIKljMEjqGAySOgaDpI7BIKljMEjq\nGAySOgaDpI7BIKljMEj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WA08C50+xnt8F\nLgSeGRr7W2Bna+8EbmrtK4AfMLg2ZAvw8IRrXQtc2NofA34CnD9r9bbnO6m1jwcebs9/D3BNG/86\n8Iet/UfA11v7GuDuCf9cbwC+Cdzb+rNa54vA6UeMLdvvfmLfyHt8c58E7hvq3wjcOOWaNh4RDM8B\na1t7LYNzLgD+HvjCYvOmVPce4LOzXC/wa8CPgE8wOPlm1ZF/B8B9wCdbe1WblwnVt57BZ4tcCtzb\nXkgzV2d7zsWCYdl+99PelRjpEu0pO6bLyyehLWM/zuC/8czV25bnTzC40O5+BqvEN6rq7UVq+UWd\nbfubwGmTqBO4Bfgy8E7rnzajdcIYPgph2LTPfBzpEu0ZNRO1JzkJ+A7wpar6abumZdGpi4xNpN6q\n+jlwQZI1DK7OPe99aplKnUk+Bxyuqv1JLhmhlmn//pf9oxCGTXvFsBIu0Z7Zy8uTHM8gFL5RVd9t\nwzNbb1W9AfyQwX7umiQL/5iGa/lFnW37ycBrEyjvYuDzSV4E7mKwO3HLDNYJjP+jEKYdDI8Cm9qR\n39UMDuLsnXJNR5rJy8szWBrcDhyoqq/Oar1JzmgrBZJ8FPgMcAB4ELjqPepcqP8q4IFqO8bjVFU3\nVtX6qtrI4O/wgar64qzVCRP6KIRJHnx6j4MoVzA4ov4C8BdTruVbwCHg/xik7HYG+437gOfb/alt\nboCvtbqfBjZPuNZPMVgOPgU80W5XzFq9wG8Dj7c6nwH+so2fAzzC4PL8fwZOaOMntv5c237OFP4O\nLuGX70rMXJ2tpifb7dmF181y/u4981FSZ9q7EpJmkMEgqWMwSOoYDJI6BoOkjsEgqWMwSOoYDJI6\n/w9qpJblviy9MgAAAABJRU5ErkJggg==\n", | |
"text/plain": [ | |
"<matplotlib.figure.Figure at 0x7f1c0a7ed588>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"(1, 512, 512, 3) (1, 3) (1, 1, 5)\n" | |
] | |
} | |
], | |
"source": [ | |
"# generate really simple image with one object\n", | |
"image = np.zeros((512, 512, 3), dtype=keras.backend.floatx())\n", | |
"image[100:300, 100:300, :] = 1.0\n", | |
"plt.imshow(image)\n", | |
"plt.show()\n", | |
"\n", | |
"# create input batch blobs\n", | |
"image_batch = np.expand_dims(image, axis=0)\n", | |
"im_info_batch = np.array([[512, 512, 1.0]])\n", | |
"gt_boxes_batch = np.array([[[100, 100, 300, 300, 1]]])\n", | |
"\n", | |
"inputs = [image_batch, im_info_batch, gt_boxes_batch]\n", | |
"\n", | |
"print(image_batch.shape, im_info_batch.shape, gt_boxes_batch.shape)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 19, | |
"metadata": { | |
"scrolled": true | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"999 3.118030463156174e-066\r" | |
] | |
} | |
], | |
"source": [ | |
"# train for some iterations\n", | |
"for i in range(1000):\n", | |
" print('{} {}'.format(i, model.train_on_batch(inputs, None)), end='\\r')\n", | |
" sys.stdout.flush()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 20, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# predict the same image again\n", | |
"classification, labels, cls_loss, anchors = model.predict_on_batch(inputs)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 21, | |
"metadata": { | |
"scrolled": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"(1, 2304) (1, 2304, 2) (1, 2304, 4)\n", | |
"1.0 [ 0.01348912 0.98651087]\n", | |
"1.0 [ 0.00627385 0.99372619]\n", | |
"1.0 [ 0.00209964 0.99790037]\n", | |
"1.0 [ 0.00452386 0.99547619]\n", | |
"1.0 [ 0.0193282 0.98067182]\n", | |
"1.0 [ 0.00812897 0.991871 ]\n", | |
"1.0 [ 0.00952255 0.99047744]\n", | |
"1.0 [ 1.06148713e-04 9.99893785e-01]\n", | |
"1.0 [ 0.05200059 0.94799942]\n", | |
"1.0 [ 0.00240846 0.99759161]\n", | |
"1.0 [ 0.02541689 0.97458309]\n", | |
"1.0 [ 0.00573512 0.9942649 ]\n", | |
"1.0 [ 1.14641634e-05 9.99988556e-01]\n", | |
"1.0 [ 2.84824437e-05 9.99971509e-01]\n", | |
"1.0 [ 8.69676078e-05 9.99912977e-01]\n", | |
"1.0 [ 0.03039886 0.96960115]\n", | |
"1.0 [ 2.02974588e-05 9.99979734e-01]\n", | |
"1.0 [ 4.90425955e-05 9.99951005e-01]\n", | |
"1.0 [ 2.19084352e-04 9.99780953e-01]\n", | |
"1.0 [ 4.56347625e-04 9.99543607e-01]\n", | |
"1.0 [ 0.00981079 0.99018925]\n", | |
"1.0 [ 7.80278788e-05 9.99921918e-01]\n", | |
"1.0 [ 4.56221518e-04 9.99543726e-01]\n", | |
"1.0 [ 0.00191325 0.99808681]\n", | |
"1.0 [ 0.07593685 0.92406309]\n", | |
"1.0 [ 0.00128312 0.99871695]\n", | |
"1.0 [ 0.00962798 0.99037194]\n", | |
"1.0 [ 8.06932861e-04 9.99193013e-01]\n", | |
"1.0 [ 0.00115529 0.99884474]\n", | |
"1.0 [ 0.00167788 0.99832207]\n", | |
"1.0 [ 0.00101345 0.99898654]\n", | |
"1.0 [ 0.00865112 0.99134892]\n", | |
"1.0 [ 0.0377437 0.96225631]\n", | |
"1.0 [ 0.02015107 0.97984892]\n", | |
"1.0 [ 0.00976999 0.99023002]\n", | |
"1.0 [ 0.00167574 0.99832422]\n" | |
] | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAksAAAJCCAYAAADQsoPKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAHSdJREFUeJzt3V+sdWldH/DvrzP8MWodQCFkZlpomAu8qEgndBJ6oWgN\noHG4gBRjZUImeW9sgtHGojemTU30RgypIZkIcTAqEpQyMaZ1MmDsDZQZoYC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/EyS/5rk\ng0n+SZIvJnnLGOPL0x/s/5Kjs+e+luTtY4yH91H3oamqf5XkfyT5bP7hGIufztFxS/pqJqrqn+fo\nYNObcvTF9INjjP9UVf8sRyMYL0zyqST/dozxN1X1/CS/mqNj0L6c5K1jjD/fT/WHadoN9+/HGD+g\nn+Zn6pMPT3dvTvLrY4yfraoXZcvbvr2HJQCAOdv3bjgAgFkTlgAAGsISAEBDWAIAaAhLAAANYQkA\noCEsAQA0hCUAgMb/B6PPLpmm/IWJAAAAAElFTkSuQmCC\n", | |
"text/plain": [ | |
"<matplotlib.figure.Figure at 0x7f1bf4318ac8>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"# visualize the positive anchors\n", | |
"indices = np.where(labels[0, :] > 0)[0]\n", | |
"im = image_batch[0, ...].copy()\n", | |
"print(labels.shape, classification.shape, anchors.shape)\n", | |
"for idx in indices:\n", | |
" # print the label and the classification scores\n", | |
" print(labels[0, idx], classification[0, idx, :])\n", | |
" b = anchors[0, idx, :].astype(int)\n", | |
" cv2.rectangle(im, (b[0], b[1]), (b[2], b[3]), (0, 1, 0), 3)\n", | |
" \n", | |
"plt.figure(figsize=(10, 10))\n", | |
"plt.imshow(im)\n", | |
"plt.show()" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Generate anchors for a certain image size" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 25, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import keras_retinanet.layers\n", | |
"\n", | |
"im_info = keras.layers.Input((3,))\n", | |
"gt_boxes = keras.layers.Input((None, 5))\n", | |
"\n", | |
"shapes = [(64, 64), (32, 32), (16, 16), (8, 8), (4, 4)]\n", | |
"strides = [8, 16, 32, 64, 128]\n", | |
"sizes = [32, 64, 128, 256, 512]\n", | |
"idx = 2\n", | |
"\n", | |
"labels, bbox_reg_targets, anchors = keras_retinanet.layers.AnchorTarget(shapes[idx], strides[idx], sizes[idx])([im_info, gt_boxes])\n", | |
"anchor_model = keras.models.Model(inputs=[im_info, gt_boxes], outputs=[labels, anchors])\n", | |
"\n", | |
"l, a = anchor_model.predict([im_info_batch, gt_boxes_batch])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 26, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAksAAAJCCAYAAADQsoPKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAHSdJREFUeJzt3V+sdWldH/DvrzP8MWodQCFkZlpomAu8qEgndBJ6oWgN\noHG4gBRjZUImeW9sgtHGojemTU30RgypIZkIcTAqEpQyMaZ1MmDsDZQZoYCOlldDmTczYWKBUUui\nGX16cdaLZ94557f3OWf/Wevszyd5c/Ze+9lr//b77LPOdz9rrWfVGCMAAJzsH+27AACAOROWAAAa\nwhIAQENYAgBoCEsAAA1hCQCgsZWwVFWvr6o/raqrVfXObbwGAMAu1KbnWaqqm5L87yT/Osm1JJ9M\n8kNjjD/e6AsBAOzANkaWXpPk6hjjz8cYf5vkA0nu3sLrAABs3c1bWOetSR47dv9akn/ZPaGqTCMO\nAOzaX4wxvm1Vo22EpTph2bPCUFVdSXJlC68PALCO/7NOo22EpWtJbj92/7Ykj9/YaIxxX5L7EiNL\nAMB8beOYpU8muaOqXl5Vz03y1iQPbOF1AAC2buMjS2OMp6vq3yX570luSvK+McYfbfp1AAB2YeNT\nB5yrCLvhAIDde2SMceeqRmbwBgBoCEsAAA1hCQCgISwBADSEJQCAhrAEANAQlgAAGsISAEBjG9eG\ng/WYipRDctIlxoFFMLLEfghKHJoRn3tYKGGJ3fMHg0Pm8w+LIywBADSEJQCAhgO8mY9dHwB72u4Q\nB+Iu31z61i43uBSMLAEANIQlAICGsAQA0BCWAAAawhIAQENYAgBoCEsAAA1hCQCgISwBADSEJQCA\nhrAEANAQlgAAGsISAEBDWAIAaA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qc9qKofSPLkGOORqvqu64tPaKqf5uG1Y4zHq+rFSR6sqj9p\n2m6sr/Y9snQtye3H7t+W5PE91cLJvnR92HL6+eS0XN/tUVU9J0dB6dfGGL89LdZXMzXG+GqS38/R\nMWa3VNX1L6rH++Lr/TQ9/i159m5xNu+1SX6wqr6Qo0NBXpejkSb9NENjjMenn0/m6AvIa7KDbd++\nw9Ink9wxnXXw3CRvTfLAnmvimR5Ics90+54kHzm2/G3T2QZ3JXnq+jAo2zUdH/HeJI+OMX7h2EP6\nakaq6tumEaVU1Tck+d4cHV/2sSRvnprd2E/X++/NST46TIS3dWOMnxpj3DbGeFmO/gZ9dIzxw9FP\ns1NV31hV33z9dpLvS/K57GDbt/dJKavqjTlK8Tcled8Y42f3WtABq6rfSPJdObpy85eS/EyS/5rk\ng0n+SZIvJnnLGOPL0x/s/5Kjs+e+luTtY4yH91H3oamqf5XkfyT5bP7hGIufztFxS/pqJqrqn+fo\nYNObcvTF9INjjP9UVf8sRyMYL0zyqST/dozxN1X1/CS/mqNj0L6c5K1jjD/fT/WHadoN9+/HGD+g\nn+Zn6pMPT3dvTvLrY4yfraoXZcvbvr2HJQCAOdv3bjgAgFkTlgAAGsISAEBDWAIAaAhLAAANYQkA\noCEsAQA0hCUAgMb/B6PPLpmm/IWJAAAAAElFTkSuQmCC\n", | |
"text/plain": [ | |
"<matplotlib.figure.Figure at 0x7f1bf3943748>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"# show labeled anchors\n", | |
"indices = np.where(l[0, :] > 0)[0]\n", | |
"im = image_batch[0, ...].copy()\n", | |
"for idx in indices:\n", | |
" b = a[0, idx, :].astype(int)\n", | |
" cv2.rectangle(im, (b[0], b[1]), (b[2], b[3]), (0, 1, 0), 3)\n", | |
" \n", | |
"plt.figure(figsize=(10, 10))\n", | |
"plt.imshow(im)\n", | |
"plt.show()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment