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

Issue 4746 #4985

Closed
wants to merge 4 commits into from
Closed

Issue 4746 #4985

wants to merge 4 commits into from

Conversation

guotong1988
Copy link
Contributor

@guotong1988 guotong1988 commented Oct 15, 2016

#4746

This code is the first commit to fix issue-4746 . I will commit the unit test code and doc later.
Thank you for your review . Thank you for any advice.I will work on it again for the advice and learn from the reviewers.

I test this code with:

x_image = tf.placeholder(tf.float32,shape=[4,4])
x = tf.reshape(x_image,[1,4,4,1])

ksize_feed = np.array([1,2,2,1])

ksize_init = tf.placeholder(tf.int32, shape=[4])
ksize0 = tf.reshape(ksize_init,[2,2])
ksize1 = tf.reshape(ksize0,[1,2,2,1])

strides=[1,2,2,1]
padding = 'VALID'

y = tf.nn.max_pool(value=x,ksize=ksize1,strides=strides,padding=padding)

x_data = np.array([[4,3,1,8],[7,2,6,3],[2,0,1,1],[3,4,2,5]],
            dtype = np.float32)

with tf.Session() as sess:
    init = tf.initialize_all_variables()
    sess.run(init)

    x = (sess.run(x,feed_dict={x_image:x_data}))
    y = (sess.run(y,feed_dict={x_image:x_data,ksize_init:ksize_feed}))

    print "The shape of x:\t", x.shape, ",\t and the x.reshpe(4,4) is :"
    print x.reshape(4,4)
    print ""

    print "The shape of y:\t", y.shape, ",\t and the y.reshpe(2,2) is :"
    print y.reshape(2,2)
    print ""

@tensorflow-jenkins
Copy link
Collaborator

Can one of the admins verify this patch?

@mention-bot
Copy link

@guotong1988, thanks for your PR! By analyzing the history of the files in this pull request, we identified @vrv, @keveman and @zheng-xq to be potential reviewers.

@guotong1988
Copy link
Contributor Author

guotong1988 commented Oct 15, 2016

also test the code with:

import numpy as np
import tensorflow as tf

x_image = tf.placeholder(tf.float32,shape=[4,4])
x = tf.reshape(x_image,[1,4,4,1])

ksize = np.array([1,2,2,1])

strides=[1,2,2,1]
padding = 'VALID'

y = tf.nn.max_pool(value=x,ksize=ksize,strides=strides,padding=padding)

x_data = np.array([[4,3,1,8],[7,2,6,3],[2,0,1,1],[3,4,2,5]],
            dtype = np.float32)

with tf.Session() as sess:
    init = tf.initialize_all_variables()
    sess.run(init)

    x = (sess.run(x,feed_dict={x_image:x_data}))
    y = (sess.run(y,feed_dict={x_image:x_data}))

    print "The shape of x:\t", x.shape, ",\t and the x.reshpe(4,4) is :"
    print x.reshape(4,4)
    print ""

    print "The shape of y:\t", y.shape, ",\t and the y.reshpe(2,2) is :"
    print y.reshape(2,2)
    print ""

@@ -448,7 +448,10 @@ Status AvgPoolShape(shape_inference::InferenceContext* c) {

Status MaxPoolShape(shape_inference::InferenceContext* c) {
ShapeHandle input_shape;
ShapeHandle kernel_sizes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try building this? This looks like a syntax error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's my mistake.I did build it but I make a copy mistake.

kernel_rows = c->Dim(kernel_sizes, 1);
kernel_cols = c->Dim(kernel_sizes, 2);
kernel_depth = c->Dim(kernel_sizes, 3);
// kernel_depth = kernel_sizes[1];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to clean these up.

@zheng-xq
Copy link
Contributor

Unfortunately, modifying an existing op like this breaks the backward compatiblity of TensorFlow.

For now, it is a good idea to add a custom op on github outside TensorFlow, so people can try it if they are interested. When it gets popular and used in more models, we can move it to TF contrib or TF core.

https://www.tensorflow.org/versions/r0.11/how_tos/adding_an_op/index.html

Thanks.

@guotong1988
Copy link
Contributor Author

OK , I will take another issue.

@drpngx
Copy link
Contributor

drpngx commented Oct 18, 2016

Thanks for looking into this! I'll close the PR. Feel free to reopen if appropriate.

@drpngx drpngx closed this Oct 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants