Skip to content
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

error in test_contextual_attention() #176

Closed
masadcv opened this issue Nov 13, 2018 · 13 comments
Closed

error in test_contextual_attention() #176

masadcv opened this issue Nov 13, 2018 · 13 comments

Comments

@masadcv
Copy link

masadcv commented Nov 13, 2018

While running the following:
python inpaint_ops.py --imageA examples/style_transfer/bnw_butterfly.png --imageB examples/style_transfer/bike.jpg --imageOut examples/style_transfer/bike_style_out.png

I get the following error:
Traceback (most recent call last):
File "/opt/virtual_tensorflow/g_tf_neuralgym/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 558, in set_shape
unknown_shape)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Dimension 1 in both shapes must be equal, but are 166 and 64. Shapes are [1,166,250,2] and [1,64,64,2].

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "inpaint_ops.py", line 513, in
test_contextual_attention(args)
File "inpaint_ops.py", line 360, in test_contextual_attention
training=False, fuse=False)
File "inpaint_ops.py", line 313, in contextual_attention
offsets.set_shape(int_bs[:3] + [2])
File "/opt/virtual_tensorflow/g_tf_neuralgym/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 561, in set_shape
raise ValueError(str(e))
ValueError: Dimension 1 in both shapes must be equal, but are 166 and 64. Shapes are [1,166,250,2] and [1,64,64,2].

I can see this has been logged before here: #67
But cant find any fix. Can you please let me know how I can fix this?

@JiahuiYu
Copy link
Owner

What image are you using? A simple fix can be commenting the lines related to offsets. Offsets are only used to visualize.

@masadcv
Copy link
Author

masadcv commented Nov 13, 2018

I am using the command and images provided in the repository:
python inpaint_ops.py --imageA examples/style_transfer/bnw_butterfly.png --imageB examples/style_transfer/bike.jpg --imageOut examples/style_transfer/bike_style_out.png

--imageA examples/style_transfer/bnw_butterfly.png
--imageB examples/style_transfer/bike.jpg
--imageOut examples/style_transfer/bike_style_out.png

@JiahuiYu
Copy link
Owner

@devkicks I don't know on your side it returns error - on my side it is fine. Try to remove all offsets related code, and set flow to None.

@masadcv
Copy link
Author

masadcv commented Nov 13, 2018

Many thanks for checking this. With offset calculation included, I still get the error. I commented out all things related to offset calculation and now it is fine. I am using tensorflow 1.12.0 on Ubuntu 16.

@JiahuiYu
Copy link
Owner

@devkicks Many thanks for your information and I think others may also find it helpful.

@daa233
Copy link

daa233 commented Dec 1, 2018

Hi, @devkicks and @JiahuiYu , I have met the same error with tensorflow 1.12.0 and it works fine if I change the tensorflow version to 1.7.0.

@JiahuiYu
Copy link
Owner

JiahuiYu commented Dec 1, 2018

Thanks a lot for your report.

@shenjackson
Copy link

shenjackson commented Jan 9, 2019

So, how to solve this problem when I use tensorflow 1.12.0?

@JiahuiYu
Copy link
Owner

JiahuiYu commented Jan 9, 2019

@shenjackson

Many thanks for checking this. With offset calculation included, I still get the error. I commented out all things related to offset calculation and now it is fine. I am using tensorflow 1.12.0 on Ubuntu 16.

@shenjackson
Copy link

I use tensorflow 1.12.0 on CentOS7.... I don't know how to remove all offsets related code, and set flow to None. But I will try my best to solve it = =

@shenjackson
Copy link

haha, I just solved this problem.

@JiahuiYu
Copy link
Owner

JiahuiYu commented Jan 9, 2019

@shenjackson If possible, please share your experience so others can have a reference as well. :)

@shenjackson
Copy link

shenjackson commented Jan 10, 2019

OK! I commented on the relevant code about “flow”,and it can work fine.

like this

"""
print(offsets)
offsets = tf.concat(offsets, axis=0)
offsets.set_shape(int_bs[:3] + [2])
# case1: visualize optical flow: minus current position
h_add = tf.tile(tf.reshape(tf.range(bs[1]), [1, bs[1], 1, 1]), [bs[0], 1, bs[2], 1])
w_add = tf.tile(tf.reshape(tf.range(bs[2]), [1, 1, bs[2], 1]), [bs[0], bs[1], 1, 1])
offsets = offsets - tf.concat([h_add, w_add], axis=3)
# to flow image
flow = flow_to_image_tf(offsets)
# # case2: visualize which pixels are attended
# flow = highlight_flow_tf(offsets * tf.cast(mask, tf.int32))
if rate != 1:
    flow = resize(flow, scale=rate, func=tf.image.resize_nearest_neighbor)
"""
flow = []
return y, flow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants