avivt / VIN

Value Iteration Networks
Other
287 stars 69 forks source link

Purpose of image_shape and filter_shape in conv2D_keep_shape? #5

Open hi-abhi opened 7 years ago

hi-abhi commented 7 years ago

In your conv2d_keep_shape function which I copied below what is the purpose of the image_shape and filter_shape args?

def conv2D_keep_shape(x, w, image_shape, filter_shape, subsample=(1, 1)):
    # crop output to same size as input
    fs = T.shape(w)[2] - 1  # this is the filter size minus 1
    ims = T.shape(x)[2]     # this is the image size
    return theano.sandbox.cuda.dnn.dnn_conv(img=x,
                                            kerns=w,
                                            border_mode='full',
                                            subsample=subsample,
                                            )[:, :, fs/2:ims+fs/2, fs/2:ims+fs/2]

The parameters exist when you call the function every time you want to do a convolution, but they aren't being used in anyway. For example:

self.h = conv2D_keep_shape(in_x, self.w0, image_shape=[batchsize, self.w0.shape.eval()[1], imsize[0], imsize[1]], filter_shape=self.w0.shape.eval())

Are they intended to be used somehow or is this a remnant of old code being refactored? I ask because I implemented this architecture in TensorFlow and am attempting to replicate the results.

avivt commented 7 years ago

Hi, This is indeed a remnant of old code. The current code uses cuDNN for the convolution, which doesn't take as input the image_shape and filter_shape. Before I used the standard Theano conv2d (slower than cuDNN), which could take these parameters as input. Actually, I see that now that Theano has a added features to their conv2d function to make it keep a smae shape convolution (http://deeplearning.net/software/theano/library/tensor/nnet/conv.html#theano.tensor.nnet.conv2d) so I guess this whole function can be replaced by it.

Excited to see your tensorflow implementation!

hi-abhi commented 7 years ago

I figured that was the case and just wanted to make sure. Tensorflow has a "SAME" padding for conv2d which does the same thing as well.

My implementation is here: https://github.com/TheAbhiKumar/tensorflow-value-iteration-networks

It converges for the 8x8, but I am still having trouble with the 16x16 and 28x28 domains. I am starting to suspect that my implementation isn't exactly the same as yours. TensorFlow's advanced indexing capabilities aren't as strong as NumPy or Theano's so I kind of have to hack around it by transposing, indexing separately and then using tf.gather_nd. I'll have to take a deeper look into it and see why I am not getting the expected results.

Also, do you have an ETA for when the datasets/code will be uploaded for the other experiments? I am interested in implementing the continuous control and webnav models.

avivt commented 7 years ago

Cool repo :)

Yes, Theano's indexing capabilities are great, which was one reason to use it. I have an early implementation of VINs in CGT http://rll.berkeley.edu/cgt/, which also had to deal with the indexing issue. I can dig it up and send you, if you think it might be useful.

No ETA at present, sorry. I will say that I intend to first publish the Mars code.

On Thu, Dec 29, 2016 at 1:29 PM, Abhishek Kumar notifications@github.com wrote:

I figured that was the case and just wanted to make sure. Tensorflow has a "SAME" padding for conv2d which does the same thing as well.

My implementation is here: https://github.com/ TheAbhiKumar/tensorflow-value-iteration-networks

It converges for the 8x8, but I am still having trouble with the 16x16 and 28x28 domains. I am starting to suspect that my implementation isn't exactly the same as yours. TensorFlow's advanced indexing capabilities aren't as strong as NumPy or Theano's so I kind of have to hack around it by transposing, indexing separately and then using tf.gather_nd. I'll have to take a deeper look into it and see why I am not getting the expected results.

Also, do you have an ETA for when the datasets/code will be uploaded for the other experiments? I am interested in implementing the continuous control and webnav models.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/avivt/VIN/issues/5#issuecomment-269696401, or mute the thread https://github.com/notifications/unsubscribe-auth/AOeQNeQuocb9tkkPC5f04lVpk25tR77mks5rNCZRgaJpZM4LWp07 .

hi-abhi commented 7 years ago

I would appreciate that. Perhaps that implementation might help me figure out the issues with my implementation.