tfdeploy icon indicating copy to clipboard operation
tfdeploy copied to clipboard

There is no support for tf.strided_slice

Open jeanlaroche opened this issue 7 years ago • 3 comments

Currently, there's no support for tf.strided_slice() so if somewhere in your graph you have x[:,:,:,None] the graph won't execute. It's a complicated function, so it won't be easy to implement.

jeanlaroche avatar Apr 20 '17 00:04 jeanlaroche

Although I don't have time to look into this right now ... Challenge accepted ;)

riga avatar Apr 20 '17 08:04 riga

I had to implement a very simple strided_slice implementation


class StridedSlice(td.Operation):
    @staticmethod
    def func(input_, begins, ends, strides):
        output = input_.copy()
        for dim, (begin, end, stride) in enumerate(zip(begins,
                                                       ends,
                                                       strides)):
            if dim >= len(input_.shape):
                raise ValueError("Dimension mismatch")
            end = end if end else None
            output = output[begin:end:stride].T

        return output,

It is sufficient for a "simple" strided slice, without new dimension add via array[None] or array[np.newaxis]

It is certainly not the best implementation, but it could be useful?

celliern avatar Aug 22 '17 13:08 celliern

@celliern: your implementation did not work for me, but this did for simple slices...

@Operation.factory()
def StridedSlice(input_, begins, ends,strides):
    dim = len(input_.shape)
    slices = [slice(b,e if e else None,s) for b,e,s in zip(begins,ends,strides)]
    return np.copy(input_)[slices],

jeanlaroche avatar Dec 07 '18 18:12 jeanlaroche