-
Notifications
You must be signed in to change notification settings - Fork 138
Adding Convolution 3d Layer #128
Conversation
Tested the build on nightly btw, If there are any review changes I will update them. |
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.
Thank you! Could you please add a test to Tests/DeepLearningTests/LayerTests.swift
?
@dan-zheng, is it okay if I add tests in a later PR? It's a little difficult to think a test case for 3-d convolution. |
Actually, could you please add a test in this PR? For PRs that add new functionality, we try to add tests for the new functionality. It helps couple functionality and tests, and ensures that new functionality is correct. |
@dan-zheng on some other note, could you tell me about the V2 versions in the raw api. Like |
Yes, please use V2 raw ops when they exist. V2 ops have fixed semantics or performance improvements. |
@dan-zheng Updated the functions to V2. In this case, I think it was fixed semantics. The build also passes now. I am still thinking of a proper test for conv3d, so I will do that in a while. |
One reliable way to write a test program using Python TensorFlow as a reference, then port the test to Swift. Here's an example: from functools import reduce
import operator
import tensorflow as tf
def product(iterable):
return reduce(operator.mul, iterable, 1)
# Returns a tensor with increasing scalar values starting from zero,
# with the given shape.
def iota(shape):
x = tf.range(0, product(shape), dtype=tf.float32)
return tf.reshape(x, shape)
input_shape = [2, 1, 2, 1, 3]
filter_shape = [2, 2, 2, 3, 5]
strides = (1, 3, 2, 2, 1)
input = iota(input_shape)
filter = iota(filter_shape)
conv3d = tf.nn.conv3d(input, filter, strides=strides, padding='SAME')
with tf.Session() as session:
result = session.run(conv3d)
print(result.shape)
# (2, 1, 1, 1, 5)
print(result)
# [[[[[ 455. 470. 485. 500. 515.]]]]
#
#
#
# [[[[1175. 1226. 1277. 1328. 1379.]]]]]
# Write a Swift for TensorFlow test checking result shape/values! |
@dan-zheng done. It passes locally. |
@dan-zheng requesting a final review. Thanks for your time. |
- Change `testConv3D` to use a non-trivial bias. - Remove calls to `round` when calling `XCTAssertEqual`. - Fix `testAvgPool3D`.
Thanks @Shashi456! I pushed a commit fixing tests: cbeea35 A few notes:
|
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.
Thank you @Shashi456, great work! 🙂
@dan-zheng I'm actually curious about how your avgpool3d test cases failed, In my case they didn't. The only error i've been getting are the linker errors. |
Hmm, that is strange. ¯_(ツ)_/¯ |
@dan-zheng one last thing :P, We are done with Conv 1D, 2D, 3D and all pooling layers. We are done with the basic recurrent cells as well. Any specific layers higher up in the priority? |
How about adding a test for Conv2D? |
Added layer and respective vjps, the build also passes locally.
I'll write the tests in a later PR. It's pretty difficult to write tests for conv layers.