This repository was archived by the owner on Jul 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 137
Add flatten & reshape layers #32
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fe0cd3c
Add Triplet loss function
tanmayb123 534ea7d
Add "flatten" and "reshape" layers
tanmayb123 8a794b7
Remove triplet loss
tanmayb123 1a683b4
Add TensorShape initializer for Reshape layer
tanmayb123 b658bee
Simplify reshaping logic.
rxwei 48dcaac
Merge branch 'master' of github.com:tensorflow/swift-apis into add-fl…
rxwei df4352d
Remove wrt list.
rxwei c91c599
Fix reshape.
rxwei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR #22848 changed the behavior of differentiation through non-differentiable types, so it may break this function (requiring a
.withoutDerivative()
call somewhere). Holding off until the next toolchain release (Monday) will be a good idea.Also, a more efficient implementation would be to use
.shapeTensor
whenever you need to get the shape from a tensor, and not use any values ofTensorShape
type in the function body. On line 510,newShape
can be defined usingTensor
's concatenation operator,Tensor.concatenated(with:)
or++
. (BTW, concatenation ops do not have a derivative defined yet, would you like to add one?)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New toolchain released!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My recommendation would be:
But I see also @rxwei's point about preferring purely TF-side shape manipulation.
If we don't switch to that completely, though, we should replace
reshaped(toShape: Tensor<Int32>(foo))
withreshaped(to: foo)
(assuming that actually works now).Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following is the host-free version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The host-free version is currently an order of magnitude slower on CPU than the hosty version (about 30us for mine and 300us for yours).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
D'oh that's terrible. Ok.