desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Check that the correct number of variables are made when sharing.'
| def testSharing(self):
| inputs1 = tf.placeholder(tf.float32, shape=[None, 64])
inputs2 = tf.placeholder(tf.float32, shape=[None, 64])
ln = snt.LayerNorm()
ln(inputs1)
ln(inputs2)
self.assertEqual(len(tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES)), 2)
|
'Constructs a Sequential module.
This feeds the output of each layer into the next and returns the output
of the final layer.
If a layer returns a tuple, it is assumed that this must be unpacked into
the argument list of the next layer. If it is not a tuple, it is simply
passed through to the next layer unchanged.
Args... | def __init__(self, layers, name='sequential'):
| super(Sequential, self).__init__(name=name)
self._layers = tuple(layers)
is_not_callable = [(i, mod) for (i, mod) in enumerate(self._layers) if (not callable(mod))]
if is_not_callable:
raise TypeError('Items {} not callable with types: {}'.format(', '.join((str(i) for (i, _)... |
'Connects the Sequential module into the graph.
Args:
*args: A tuple of inputs, to be unpacked as the arguments to the first
layer.
Returns:
The output value of the last layer.'
| def _build(self, *args):
| net = args
for layer in self._layers:
if isinstance(net, tuple):
net = layer(*net)
else:
net = layer(net)
return net
|
'Tests the _fill_list private function in snt.conv.'
| def test(self):
| x = random.randint(1, 10)
self.assertEqual(conv._fill_shape(x, 1), (x,))
self.assertEqual(conv._fill_shape(x, 2), (x, x))
self.assertEqual(conv._fill_shape(x, 3), (x, x, x))
self.assertEqual(conv._fill_shape(x, 4), (x, x, x, x))
self.assertEqual(conv._fill_shape([x, (x + 1), (x + 2)], 3), (x, (x... |
'Test output shapes are correct.'
| @parameterized.Parameters(*zip(input_shape, stride, kernel_shape, padding, output_shape))
def testFunction(self, input_shape, stride, kernel_shape, padding, output_shape):
| self.assertEqual(conv._default_transpose_size(input_shape, stride, kernel_shape=kernel_shape, padding=padding), tuple(output_shape))
|
'Test ConvTranspose modules return expected default output shapes.'
| @parameterized.Parameters(*zip(input_shape, stride, kernel_shape, padding, output_shape))
def testModules(self, input_shape, stride, kernel_shape, padding, output_shape):
| if (len(input_shape) == 1):
module = snt.Conv1DTranspose
elif (len(input_shape) == 2):
module = snt.Conv2DTranspose
elif (len(input_shape) == 3):
module = snt.Conv3DTranspose
batch_size = [1]
channels = [1]
inputs = tf.zeros(shape=((batch_size + input_shape) + channels), ... |
'Test ConvTranspose modules with multiple connections.'
| @parameterized.Parameters(*zip(input_shape, stride, kernel_shape, padding, output_shape))
def testConnectTwice(self, input_shape, stride, kernel_shape, padding, output_shape):
| if (len(input_shape) == 1):
module = snt.Conv1DTranspose
elif (len(input_shape) == 2):
module = snt.Conv2DTranspose
elif (len(input_shape) == 3):
module = snt.Conv3DTranspose
batch_size = [1]
channels = [1]
inputs = tf.zeros(shape=((batch_size + input_shape) + channels), ... |
'The correct number of variables are created.'
| @parameterized.Parameters(*itertools.product(modules, (True, False)))
def testVariables(self, module_info, use_bias):
| (module, num_input_dims, module_kwargs) = module_info
mod_name = 'module'
input_shape = ((10,) * (num_input_dims + 2))
inputs = tf.placeholder(tf.float32, input_shape)
with tf.variable_scope('scope'):
conv_mod = module(name=mod_name, use_bias=use_bias, **module_kwargs)
self.assertEqual(c... |
'Error is thrown if the input is missing a channel dimension.'
| @parameterized.Parameters(*itertools.product(modules, (True, False)))
def testMissingChannelsError(self, module_info, use_bias):
| (module, num_input_dims, module_kwargs) = module_info
conv_mod = module(use_bias=use_bias, **module_kwargs)
inputs = tf.placeholder(tf.float32, ((10,) * (num_input_dims + 1)))
err = 'Input Tensor must have shape'
with self.assertRaisesRegexp(snt.IncompatibleShapeError, err):
conv... |
'Error is thrown if the input has been incorrectly flattened.'
| @parameterized.Parameters(*itertools.product(modules, (True, False)))
def testFlattenedError(self, module_info, use_bias):
| (module, num_input_dims, module_kwargs) = module_info
conv_mod = module(use_bias=use_bias, **module_kwargs)
inputs = tf.placeholder(tf.float32, ((10,) * (num_input_dims + 1)))
inputs = snt.BatchFlatten()(inputs)
err = 'Input Tensor must have shape'
with self.assertRaisesRegexp(snt.In... |
'Check that custom_getter option works.'
| @parameterized.Parameters(*modules)
def testCustomGetter(self, module, num_input_dims, module_kwargs):
| def stop_gradient(getter, *args, **kwargs):
return tf.stop_gradient(getter(*args, **kwargs))
inputs = tf.placeholder(tf.float32, ((10,) * (num_input_dims + 2)))
conv_mod1 = module(**module_kwargs)
out1 = conv_mod1(inputs)
conv_mod2 = module(custom_getter=stop_gradient, **module_kwargs)
o... |
'The generated shapes are correct with SAME padding.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testShapesSame(self, use_bias):
| batch_size = random.randint(1, 100)
in_height = random.randint(10, 288)
in_width = random.randint(10, 288)
in_channels = random.randint(1, 10)
out_channels = random.randint(1, 32)
kernel_shape_h = random.randint(1, 11)
kernel_shape_w = random.randint(1, 11)
inputs = tf.placeholder(tf.flo... |
'The generated shapes are correct when input shape not known.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testShapesNotKnown(self, use_bias):
| batch_size = 5
in_height = in_width = 32
in_channels = out_channels = 5
kernel_shape_h = kernel_shape_w = 3
inputs = tf.placeholder(tf.float32, shape=[None, None, None, in_channels], name='inputs')
conv1 = snt.Conv2D(name='conv1', output_channels=out_channels, kernel_shape=[kernel_shape_h, kerne... |
'No error is thrown if image shape isn\'t known for atrous convolution.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testShapesNotKnownAtrous(self, use_bias):
| inputs = tf.placeholder(tf.float32, shape=[None, None, None, 5], name='inputs')
conv1 = snt.Conv2D(name='conv1', output_channels=5, kernel_shape=[3, 3], padding=snt.SAME, stride=1, rate=2, use_bias=use_bias)
conv1(inputs)
|
'Errors are thrown for invalid kernel shapes.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testKernelShape(self, use_bias):
| snt.Conv2D(output_channels=10, kernel_shape=[3, 4], name='conv1', use_bias=use_bias)
snt.Conv2D(output_channels=10, kernel_shape=3, name='conv1', use_bias=use_bias)
err = 'Invalid kernel shape'
with self.assertRaisesRegexp(snt.IncompatibleShapeError, err):
snt.Conv2D(output_channels=10, ke... |
'Errors are thrown for invalid strides.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testStrideError(self, use_bias):
| snt.Conv2D(output_channels=10, kernel_shape=3, stride=1, name='conv1', use_bias=use_bias)
snt.Conv2D(output_channels=10, kernel_shape=3, stride=[1, 1], name='conv1', use_bias=use_bias)
snt.Conv2D(output_channels=10, kernel_shape=3, stride=[1, 1, 1, 1], name='conv1', use_bias=use_bias)
with self.assertRa... |
'Errors are thrown for invalid dilation rates.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testRateError(self, use_bias):
| snt.Conv2D(output_channels=10, kernel_shape=3, rate=1, name='conv1', use_bias=use_bias)
snt.Conv2D(output_channels=10, kernel_shape=3, rate=2, name='conv1', use_bias=use_bias)
for rate in [0, 0.5, (-1)]:
with self.assertRaisesRegexp(snt.IncompatibleShapeError, 'Invalid rate shape*'):
... |
'Errors are thrown for stride > 1 when using atrous convolution.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testRateAndStrideError(self, use_bias):
| err = 'Cannot have stride > 1 with rate > 1'
with self.assertRaisesRegexp(snt.NotSupportedError, err):
snt.Conv2D(output_channels=10, kernel_shape=3, stride=2, rate=2, name='conv1', use_bias=use_bias)
with self.assertRaisesRegexp(snt.NotSupportedError, err):
snt.Conv2... |
'Errors are thrown for invalid input types.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testInputTypeError(self, use_bias):
| conv1 = snt.Conv2D(output_channels=1, kernel_shape=3, stride=1, padding=snt.SAME, name='conv1', use_bias=use_bias, initializers=create_constant_initializers(1.0, 1.0, use_bias))
for dtype in (tf.float16, tf.float64):
x = tf.constant(np.ones([1, 5, 5, 1]), dtype=dtype)
err = 'Input must hav... |
'Test initializers work as expected.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testInitializers(self, use_bias):
| w = random.random()
b = random.random()
conv1 = snt.Conv2D(output_channels=1, kernel_shape=3, stride=1, name='conv1', use_bias=use_bias, initializers=create_constant_initializers(w, b, use_bias))
conv1(tf.placeholder(tf.float32, [1, 10, 10, 2]))
with self.test_session():
tf.variables_initial... |
'Test that initializers are not mutated.'
| def testInitializerMutation(self):
| initializers = {'b': tf.constant_initializer(0)}
initializers_copy = dict(initializers)
conv1 = snt.Conv2D(output_channels=1, kernel_shape=3, stride=1, name='conv1', initializers=initializers)
conv1(tf.placeholder(tf.float32, [1, 10, 10, 2]))
self.assertAllEqual(initializers, initializers_copy)
|
'Run through for something with a known answer using SAME padding.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testComputationSame(self, use_bias):
| conv1 = snt.Conv2D(output_channels=1, kernel_shape=3, stride=1, padding=snt.SAME, name='conv1', use_bias=use_bias, initializers=create_constant_initializers(1.0, 1.0, use_bias))
out = conv1(tf.constant(np.ones([1, 5, 5, 1], dtype=np.float32)))
expected_out = np.array([[5, 7, 7, 7, 5], [7, 10, 10, 10, 7], [7... |
'Run through for something with a known answer using snt.VALID padding.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testComputationValid(self, use_bias):
| conv1 = snt.Conv2D(output_channels=1, kernel_shape=3, stride=1, padding=snt.VALID, name='conv1', use_bias=use_bias, initializers=create_constant_initializers(1.0, 1.0, use_bias))
out = conv1(tf.constant(np.ones([1, 5, 5, 1], dtype=np.float32)))
expected_output = np.array([[10, 10, 10], [10, 10, 10], [10, 10... |
'Sharing is working.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testSharing(self, use_bias):
| conv1 = snt.Conv2D(output_channels=1, kernel_shape=3, stride=1, padding=snt.SAME, use_bias=use_bias, name='conv1')
x = np.random.randn(1, 5, 5, 1)
x1 = tf.constant(x, dtype=np.float32)
x2 = tf.constant(x, dtype=np.float32)
out1 = conv1(x1)
out2 = conv1(x2)
with self.test_session():
t... |
'The atrous conv is constructed and applied correctly with snt.VALID.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testAtrousConvValid(self, use_bias):
| conv1 = snt.Conv2D(output_channels=1, kernel_shape=3, stride=1, rate=2, padding=snt.VALID, name='conv1', use_bias=use_bias, initializers=create_constant_initializers(1.0, 0.0, use_bias))
out = conv1(tf.constant(np.ones([1, 5, 5, 1], dtype=np.float32)))
with self.test_session():
tf.variables_initiali... |
'The atrous conv 2D is constructed and applied correctly with SAME.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testAtrousConvSame(self, use_bias):
| conv1 = snt.Conv2D(output_channels=1, kernel_shape=3, stride=1, rate=2, padding=snt.SAME, name='conv1', use_bias=use_bias, initializers=create_constant_initializers(1.0, 1.0, use_bias))
out = conv1(tf.constant(np.ones([1, 5, 5, 1], dtype=np.float32)))
expected_out = np.array([[5, 5, 7, 5, 5], [5, 5, 7, 5, 5... |
'Tests if the correct output shapes are setup in transposed module.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testTransposition(self, use_bias):
| net = snt.Conv2D(name='conv2d', output_channels=4, kernel_shape=3, stride=1, use_bias=use_bias)
net_transpose = net.transpose()
input_to_net = tf.placeholder(tf.float32, shape=[None, 100, 100, 3])
err = 'Variables in {} not instantiated yet, __call__ the module first.'
wit... |
'2D Masks are applied properly.'
| def testMask2D(self):
| mask = np.array([[1, 1, 1], [1, 0, 0], [0, 0, 0]], dtype=np.float32)
inputs = tf.constant(1.0, shape=(1, 5, 5, 2))
conv1 = snt.Conv2D(output_channels=1, kernel_shape=3, mask=mask, padding=snt.VALID, use_bias=False, initializers=create_constant_initializers(1.0, 0.0, use_bias=False))
out = conv1(inputs)
... |
'4D Masks are applied properly.'
| def testMask4D(self):
| mask = np.ones([3, 3, 2, 1], dtype=np.float32)
mask[0, 0, 0, :] = 0
inputs = tf.constant(1.0, shape=(1, 5, 5, 2))
conv1 = snt.Conv2D(output_channels=1, kernel_shape=3, mask=mask, padding=snt.VALID, use_bias=False, initializers=create_constant_initializers(1.0, 0.0, use_bias=False))
out = conv1(input... |
'Errors are thrown for invalid mask rank.'
| def testMaskErrorInvalidRank(self):
| mask = np.ones((3,))
with self.assertRaises(snt.Error) as cm:
snt.Conv2D(output_channels=4, kernel_shape=3, mask=mask)
self.assertEqual(str(cm.exception), 'Invalid mask rank: {}'.format(mask.ndim))
|
'Errors are thrown for invalid mask type.'
| def testMaskErrorInvalidType(self):
| mask = tf.constant(1.0, shape=(3, 3))
with self.assertRaises(TypeError) as cm:
snt.Conv2D(output_channels=4, kernel_shape=3, mask=mask)
self.assertEqual(str(cm.exception), 'Invalid type for mask: {}'.format(type(mask)))
|
'Errors are thrown for incompatible rank 2 mask.'
| def testMaskErrorIncompatibleRank2(self):
| mask = np.ones((3, 3))
x = tf.constant(0.0, shape=(2, 8, 8, 6))
with self.assertRaises(snt.Error) as cm:
snt.Conv2D(output_channels=4, kernel_shape=5, mask=mask)(x)
self.assertTrue(str(cm.exception).startswith('Invalid mask shape: {}'.format(mask.shape)))
|
'Errors are thrown for incompatible rank 4 mask.'
| def testMaskErrorIncompatibleRank4(self):
| mask = np.ones((3, 3, 4, 5))
x = tf.constant(0.0, shape=(2, 8, 8, 6))
with self.assertRaises(snt.Error) as cm:
snt.Conv2D(output_channels=4, kernel_shape=5, mask=mask)(x)
self.assertTrue(str(cm.exception).startswith('Invalid mask shape: {}'.format(mask.shape)))
|
'Set up some variables to re-use in multiple tests.'
| def setUp(self):
| super(Conv2DTransposeTest, self).setUp()
self.batch_size = 100
self.in_height = 32
self.in_width = 32
self.in_channels = 3
self.out_channels = 10
self.kernel_shape_h = 5
self.kernel_shape_w = 5
self.strides = (1, 1, 1, 1)
self.padding = snt.SAME
self.in_shape = (self.batch_si... |
'Tests error is raised if kernel shape is not specified.'
| def testKernelsNotSpecified(self):
| with self.assertRaisesRegexp(ValueError, '`kernel_shape` cannot be None.'):
snt.Conv2DTranspose(output_channels=1)
|
'Tests if output shapes are valid.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testOutputShapeConsistency(self, use_bias):
| inputs = tf.placeholder(tf.float32, shape=self.in_shape)
conv1 = snt.Conv2DTranspose(name='conv2d_1', output_channels=self.out_channels, output_shape=self.out_shape, kernel_shape=self.kernel_shape, padding=self.padding, stride=1, use_bias=use_bias)
outputs = conv1(inputs)
self.assertTrue(outputs.get_sha... |
'Tests if output shapes are valid when specified as an integer.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testOutputShapeInteger(self, use_bias):
| inputs = tf.zeros(shape=[3, 5, 5, 2], dtype=tf.float32)
inputs_2 = tf.zeros(shape=[3, 5, 7, 2], dtype=tf.float32)
conv1 = snt.Conv2DTranspose(name='conv2d_1', output_channels=10, output_shape=10, kernel_shape=5, padding=snt.SAME, stride=2, use_bias=use_bias)
outputs = conv1(inputs)
outputs_2 = conv1... |
'Tests if the correct output shapes are setup in transposed module.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testTransposition(self, use_bias):
| net = snt.Conv2DTranspose(name='conv2d', output_channels=self.out_channels, output_shape=self.out_shape, kernel_shape=self.kernel_shape, padding=self.padding, stride=1, use_bias=use_bias)
net_transpose = net.transpose()
input_to_net = tf.placeholder(tf.float32, shape=self.in_shape)
err = 'Variables i... |
'Test that initializers are not mutated.'
| def testInitializerMutation(self):
| initializers = {'b': tf.constant_initializer(0)}
initializers_copy = dict(initializers)
conv1 = snt.Conv2DTranspose(output_shape=(10, 10), output_channels=1, kernel_shape=3, stride=1, name='conv2d', initializers=initializers)
conv1(tf.placeholder(tf.float32, [1, 10, 10, 2]))
self.assertAllEqual(init... |
'The generated shapes are correct with SAME and VALID padding.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testShapes(self, use_bias):
| batch_size = random.randint(1, 100)
in_length = random.randint(10, 288)
in_channels = random.randint(1, 10)
out_channels = random.randint(1, 32)
kernel_shape = random.randint(1, 10)
inputs = tf.placeholder(tf.float32, shape=[batch_size, in_length, in_channels])
conv1 = snt.Conv1D(output_chan... |
'The generated shapes are correct when input shape not known.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testShapesNotKnown(self, use_bias):
| batch_size = 5
in_length = 32
in_channels = out_channels = 5
kernel_shape = 3
inputs = tf.placeholder(tf.float32, shape=[None, None, in_channels], name='inputs')
conv1 = snt.Conv1D(name='conv1', output_channels=out_channels, kernel_shape=kernel_shape, padding=snt.SAME, stride=1, use_bias=use_bia... |
'Errors are thrown for invalid kernel shapes.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testKernelShape(self, use_bias):
| snt.Conv1D(output_channels=10, kernel_shape=[3], name='conv1', use_bias=use_bias)
snt.Conv1D(output_channels=10, kernel_shape=3, name='conv1', use_bias=use_bias)
err = 'Invalid kernel shape'
with self.assertRaisesRegexp(snt.IncompatibleShapeError, err):
snt.Conv1D(output_channels=10, kerne... |
'Errors are thrown for invalid strides.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testStrideError(self, use_bias):
| snt.Conv1D(output_channels=10, kernel_shape=3, stride=1, name='conv1', use_bias=use_bias)
err = 'Invalid stride'
with self.assertRaisesRegexp(snt.IncompatibleShapeError, err):
snt.Conv1D(output_channels=10, kernel_shape=3, stride=[1, 1], name='conv1')
with self.assertRaisesRegexp(snt.Incompat... |
'Errors are thrown for invalid dilation rates.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testRateError(self, use_bias):
| snt.Conv1D(output_channels=10, kernel_shape=3, rate=1, name='conv1', use_bias=use_bias)
snt.Conv1D(output_channels=10, kernel_shape=3, rate=2, name='conv1', use_bias=use_bias)
for rate in [0, 0.5, (-1)]:
with self.assertRaisesRegexp(snt.IncompatibleShapeError, 'Invalid rate shape*'):
... |
'Errors are thrown for stride > 1 when using atrous convolution.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testRateAndStrideError(self, use_bias):
| err = 'Cannot have stride > 1 with rate > 1'
with self.assertRaisesRegexp(snt.NotSupportedError, err):
snt.Conv1D(output_channels=10, kernel_shape=3, stride=2, rate=2, name='conv1', use_bias=use_bias)
|
'Errors are thrown for invalid input types.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testInputTypeError(self, use_bias):
| conv1 = snt.Conv1D(output_channels=1, kernel_shape=3, stride=1, padding=snt.VALID, use_bias=use_bias, name='conv1', initializers=create_constant_initializers(1.0, 1.0, use_bias))
for dtype in (tf.float16, tf.float64):
x = tf.constant(np.ones([1, 5, 1]), dtype=dtype)
err = 'Input must have ... |
'Test initializers work as expected.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testInitializers(self, use_bias):
| w = random.random()
b = random.random()
conv1 = snt.Conv1D(output_channels=1, kernel_shape=3, stride=1, padding=snt.SAME, use_bias=use_bias, name='conv1', initializers=create_constant_initializers(w, b, use_bias))
conv1(tf.placeholder(tf.float32, [1, 10, 2]))
with self.test_session():
tf.var... |
'Test that initializers are not mutated.'
| def testInitializerMutation(self):
| initializers = {'b': tf.constant_initializer(0)}
initializers_copy = dict(initializers)
conv1 = snt.Conv1D(output_channels=1, kernel_shape=3, stride=1, name='conv1', initializers=initializers)
conv1(tf.placeholder(tf.float32, [1, 10, 2]))
self.assertAllEqual(initializers, initializers_copy)
|
'Run through for something with a known answer using SAME padding.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testComputationSame(self, use_bias):
| conv1 = snt.Conv1D(output_channels=1, kernel_shape=3, stride=1, padding=snt.SAME, use_bias=use_bias, name='conv1', initializers=create_constant_initializers(1.0, 1.0, use_bias))
out = conv1(tf.constant(np.ones([1, 5, 1], dtype=np.float32)))
expected_out = np.asarray([3, 4, 4, 4, 3])
if (not use_bias):
... |
'Run through for something with a known answer using snt.VALID padding.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testComputationValid(self, use_bias):
| conv1 = snt.Conv1D(output_channels=1, kernel_shape=3, stride=1, padding=snt.VALID, use_bias=use_bias, name='conv1', initializers=create_constant_initializers(1.0, 1.0, use_bias))
out = conv1(tf.constant(np.ones([1, 5, 1], dtype=np.float32)))
expected_out = np.asarray([4, 4, 4])
if (not use_bias):
... |
'Sharing is working.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testSharing(self, use_bias):
| conv1 = snt.Conv1D(output_channels=1, kernel_shape=3, stride=1, padding=snt.SAME, use_bias=use_bias, name='conv1')
x = np.random.randn(1, 5, 1)
x1 = tf.constant(x, dtype=np.float32)
x2 = tf.constant(x, dtype=np.float32)
out1 = conv1(x1)
out2 = conv1(x2)
with self.test_session():
tf.v... |
'Tests error is raised if kernel shape is not specified.'
| def testKernelsNotSpecified(self):
| with self.assertRaisesRegexp(ValueError, '`kernel_shape` cannot be None.'):
snt.Conv1DTranspose(output_channels=1)
|
'Check functionality with unknown batch size at build time.'
| @parameterized.Parameters(*zip(out_channels, kernel_shape, padding, use_bias, in_shape, out_shape, stride_shape))
def testMissingBatchSize(self, out_channels, kernel_shape, padding, use_bias, in_shape, out_shape, stride_shape):
| conv1 = snt.Conv1DTranspose(output_channels=out_channels, output_shape=out_shape, kernel_shape=kernel_shape, padding=padding, stride=stride_shape, name='conv1', use_bias=use_bias)
image = tf.placeholder(tf.float32, shape=((None,) + in_shape[1:]))
output = conv1(image)
self.assertTrue(output.get_shape().... |
'The generated shapes are correct.'
| @parameterized.Parameters(*zip(batch_size, in_length, in_channels, out_length, out_channels, kernel_shape, padding, use_bias, in_shape, out_shape, stride_shape))
def testShapesSame(self, batch_size, in_length, in_channels, out_length, out_channels, kernel_shape, padding, use_bias, in_shape, out_shape, stride_shape):
| inputs = tf.placeholder(tf.float32, shape=[batch_size, in_length, in_channels])
conv1 = snt.Conv1DTranspose(output_channels=out_channels, output_shape=out_shape, kernel_shape=kernel_shape, padding=padding, stride=stride_shape, name='conv1', use_bias=use_bias)
output = conv1(inputs)
self.assertTrue(outpu... |
'Errors are thrown for invalid kernel shapes.'
| @parameterized.Parameters(*zip(out_channels, padding, use_bias, in_shape, out_shape, stride_shape))
def testKernelShape(self, out_channels, padding, use_bias, in_shape, out_shape, stride_shape):
| snt.Conv1DTranspose(output_channels=out_channels, output_shape=out_shape, kernel_shape=[3], padding=padding, stride=stride_shape, name='conv1', use_bias=use_bias)
snt.Conv1DTranspose(output_channels=out_channels, output_shape=out_shape, kernel_shape=3, padding=padding, stride=stride_shape, name='conv1', use_bia... |
'Errors are thrown for invalid strides.'
| @parameterized.Parameters(*zip(out_channels, padding, use_bias, in_shape, out_shape))
def testStrideError(self, out_channels, padding, use_bias, in_shape, out_shape):
| snt.Conv1DTranspose(output_channels=out_channels, output_shape=out_shape, kernel_shape=3, padding=padding, stride=1, name='conv1', use_bias=use_bias)
err = 'must be either a positive integer or an iterable of positive integers of size 1'
with self.assertRaisesRegexp... |
'Errors are thrown for invalid input types.'
| @parameterized.Parameters(*zip(batch_size, in_length, in_channels, out_channels, kernel_shape, padding, use_bias, out_shape, stride_shape))
def testInputTypeError(self, batch_size, in_length, in_channels, out_channels, kernel_shape, padding, use_bias, out_shape, stride_shape):
| conv1 = snt.Conv1DTranspose(output_channels=out_channels, output_shape=out_shape, kernel_shape=kernel_shape, padding=padding, stride=stride_shape, name='conv1', use_bias=use_bias)
for dtype in (tf.float16, tf.float64):
x = tf.constant(np.ones([batch_size, in_length, in_channels]), dtype=dtype)
e... |
'Sharing is working.'
| @parameterized.Parameters(*zip(batch_size, in_length, in_channels, out_channels, kernel_shape, padding, use_bias, out_shape, stride_shape))
def testSharing(self, batch_size, in_length, in_channels, out_channels, kernel_shape, padding, use_bias, out_shape, stride_shape):
| conv1 = snt.Conv1DTranspose(output_channels=out_channels, output_shape=out_shape, kernel_shape=kernel_shape, padding=padding, stride=stride_shape, name='conv1', use_bias=use_bias)
x = np.random.randn(batch_size, in_length, in_channels)
x1 = tf.constant(x, dtype=np.float32)
x2 = tf.constant(x, dtype=np.f... |
'Test transpose.'
| @parameterized.Parameters(*zip(batch_size, in_length, in_channels, out_channels, kernel_shape, padding, use_bias, out_shape, stride_shape))
def testTranspose(self, batch_size, in_length, in_channels, out_channels, kernel_shape, padding, use_bias, out_shape, stride_shape):
| conv1_transpose = snt.Conv1DTranspose(output_channels=out_channels, output_shape=out_shape, kernel_shape=kernel_shape, padding=padding, stride=stride_shape, name='conv1_transpose', use_bias=use_bias)
conv1 = conv1_transpose.transpose()
self.assertEqual(conv1_transpose.kernel_shape, conv1.kernel_shape)
s... |
'Test that initializers are not mutated.'
| def testInitializerMutation(self):
| initializers = {'b': tf.constant_initializer(0)}
initializers_copy = dict(initializers)
conv1 = snt.Conv1DTranspose(output_shape=(10,), output_channels=1, kernel_shape=3, stride=1, name='conv1', initializers=initializers)
conv1(tf.placeholder(tf.float32, [1, 10, 2]))
self.assertAllEqual(initializers... |
'Run through for something with a known answer.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testComputation(self, use_bias):
| conv1 = snt.CausalConv1D(output_channels=1, kernel_shape=3, stride=1, use_bias=use_bias, name='conv1', initializers=create_constant_initializers(1.0, 1.0, use_bias))
out = conv1(tf.constant(np.ones([1, 5, 1], dtype=np.float32)))
expected_out = np.reshape(np.array([1, 2, 3, 3, 3]), [1, 5, 1])
if use_bias... |
'Run through for something with a known answer.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testComputationStrided(self, use_bias):
| conv1 = snt.CausalConv1D(output_channels=1, kernel_shape=3, stride=2, use_bias=use_bias, name='conv1', initializers=create_constant_initializers(1.0, 1.0, use_bias))
out = conv1(tf.constant(np.ones([1, 5, 1], dtype=np.float32)))
expected_out = np.reshape(np.array([1, 3, 3]), [1, 3, 1])
if use_bias:
... |
'Run through for something with a known answer.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testComputationDilated(self, use_bias):
| conv1 = snt.CausalConv1D(output_channels=1, kernel_shape=3, stride=1, rate=2, use_bias=use_bias, name='conv1', initializers=create_constant_initializers(1.0, 1.0, use_bias))
out = conv1(tf.constant(np.ones([1, 5, 1], dtype=np.float32)))
expected_out = np.reshape(np.array([1, 1, 2, 2, 3]), [1, 5, 1])
if ... |
'Sharing is working.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testSharing(self, use_bias):
| conv1 = snt.CausalConv1D(output_channels=1, kernel_shape=3, stride=1, use_bias=use_bias, name='conv1')
x = np.random.randn(1, 5, 1)
x1 = tf.constant(x, dtype=np.float32)
x2 = tf.constant(x, dtype=np.float32)
out1 = conv1(x1)
out2 = conv1(x2)
w = np.random.randn(3, 1, 1)
weight_change_op ... |
'Test that the number of output and input channels are equal.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testSameNumberOfOutputAndInputChannels(self, use_bias):
| input_channels = random.randint(1, 32)
inputs = tf.placeholder(tf.float32, shape=[1, 10, 10, input_channels])
conv1 = snt.InPlaneConv2D(kernel_shape=3, use_bias=use_bias)
err = 'Variables in in_plane_conv2d not instantiated yet'
with self.assertRaisesRegexp(snt.NotConnectedError, err)... |
'Sharing is working.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testSharing(self, use_bias):
| conv1 = snt.InPlaneConv2D(kernel_shape=3, use_bias=use_bias)
x = np.random.randn(1, 5, 5, 1)
x1 = tf.constant(x, dtype=np.float32)
x2 = tf.constant(x, dtype=np.float32)
out1 = conv1(x1)
out2 = conv1(x2)
with self.test_session():
tf.variables_initializer(([conv1.w, conv1.b] if use_bia... |
'Test that initializers are not mutated.'
| def testInitializerMutation(self):
| initializers = {'b': tf.constant_initializer(0)}
initializers_copy = dict(initializers)
conv1 = snt.InPlaneConv2D(kernel_shape=3, initializers=initializers)
conv1(tf.placeholder(tf.float32, [1, 10, 10, 2]))
self.assertAllEqual(initializers, initializers_copy)
|
'Set up some variables to re-use in multiple tests.'
| def setUp(self):
| super(DepthwiseConv2DTest, self).setUp()
self.batch_size = batch_size = random.randint(1, 20)
self.in_height = in_height = random.randint(10, 128)
self.in_width = in_width = random.randint(10, 128)
self.in_channels = in_channels = random.randint(1, 10)
self.kernel_shape_h = kernel_shape_h = rand... |
'Test that the generated shapes are correct with SAME padding.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testShapesSame(self, use_bias):
| out_channels = self.out_channels
input_shape = self.input_shape
kernel_shape = self.kernel_shape
output_shape = self.output_shape
weight_shape = self.weight_shape
channel_multiplier = self.channel_multiplier
inputs = tf.placeholder(tf.float32, shape=input_shape)
conv1 = snt.DepthwiseConv... |
'Test that the generated shapes are correct when input shape not known.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testShapesNotKnown(self, use_bias):
| inputs = tf.placeholder(tf.float32, shape=[None, None, None, self.in_channels], name='inputs')
conv1 = snt.DepthwiseConv2D(channel_multiplier=self.channel_multiplier, kernel_shape=self.kernel_shape, padding=snt.SAME, stride=1, use_bias=use_bias)
output = conv1(inputs)
with self.test_session():
t... |
'Test that errors are thrown for invalid kernel shapes.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testKernelShape(self, use_bias):
| snt.DepthwiseConv2D(channel_multiplier=1, kernel_shape=[3, 4])
snt.DepthwiseConv2D(channel_multiplier=1, kernel_shape=3)
error_msg = 'Invalid kernel shape: x is \\[3], must be either a positive integer or an iterable of positive integers of size 2'... |
'Test that errors are thrown for invalid strides.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testStrideError(self, use_bias):
| snt.DepthwiseConv2D(channel_multiplier=1, kernel_shape=3, stride=1, use_bias=use_bias)
snt.DepthwiseConv2D(channel_multiplier=1, kernel_shape=3, stride=([1] * 2), use_bias=use_bias)
snt.DepthwiseConv2D(channel_multiplier=1, kernel_shape=3, stride=([1] * 4), use_bias=use_bias)
error_msg = 'stride is ... |
'Test that errors are thrown for invalid input types.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testInputTypeError(self, use_bias):
| conv1 = snt.DepthwiseConv2D(channel_multiplier=3, kernel_shape=3, stride=1, padding=snt.SAME, use_bias=use_bias, initializers=create_constant_initializers(1.0, 1.0, use_bias))
for dtype in (tf.float16, tf.float64):
x = tf.constant(np.ones([1, 5, 5, 1]), dtype=dtype)
err = 'Input must have ... |
'Test that initializers work as expected.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testInitializers(self, use_bias):
| w = random.random()
b = np.random.randn(6)
conv1 = snt.DepthwiseConv2D(channel_multiplier=3, kernel_shape=3, stride=1, use_bias=use_bias, initializers=create_constant_initializers(w, b, use_bias))
conv1(tf.placeholder(tf.float32, [1, 10, 10, 2]))
with self.test_session():
tf.variables_initia... |
'Test that initializers are not mutated.'
| def testInitializerMutation(self):
| initializers = {'b': tf.constant_initializer(0)}
initializers_copy = dict(initializers)
conv1 = snt.DepthwiseConv2D(channel_multiplier=3, kernel_shape=3, stride=1, initializers=initializers)
conv1(tf.placeholder(tf.float32, [10, 10, 1, 2]))
self.assertAllEqual(initializers, initializers_copy)
|
'Run through for something with a known answer using SAME padding.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testComputationSame(self, use_bias):
| conv1 = snt.DepthwiseConv2D(channel_multiplier=1, kernel_shape=[3, 3], stride=1, padding=snt.SAME, use_bias=use_bias, initializers=create_constant_initializers(1.0, 1.0, use_bias))
out = conv1(tf.constant(np.ones([1, 5, 5, 1], dtype=np.float32)))
expected_out = np.array([[5, 7, 7, 7, 5], [7, 10, 10, 10, 7],... |
'Run through for something with a known answer using snt.VALID padding.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testComputationValid(self, use_bias):
| conv1 = snt.DepthwiseConv2D(channel_multiplier=1, kernel_shape=[3, 3], stride=1, padding=snt.VALID, use_bias=use_bias, initializers=create_constant_initializers(1.0, 1.0, use_bias))
out = conv1(tf.constant(np.ones([1, 5, 5, 1], dtype=np.float32)))
expected_out = np.array([[10, 10, 10], [10, 10, 10], [10, 10... |
'Run through for something with a known answer using snt.VALID padding.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testComputationValidMultiChannel(self, use_bias):
| conv1 = snt.DepthwiseConv2D(channel_multiplier=1, kernel_shape=[3, 3], stride=1, padding=snt.VALID, use_bias=use_bias, initializers=create_constant_initializers(1.0, 1.0, use_bias))
out = conv1(tf.constant(np.ones([1, 5, 5, 3], dtype=np.float32)))
expected_out = np.array(([([([10] * 3)] * 3)] * 3))
if (... |
'Sharing is working.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testSharing(self, use_bias):
| conv1 = snt.DepthwiseConv2D(channel_multiplier=3, kernel_shape=3, stride=1, padding=snt.SAME, use_bias=use_bias)
x = np.random.randn(1, 5, 5, 1)
x1 = tf.constant(x, dtype=np.float32)
x2 = tf.constant(x, dtype=np.float32)
out1 = conv1(x1)
out2 = conv1(x2)
with self.test_session():
tf.... |
'Set up some variables to re-use in multiple tests.'
| def setUp(self):
| super(SeparableConv2DTest, self).setUp()
self.batch_size = batch_size = random.randint(1, 100)
self.in_height = in_height = random.randint(10, 188)
self.in_width = in_width = random.randint(10, 188)
self.in_channels = in_channels = random.randint(1, 10)
self.input_shape = [batch_size, in_height,... |
'Test that the generated shapes are correct with SAME padding.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testShapesSame(self, use_bias):
| out_channels = self.out_channels_dw
input_shape = self.input_shape
kernel_shape = self.kernel_shape
output_shape = self.output_shape
depthwise_filter_shape = self.depthwise_filter_shape
pointwise_filter_shape = self.pointwise_filter_shape
channel_multiplier = self.channel_multiplier
inpu... |
'Test that the generated shapes are correct when input shape not known.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testShapesNotKnown(self, use_bias):
| inputs = tf.placeholder(tf.float32, shape=[None, None, None, self.in_channels], name='inputs')
conv1 = snt.SeparableConv2D(output_channels=self.out_channels_dw, channel_multiplier=1, kernel_shape=self.kernel_shape, padding=snt.SAME, use_bias=use_bias)
output = conv1(inputs)
with self.test_session():
... |
'Test that errors are thrown for invalid kernel shapes.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testKernelShape(self, use_bias):
| snt.SeparableConv2D(output_channels=1, channel_multiplier=2, kernel_shape=[3, 4], name='conv1', use_bias=use_bias)
snt.SeparableConv2D(output_channels=1, channel_multiplier=1, kernel_shape=3, name='conv1')
error_msg = 'Invalid kernel shape: x is \\[3], must be either a positive... |
'Test that errors are thrown for invalid strides.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testStrideError(self, use_bias):
| snt.SeparableConv2D(output_channels=1, channel_multiplier=3, kernel_shape=3, stride=1, use_bias=use_bias)
snt.SeparableConv2D(output_channels=1, channel_multiplier=3, kernel_shape=3, stride=[1, 1], use_bias=use_bias)
snt.SeparableConv2D(output_channels=1, channel_multiplier=3, kernel_shape=3, stride=[1, 1, ... |
'Test that errors are thrown for invalid input types.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testInputTypeError(self, use_bias):
| conv1 = snt.SeparableConv2D(output_channels=3, channel_multiplier=1, kernel_shape=3, padding=snt.SAME, use_bias=use_bias, initializers=create_separable_constant_initializers(1.0, 1.0, 1.0, use_bias))
for dtype in (tf.float16, tf.float64):
x = tf.constant(np.ones([1, 5, 5, 1]), dtype=dtype)
err =... |
'Test that initializers work as expected.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testInitializers(self, use_bias):
| w_dw = random.random()
w_pw = random.random()
b = np.random.randn(6)
conv1 = snt.SeparableConv2D(output_channels=6, channel_multiplier=3, kernel_shape=3, use_bias=use_bias, initializers=create_separable_constant_initializers(w_dw, w_pw, b, use_bias))
conv1(tf.placeholder(tf.float32, [1, 10, 10, 2]))... |
'Test that initializers are not mutated.'
| def testInitializerMutation(self):
| initializers = {'b': tf.constant_initializer(0)}
initializers_copy = dict(initializers)
conv1 = snt.SeparableConv2D(output_channels=3, channel_multiplier=1, kernel_shape=3, stride=1, initializers=initializers)
conv1(tf.placeholder(tf.float32, [10, 10, 1, 2]))
self.assertAllEqual(initializers, initia... |
'Run through for something with a known answer using SAME padding.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testComputationSame(self, use_bias):
| conv1 = snt.SeparableConv2D(output_channels=1, channel_multiplier=1, kernel_shape=[3, 3], padding=snt.SAME, name='conv1', use_bias=use_bias, initializers=create_separable_constant_initializers(1.0, 1.0, 1.0, use_bias))
out = conv1(tf.constant(np.ones([1, 5, 5, 1], dtype=np.float32)))
expected_out = np.array... |
'Run through for something with a known answer using snt.VALID padding.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testComputationValid(self, use_bias):
| conv1 = snt.SeparableConv2D(output_channels=1, channel_multiplier=1, kernel_shape=[3, 3], padding=snt.VALID, use_bias=use_bias, initializers=create_separable_constant_initializers(1.0, 1.0, 1.0, use_bias))
out = conv1(tf.constant(np.ones([1, 5, 5, 1], dtype=np.float32)))
expected_out = np.array([[10, 10, 10... |
'Run through for something with a known answer using snt.VALID padding.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testComputationValidMultiChannel(self, use_bias):
| conv1 = snt.SeparableConv2D(output_channels=3, channel_multiplier=1, kernel_shape=[3, 3], padding=snt.VALID, use_bias=use_bias, initializers=create_separable_constant_initializers(1.0, 1.0, 1.0, use_bias))
out = conv1(tf.constant(np.ones([1, 5, 5, 3], dtype=np.float32)))
expected_out = np.array(([([([28] * ... |
'Run through for something with a known answer using snt.VALID padding.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testComputationValidChannelMultiplier(self, use_bias):
| input_channels = 3
channel_multiplier = 5
output_channels = (input_channels * channel_multiplier)
conv1 = snt.SeparableConv2D(output_channels=output_channels, channel_multiplier=channel_multiplier, kernel_shape=[3, 3], padding=snt.VALID, use_bias=use_bias, initializers=create_separable_constant_initiali... |
'Sharing is working.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testSharing(self, use_bias):
| conv1 = snt.SeparableConv2D(output_channels=3, channel_multiplier=3, kernel_shape=3, use_bias=use_bias)
x = np.random.randn(1, 5, 5, 1)
x1 = tf.constant(x, dtype=np.float32)
x2 = tf.constant(x, dtype=np.float32)
out1 = conv1(x1)
out2 = conv1(x2)
with self.test_session():
tf.variables... |
'The generated shapes are correct with SAME padding.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testShapesSame(self, use_bias):
| batch_size = random.randint(1, 100)
in_depth = random.randint(10, 288)
in_height = random.randint(10, 288)
in_width = random.randint(10, 288)
in_channels = random.randint(1, 10)
out_channels = random.randint(1, 32)
kernel_shape_d = random.randint(1, 11)
kernel_shape_h = random.randint(1,... |
'The generated shapes are correct when input shape not known.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testShapesWithUnknownInputShape(self, use_bias):
| batch_size = 5
in_depth = in_height = in_width = 32
in_channels = out_channels = 5
kernel_shape_d = kernel_shape_h = kernel_shape_w = 3
inputs = tf.placeholder(tf.float32, shape=[None, None, None, None, in_channels], name='inputs')
conv1 = snt.Conv3D(name='conv1', output_channels=out_channels, k... |
'Errors are thrown for invalid kernel shapes.'
| def testKernelShape(self):
| snt.Conv3D(output_channels=10, kernel_shape=[3, 4, 5], name='conv1')
snt.Conv3D(output_channels=10, kernel_shape=3, name='conv1')
with self.assertRaisesRegexp(snt.Error, 'Invalid kernel shape.*'):
snt.Conv3D(output_channels=10, kernel_shape=[3, 3], name='conv1')
snt.Conv3D(output_chann... |
'Errors are thrown for invalid strides.'
| def testStrideError(self):
| snt.Conv3D(output_channels=10, kernel_shape=3, stride=1, name='conv1')
snt.Conv3D(output_channels=10, kernel_shape=3, stride=[1, 1, 1], name='conv1')
snt.Conv3D(output_channels=10, kernel_shape=3, stride=[1, 1, 1, 1, 1], name='conv1')
with self.assertRaisesRegexp(snt.Error, 'Invalid stride.*'):
... |
'Errors are thrown for invalid dilation rates.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testRateError(self, use_bias):
| snt.Conv3D(output_channels=10, kernel_shape=3, rate=1, name='conv1', use_bias=use_bias)
snt.Conv3D(output_channels=10, kernel_shape=3, rate=2, name='conv1', use_bias=use_bias)
for rate in [0, 0.5, (-1)]:
with self.assertRaisesRegexp(snt.IncompatibleShapeError, 'Invalid rate shape*'):
... |
'Errors are thrown for stride > 1 when using atrous convolution.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testRateAndStrideError(self, use_bias):
| err = 'Cannot have stride > 1 with rate > 1'
with self.assertRaisesRegexp(snt.NotSupportedError, err):
snt.Conv3D(output_channels=10, kernel_shape=3, stride=2, rate=2, name='conv1', use_bias=use_bias)
with self.assertRaisesRegexp(snt.NotSupportedError, err):
snt.Conv3... |
'Errors are thrown for invalid input types.'
| def testInputTypeError(self):
| conv1 = snt.Conv3D(output_channels=1, kernel_shape=3, stride=1, padding=snt.SAME, name='conv1', initializers={'w': tf.constant_initializer(1.0), 'b': tf.constant_initializer(1.0)})
for dtype in (tf.float16, tf.float64):
x = tf.constant(np.ones([1, 5, 5, 5, 1]), dtype=dtype)
self.assertRaisesRege... |
'Test initializers work as expected.'
| @parameterized.NamedParameters(('WithBias', True), ('WithoutBias', False))
def testInitializers(self, use_bias):
| w = random.random()
b = random.random()
conv1 = snt.Conv3D(output_channels=1, kernel_shape=3, stride=1, name='conv1', use_bias=use_bias, initializers=create_constant_initializers(w, b, use_bias))
conv1(tf.placeholder(tf.float32, [1, 10, 10, 10, 2]))
with self.test_session():
tf.variables_ini... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.