-
Notifications
You must be signed in to change notification settings - Fork 617
Implement sparse image warp #252
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
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.
Hi Kyle, thanks for the contribution! I leave some comments below and hope them could help you.
| self.assertAllClose(interp_val[0, :, 0], | ||
| target_interpolation) | ||
|
|
||
| def test_nd_linear_interpolation_unspecified_shape(self): |
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.
To use placeholder in the test case, we could test it with decorator test_utils.run_deprecated_v1.
Another way to test the shape of None at graph build time is #260 (comment).
| _ = interpolate_spline(train_points_ph, train_values_ph_invalid, | ||
| query_points_ph, order, reg_weight) | ||
|
|
||
| def test_interpolation_gradient(self): |
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.
I wonder if tf.test.compute_gradient can help you. test_utils.run_deprecated_v1 could be a workaround though.
|
Thanks for the comments, I believe I have addressed all three. On the third comment, I ended up switching to use |
|
@yhliang2018 Could you give this a review when time allows? Thanks. |
|
@seanpmorgan Sure, I will take a look. |
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.
Thanks for the PR!
| @@ -0,0 +1,303 @@ | |||
| # Copyright 2018 The TensorFlow Authors. All Rights Reserved. | |||
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.
nit: 2019
| @@ -0,0 +1,365 @@ | |||
| # Copyright 2018 The TensorFlow Authors. All Rights Reserved. | |||
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.
nit: 2019
| @@ -0,0 +1,201 @@ | |||
| # Copyright 2018 The TensorFlow Authors. All Rights Reserved. | |||
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.
nit: same as above.
| class _QuadraticPlusSinProblem1D(_InterpolationProblem): | ||
| """1D interpolation problem used for regression testing.""" | ||
| DATA_DIM = 1 | ||
| HARDCODED_QUERY_VALUES = { |
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.
Is it better to move all these test data to a util file, like test_util.py?
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.
I guess my preference is to leave them where they are so that the the tests and the test constants are co-located...also that's how the code was in TF.
|
|
||
| import tensorflow as tf | ||
| import tensorflow.compat.v1 as tf1 # TODO: locate placeholder | ||
| from tensorflow.python.training import momentum |
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.
It can be replaced as tf1.train.MomentumOptimizer, as we try to avoid direct import as much as possible.
Do you need to make addons as TF 2.0 as possible? If so, you may want to check optimizer v2: https://www.tensorflow.org/versions/r2.0/api_docs/python/tf/keras/optimizers/SGD
| num_boundary_points=3) | ||
|
|
||
| loss = tf.reduce_mean(tf.abs(warped_image - image)) | ||
| optimizer = momentum.MomentumOptimizer(0.001, 0.9) |
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.
tf1.train.MomentumOptimizer.
| merged_control_point_flows: augmented set of control point flows | ||
| """ | ||
|
|
||
| batch_size = tensor_shape.dimension_value(control_point_locations.shape[0]) |
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.
|
OK I think I've addressed all the comments. |
|
So I had to add scipy to the requirements. In previous commits, even in this PR, it was transitively included from the tensorflow install. However, it was missing in the latest couple of commits. For now, the easiest solution was to include it in the requirements. |
|
OK, I resolved all conflicts again on this PR, so it should be all synced up for review/merge. |
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.
Thanks Kyle! LGTM I'm not in love with binary test images as part of the repo, but it's easier than downloading and verifying the hash.
As requested in #25.
The main reason this is WIP is that I had to skip a handful of tests that were incompatible with eager mode. I still need to wrap my head around some of the eager testing / gradient mechanics, so I might not be able to finish this myself.