-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Update utils.py and Create test_utils_predict.py #566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@2wins thanks, I have one question. If the number of example can not be divided by the batch size, it is still work fine? |
@zsdonghao Partially yes. Please check my comment in #288. |
@2wins @zsdonghao why not trying to write a small unittests for all the cases you could think of? BTW. In case you need smthg more versatile, |
@DEKHTIARJonathan good idea. @2wins could you help to put the test in this PR? Simply extend this one https://github.com/tensorlayer/tensorlayer/blob/master/tests/test_mnist_simple.py |
@DEKHTIARJonathan @zsdonghao Please see the below snippets. # case 1: No. of examples is not divisible by batch_size
# but the input placeholder's first dim is None.
x = tf.placeholder(tf.float32, [None, 5, 5, 3])
X = np.ones([127, 5, 5, 3])
net = tl.layers.InputLayer(x)
y = net.outputs
y_op = tf.nn.softmax(y)
result = tl.utils.predict(sess, net, X, x, y_op, batch_size=8) # case 2: No. of examples > batch_size & not divisible by batch_size
x = tf.placeholder(tf.float32, [8, 5, 5, 3])
X = np.ones([127, 5, 5, 3])
net = tl.layers.InputLayer(x)
y = net.outputs
y_op = tf.nn.softmax(y)
result = tl.utils.predict(sess, net, X, x, y_op, batch_size=8) # case 3: No. of examples < batch_size (actually same with the last mini-batch in case 2)
x = tf.placeholder(tf.float32, [8, 5, 5, 3])
X = np.ones([7, 5, 5, 3])
net = tl.layers.InputLayer(x)
y = net.outputs
y_op = tf.nn.softmax(y)
result = tl.utils.predict(sess, net, X, x, y_op, batch_size=8) |
@2wins nice! it would be great to add this test scripts into test folder ~ |
@DEKHTIARJonathan I see. Sorry to bother you. |
There is a huge button in the readme. There is no way u can miss it. |
BTW. As you can see the test is still failing. So there is an error either in your modifications or your test 😉. |
@DEKHTIARJonathan OK, I'll check it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why most of the test is commented out ?
The modification is supposed to cover all cases right ?
CHANGELOG.md
Outdated
- `tutorial_tfslim` added by (@2wins). | ||
- `tutorial_tfslim` added (by @2wins). | ||
- Tests: | ||
- `test_utils_predict.py` added (by @2wins). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please mention why the test has been added: to insure that issue #??? is solved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I didn't know what comment is proper and left a comment simply.
It is for the issue #288.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do the following:
- `test_utils_predict.py` added to reproduce and fix issue #288 (by @2wins).
The objective is just to have an idea about why you added this file.
@DEKHTIARJonathan |
@2wins I believe that everyone can make mistakes beginners like experts. Maybe we can raise an explicit Exception "Batch_Size Mismatched bla bla bla" to make it easier to debug. However, in my opinion, we should not in any case torture the library to make it user-error proof. |
@DEKHTIARJonathan You're right. I completely have the same opinion about that. I think the explicit exception is the best solution here. Thanks. |
You can use "AssertRaises" in the unittest to check that some case are raising an Exception ;) |
@DEKHTIARJonathan Thanks. I'll apply it. |
@2wins Please resolve the conflicts by copy-pasting the following, I can not do it on your fork.
|
@2wins you have to use the resolve conflicts function Please copy+paste exactly the code I gave you by replacing everything ;) |
@DEKHTIARJonathan I tried it first but |
CHANGELOG.md
Outdated
@@ -72,6 +72,8 @@ To release a new version, please update the changelog as followed: | |||
- Tutorials: | |||
- `tutorial_tfslim` has been introduced to show how to use `SlimNetsLayer` (by @2wins in #560). | |||
- Test: | |||
- `Layer_DeformableConvolution_Test` added to reproduce issue #572 with deformable convolution (by @DEKHTIARJonathan in #573) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is a duplicate, please remove it.
I don't know how this one appeared here anyhow ^^
@zsdonghao @lgarithm can you please take 2 minutes to have a look. To me the general structure of the PR is okay, I am unsure about np.concatenate vs np.hstack vs np.vstack. I let you have a look. If it is good, you can remove [WIP] in the PR title, and you will be able to merge the PR |
I don't use numpy much, but it looks OK from the document. LGTM (Not that the layout of the result variable is changed.) @zsdonghao I'll leave it to you to merge. |
@DEKHTIARJonathan FYI,
|
@zsdonghao Please confirm this PR. Thanks. |
* Update visualize.py * Update README.md Add an example for Adversarial Learning * Update more.rst Update the URLs * Update more.rst * Update example.rst Add the same link of BEGAN implementation. * Update example.rst * Update example.rst * Create tutorial_tfslim.py fixes #552 * Update tutorial_tfslim.py * Update utils.py Fix #565 * Update utils.py * Create test_utils_predict.py related with #288, #565, #566 * Create test_utils_predict.py * Update utils.py * Update test_utils_predict.py * Update CHANGELOG.md related to #566 * Update test_utils_predict.py * Update CHANGELOG.md * Update CHANGELOG.md * Update CHANGELOG.md * Update test_utils_predict.py * Update test_utils_predict.py * Update test_utils_predict.py * Update test_utils_predict.py * Update test_utils_predict.py * Update test_utils_predict.py (fix Bad Coding Style) * Update test_utils_predict.py * Update CHANGELOG.md * Update CHANGELOG.md * Update CHANGELOG.md * Update CHANGELOG.md * Update convolution.py (Add AtrousConv2dTransLayer) * Add AtrousConv2dTransLayer * Fix some mistakes * Follow protocols * Fix coding style (yapf) * AtrousConv2dLayer fixed * AtrousConv2dTransposeLayer refactored * Fix coding style (yapf) * Fix error * Bias Add using premade tf func * Old TF Code Removed * Renamed to AtrousDeConv2dLayer * Update CHANGELOG.md * Release 1.8.6rc2 * Documentation Fix
* Update utils.py Fix #565 * Update utils.py * Create test_utils_predict.py * Update utils.py * Update test_utils_predict.py * Update CHANGELOG.md related to #566 * Update test_utils_predict.py * Update CHANGELOG.md * Update CHANGELOG.md * Update CHANGELOG.md * Update test_utils_predict.py * Update test_utils_predict.py * Update test_utils_predict.py * Update test_utils_predict.py * Update test_utils_predict.py * Update test_utils_predict.py (fix Bad Coding Style) * Update test_utils_predict.py * Update CHANGELOG.md * Update CHANGELOG.md * Update CHANGELOG.md * Update CHANGELOG.md
* Update visualize.py * Update README.md Add an example for Adversarial Learning * Update more.rst Update the URLs * Update more.rst * Update example.rst Add the same link of BEGAN implementation. * Update example.rst * Update example.rst * Create tutorial_tfslim.py fixes #552 * Update tutorial_tfslim.py * Update utils.py Fix #565 * Update utils.py * Create test_utils_predict.py related with #288, #565, #566 * Create test_utils_predict.py * Update utils.py * Update test_utils_predict.py * Update CHANGELOG.md related to #566 * Update test_utils_predict.py * Update CHANGELOG.md * Update CHANGELOG.md * Update CHANGELOG.md * Update test_utils_predict.py * Update test_utils_predict.py * Update test_utils_predict.py * Update test_utils_predict.py * Update test_utils_predict.py * Update test_utils_predict.py (fix Bad Coding Style) * Update test_utils_predict.py * Update CHANGELOG.md * Update CHANGELOG.md * Update CHANGELOG.md * Update CHANGELOG.md * Update convolution.py (Add AtrousConv2dTransLayer) * Add AtrousConv2dTransLayer * Fix some mistakes * Follow protocols * Fix coding style (yapf) * AtrousConv2dLayer fixed * AtrousConv2dTransposeLayer refactored * Fix coding style (yapf) * Fix error * Bias Add using premade tf func * Old TF Code Removed * Renamed to AtrousDeConv2dLayer * Update CHANGELOG.md * Release 1.8.6rc2 * Documentation Fix
Checklist
Motivation and Context
Fix #565
In #288, the error has not been handled properly.
Description
np.hstack
makes data stacked alongaxis=1
whilenp.vstack
alongaxis=0
.