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

Add Permute layer #142

Closed
mkaze opened this issue Jun 19, 2021 · 4 comments · Fixed by #149
Closed

Add Permute layer #142

mkaze opened this issue Jun 19, 2021 · 4 comments · Fixed by #149
Assignees
Labels
good first issue Good for newcomers
Milestone

Comments

@mkaze
Copy link
Contributor

mkaze commented Jun 19, 2021

Currently, the support for Permute layer is missing and it would be great if we could add support for this layer as well. The desired PR addressing this issue should include:

  • Implementation of layer class named as Permute (hint: you can use tf.linalg.transpose(...) for forward pass of this layer).
  • Documentation of layer.
  • Test cases
  • Support for export of layer to JSON (see ModelSaver.kt)
  • Support for import of layer from JSON (see ModelLoader.kt)

Also, if needed, you can take a look at Keras documentation for this layer.

@therealansh
Copy link
Contributor

I'll like to work on this one.

@zaleslaw zaleslaw added the good first issue Good for newcomers label Jun 21, 2021
@zaleslaw zaleslaw added this to the 0.3 milestone Jun 21, 2021
@therealansh
Copy link
Contributor

Hey @mkaze the Permute layer implementation in keras uses perm which is a tuple. While in the tf.linalg.transpose(...) perm needs to be of Operand<U extends Number> . I dont think we can typecast a tuple(IntArray) into Number(Int)?

@mkaze
Copy link
Contributor Author

mkaze commented Jun 21, 2021

@therealansh As far as I understand, all Operand values resolve in a Tensor and therefore the U in Operand<U> refers to the underlying datatype of each single element of Tensor (e.g. Float, Int, etc.).
So you can simply put the permutation in an IntArray and then use tf.constant, like tf.constant(permArray), to create an instance of Constant<Int> (which is a basically a subclass of Operand) and then pass it to transpose function.

@zaleslaw
Copy link
Collaborator

zaleslaw commented Jun 21, 2021

Agree with @mkazetf.constantwill work for the array in this case, look at this in Flatten

@therealansh therealansh mentioned this issue Jun 22, 2021
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants