Skip to content

Commit

Permalink
roi pooling minimal example in Jupyter Notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
stared committed Apr 7, 2017
1 parent fc47bee commit cbaf11f
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ from roi_pooling.roi_pooling_ops import roi_pooling
rpooling = roi_pooling(feature_map, rois, 7, 7)
# continue the model
```

Working example in Jupyter Notebook: [examples/roi_pooling_minimal_example.ipynb](https://github.com/deepsense-io/roi-pooling/blob/master/examples/roi_pooling_minimal_example.ipynb)

148 changes: 148 additions & 0 deletions examples/roi_pooling_minimal_example.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* blog post: [Region of interest pooling explained - deepsense.io](https://deepsense.io/region-of-interest-pooling-explained/)\n",
"* repository: [deepsense-io/roi-pooling](https://github.com/deepsense-io/roi-pooling)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from __future__ import print_function\n",
"\n",
"import tensorflow as tf\n",
"import numpy as np\n",
"\n",
"from roi_pooling.roi_pooling_ops import roi_pooling"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# 4x4 feature map with only 1 channel\n",
"input_value = [[\n",
" [[1], [2], [4], [4]],\n",
" [[3], [4], [1], [2]],\n",
" [[6], [2], [1], [7]],\n",
" [[1], [3], [2], [8]]\n",
"]]\n",
"input_value = np.asarray(input_value, dtype='float32')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# regions of interest as lists of:\n",
"# feature map index, upper left, bottom right coordinates\n",
"rois_value = [\n",
" [0, 0, 0, 1, 3],\n",
" [0, 2, 2, 3, 3],\n",
" [0, 1, 0, 3, 2]\n",
"]\n",
"rois_value = np.asarray(rois_value, dtype='int32')\n",
"\n",
"# in this case we have 3 RoI pooling operations:\n",
"# * channel 0, rectangular region (0, 0) to (1, 3)\n",
"# xx..\n",
"# xx..\n",
"# xx..\n",
"# xx..\n",
"#\n",
"# * channel 0, rectangular region (2, 2) to (3, 3)\n",
"# ....\n",
"# ....\n",
"# ..xx\n",
"# ..xx\n",
"# * channel 0, rectangular region (1, 0) to (3, 2)\n",
"# ....\n",
"# xxx.\n",
"# xxx.\n",
"# xxx."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[[[ 3. 4.]\n",
" [ 6. 3.]]]\n",
"\n",
"\n",
" [[[ 1. 7.]\n",
" [ 2. 8.]]]\n",
"\n",
"\n",
" [[[ 4. 4.]\n",
" [ 4. 7.]]]]\n"
]
}
],
"source": [
"input_featuremap = tf.placeholder(tf.float32)\n",
"rois = tf.placeholder(tf.int32)\n",
"input_const = tf.constant(input_value, tf.float32)\n",
"rois_const = tf.constant(rois_value, tf.int32)\n",
"y = roi_pooling(input_const, rois_const, pool_height=2, pool_width=2)\n",
"\n",
"with tf.Session('') as sess:\n",
" y_output = sess.run(y, feed_dict={input_featuremap: input_value, rois: rois_value})\n",
" print(y_output)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit cbaf11f

Please sign in to comment.