Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

Fast style transfer example #191

Merged
merged 10 commits into from
Dec 4, 2019
Merged

Conversation

vvmnnnkv
Copy link
Contributor

@vvmnnnkv vvmnnnkv commented Aug 7, 2019

Example model for issue #146

@review-notebook-app
Copy link

Check out this pull request on ReviewNB: https://app.reviewnb.com/tensorflow/swift-models/pull/191

You'll be able to see notebook diffs and discuss changes. Powered by ReviewNB.

Copy link
Contributor

@rxwei rxwei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch. I left some high level comments on coding style. Could you please make sure that the Swift API Design Guidelines and the Google Swift Style Guide are applied to everything in this PR?

@vvmnnnkv
Copy link
Contributor Author

vvmnnnkv commented Aug 8, 2019

Hi @rxwei, I've tried to spot & fix similar issues manually, but do you use some kind of 'official' linter to make this job automatic?

@BradLarson
Copy link
Contributor

@vvmnnnkv - For formatting, I use swift-format: https://github.com/apple/swift-format , for which we have a .swift-format file in this repository that defines the formatting conventions used here. It really helps to catch even subtle formatting issues.

Might not work as well on notebooks, however.

@vvmnnnkv
Copy link
Contributor Author

@BradLarson - interesting, https://github.com/apple/swift-format crashes when compiled in Ubuntu (with DEVELOPMENT-SNAPSHOT-2019-07-10-a). I'm not sure if this repo is the right swift-format @rxwei mentions in this PR tensorflow/swift-apis#374? I also found https://github.com/google/swift/tree/format but it looks outdated.
Compiling apple/swift-format with Xcode 11b4 works, though. I've applied it to the code, but some places seem to look less readable after that, e.g. inline closure here: 29e9f88#diff-0a85214f52c515dacd5ce305c43b1720

@BradLarson
Copy link
Contributor

@vvmnnnkv - Yes, I've seen similar problems with Swift for TensorFlow toolchains vs. stock Swift toolchains on swift-format. I think it's something that's being looked into. In the meantime, using swift-format with the stock toolchain should be fine.

We do know that it has some problems around a few specific cases, so you may need to hand-correct in a couple of places. It works well overall, but isn't perfect. I know those cases are being worked on.

@vvmnnnkv
Copy link
Contributor Author

@rxwei @BradLarson
I think I'm done with all changes.

@differentiable
public func callAsFunction(_ input: Tensor<Scalar>) -> Tensor<Scalar> {
// Calculate mean & variance along H,W axes.
let mean = input.mean(alongAxes: [1, 2])
Copy link
Contributor

@t-ae t-ae Aug 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moments computes mean and variance simultaneously.
https://github.com/tensorflow/swift-apis/blob/c7595c4b4b0e824cd6d9449e2bed39944fafb472/Sources/TensorFlow/Operators/Math.swift#L2501-L2512
(variance computes mean internally so moments is some more efficient)

/// 2-D layer applying instance normalization over a mini-batch of inputs.
///
/// Reference: [Instance Normalization](https://arxiv.org/abs/1607.08022)
public struct InstanceNorm2D<Scalar: TensorFlowFloatingPoint>: Layer {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding InstanceNorm2D to swift-apis?

rxwei pushed a commit to tensorflow/swift-apis that referenced this pull request Oct 1, 2019
Makes Tensor.padded() on par with tf.pad().
Added padding modes (reflect, symmetric) can be used to make "resize-convolution" layers like in tensorflow/swift-models#191.
ocampor pushed a commit to ocampor/swift-apis that referenced this pull request Oct 4, 2019
Makes Tensor.padded() on par with tf.pad().
Added padding modes (reflect, symmetric) can be used to make "resize-convolution" layers like in tensorflow/swift-models#191.
@BradLarson
Copy link
Contributor

Sorry it has been so long since we've reviewed this. I quick resolved the couple of merge conflicts, but it looks like a few areas of this model might need to be brought up to date to get this to build under the current toolchain.

The warnings don't look too hard to fix (Raw has been renamed to _Raw, transposed(permutation:) instead of transposed(withPermutations:)). I think you might need to make ReflectionPad2D and maybe others ParameterlessLayers to resolve the ...does not conform to protocol 'VectorProtocol' errors, but I might be mistaken there.

If you can get this to build cleanly under the current toolchain, I think this would be good to pull in. It looks like all previous comments have been addressed.

@vvmnnnkv
Copy link
Contributor Author

vvmnnnkv commented Dec 1, 2019

Hi @BradLarson
With suggested changes it compiles fine on v0.6 toolchain (Ubuntu). I also removed tensor extension for reflected padding because it's now included in swift-apis. Perhaps, I did this too early because example notebook doesn't work with Colab after that (error: there's no mode param in Tensor.padded). Do you know if Colab is going to be updated to v0.6 soon?

@BradLarson
Copy link
Contributor

We're looking into the test failure, which looks to be a toolchain artifact. Once we get that resolved, I'll re-run CI and make sure everything's green. Sorry for the delay due to the U.S. holiday.

@BradLarson
Copy link
Contributor

We think we have a workaround for the failing test. Could you bring this branch up to date with the head of swift-models? I think that should allow for the tests to pass, with Marc's workaround that he committed yesterday.

Copy link
Contributor

@BradLarson BradLarson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like everything's building and testing correctly now, so I'll merge this in. Thanks again for the work on this.

@BradLarson BradLarson merged commit 25c4452 into tensorflow:master Dec 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants