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

[New feature] col2im/ image patch #2819

Open
roya0045 opened this issue Jan 5, 2018 · 2 comments
Open

[New feature] col2im/ image patch #2819

roya0045 opened this issue Jan 5, 2018 · 2 comments
Assignees

Comments

@roya0045
Copy link

roya0045 commented Jan 5, 2018

Greetings,

I am writing this to officially document my proposition to add something that would separate a dataset into subparts like is it possible to do in Tensorflow and chainer.

The chainer version is the following: https://docs.chainer.org/en/stable/reference/generated/chainer.functions.im2col.html

With Tensorflow it's not that straightforward it can be done with proper reshaping:
https://www.tensorflow.org/versions/master/api_docs/python/tf/extract_image_patches

Here is the CNTK equivalent that I made, though it is different compared to the original chainer function as I made it more viable for broadcasting. I was wondering if it could be possible to integrate this officially as an utility function for all languages.

    def cnwindow(image,window,pad=0,stride=1):
        if pad>0:
            image=C.pad(image, pattern=[(0,0),(0,0),(pad,pad),(pad,pad)],  constant_value=0)
        image_shape=image.shape
        output_shape=(*image_shape[:-2],*window,((image_shape[-2]-window[-2])+1)//stride,((image_shape[-1]-window[-1])+1)//stride)
        holder=None
        for R in range(window[0]):
            j_lim = R + output_shape[-2]
            for H in range(window[1]):
                temp_data=C.slice(image,[-2,-1], [R*stride,H*stride], [j_lim*stride,(H +  output_shape[-1])*stride])
                if holder is None:
                    holder=temp_data
                else:
                    holder=C.splice(holder,temp_data,axis=1)
        output=(C.reshape(C.transpose(C.reshape(holder, shape=output_shape),(0,4,5,3,1,2)), (output_shape[0],*output_shape[5:3:-1],1,*output_shape[3:0:-1])))
        print(output.shape,"CNWINDOWSHAPE")#(0,5,4,3,2,1)
        return(output)
@ebarsoumMS
Copy link
Contributor

Can you submit is PR?

@roya0045
Copy link
Author

Sure, I'll just correct the name of the variables in the code, in what folder do you want me to put the code? (unless you are referring to @spandantiwari )

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

3 participants