-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
roi pooling minimal example in Jupyter Notebook
- Loading branch information
Showing
2 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
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
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
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 | ||
} |