/
usr
/
local
/
lib64
/
python3.6
/
site-packages
/
caffe2
/
python
/
ideep
/
/usr/local/lib64/python3.6/site-packages/caffe2/python/ideep
mkdir
upload
Name
Size
Mode
Actions
__pycache__/
-
0755
rm
adam_op_test.py
3212
0644
edit
dl
rm
blobs_queue_db_test.py
4045
0644
edit
dl
rm
channel_shuffle_op_test.py
1286
0644
edit
dl
rm
concat_split_op_test.py
5532
0644
edit
dl
rm
convfusion_op_test.py
31919
0644
edit
dl
rm
conv_op_test.py
5666
0644
edit
dl
rm
conv_transpose_test.py
2595
0644
edit
dl
rm
copy_op_test.py
3074
0644
edit
dl
rm
dropout_op_test.py
2075
0644
edit
dl
rm
elementwise_sum_op_test.py
6317
0644
edit
dl
rm
expanddims_squeeze_op_test.py
4285
0644
edit
dl
rm
fc_op_test.py
11745
0644
edit
dl
rm
leaky_relu_op_test.py
2854
0644
edit
dl
rm
LRN_op_test.py
1195
0644
edit
dl
rm
moment_sgd_op_test.py
1777
0644
edit
dl
rm
operator_fallback_op_test.py
3450
0644
edit
dl
rm
order_switch_op_test.py
2299
0644
edit
dl
rm
pool_op_test.py
4296
0644
edit
dl
rm
pre_convert_test.py
4115
0644
edit
dl
rm
relu_op_test.py
3705
0644
edit
dl
rm
reshape_op_test.py
5919
0644
edit
dl
rm
shape_op_test.py
2631
0644
edit
dl
rm
sigmoid_op_test.py
775
0644
edit
dl
rm
softmax_op_test.py
932
0644
edit
dl
rm
spatial_bn_op_test.py
5237
0644
edit
dl
rm
test_ideep_net.py
4094
0644
edit
dl
rm
transform_ideep_net.py
11683
0644
edit
dl
rm
transpose_op_test.py
1284
0644
edit
dl
rm
weightedsum_op_test.py
1560
0644
edit
dl
rm
__init__.py
0
0644
edit
dl
rm
Edit:
/usr/local/lib64/python3.6/site-packages/caffe2/python/ideep/spatial_bn_op_test.py
(5237B)
from hypothesis import given, settings import hypothesis.strategies as st import numpy as np import unittest from caffe2.python import core, workspace import caffe2.python.hypothesis_test_util as hu import caffe2.python.ideep_test_util as mu @unittest.skipIf(not workspace.C.use_mkldnn, "No MKLDNN support.") class TestSpatialBN(hu.HypothesisTestCase): @given(size=st.integers(7, 10), input_channels=st.integers(7, 10), batch_size=st.integers(1, 3), seed=st.integers(0, 65535), order=st.sampled_from(["NCHW"]), epsilon=st.floats(min_value=1e-5, max_value=1e-2), inplace=st.sampled_from([True, False]), **mu.gcs) @settings(deadline=1000) def test_spatialbn_test_mode( self, size, input_channels, batch_size, seed, order, epsilon, inplace, gc, dc): op = core.CreateOperator( "SpatialBN", ["X", "scale", "bias", "mean", "var"], ["X" if inplace else "Y"], order=order, is_test=True, epsilon=epsilon ) def reference_spatialbn_test(X, scale, bias, mean, var): if order == "NCHW": scale = scale[np.newaxis, :, np.newaxis, np.newaxis] bias = bias[np.newaxis, :, np.newaxis, np.newaxis] mean = mean[np.newaxis, :, np.newaxis, np.newaxis] var = var[np.newaxis, :, np.newaxis, np.newaxis] return ((X - mean) / np.sqrt(var + epsilon) * scale + bias,) np.random.seed(1701) scale = np.random.rand(input_channels).astype(np.float32) + 0.5 bias = np.random.rand(input_channels).astype(np.float32) - 0.5 mean = np.random.randn(input_channels).astype(np.float32) var = np.random.rand(input_channels).astype(np.float32) + 0.5 X = np.random.rand( batch_size, input_channels, size, size).astype(np.float32) - 0.5 if order == "NHWC": X = X.swapaxes(1, 2).swapaxes(2, 3) self.assertDeviceChecks(dc, op, [X, scale, bias, mean, var], [0]) @given(size=st.integers(7, 10), input_channels=st.integers(7, 10), batch_size=st.integers(1, 3), seed=st.integers(0, 65535), order=st.sampled_from(["NCHW"]), epsilon=st.floats(1e-5, 1e-2), inplace=st.sampled_from([True, False]), **mu.gcs) def test_spatialbn_train_mode( self, size, input_channels, batch_size, seed, order, epsilon, inplace, gc, dc): print("dc0: {}, dc1: {}".format(dc[0], dc[1])) op = core.CreateOperator( "SpatialBN", ["X", "scale", "bias", "running_mean", "running_var"], ["X" if inplace else "Y", "running_mean", "running_var", "saved_mean", "saved_var"], order=order, is_test=False, epsilon=epsilon, ) np.random.seed(1701) scale = np.random.rand(input_channels).astype(np.float32) + 0.5 bias = np.random.rand(input_channels).astype(np.float32) - 0.5 running_mean = np.random.randn(input_channels).astype(np.float32) running_var = np.random.rand(input_channels).astype(np.float32) + 0.5 X = np.random.rand( batch_size, input_channels, size, size).astype(np.float32) - 0.5 if order == "NHWC": X = X.swapaxes(1, 2).swapaxes(2, 3) # TODO: It looks like IDEEP spatial_bn op outputs save_var (output[4]) # as the reciprocal of CPU op's output. Need to check back and add # output[4] for comparison self.assertDeviceChecks(dc, op, [X, scale, bias, running_mean, running_var], [0, 1, 2, 3]) @given(size=st.integers(7, 10), input_channels=st.integers(1, 10), batch_size=st.integers(1, 3), seed=st.integers(0, 65535), order=st.sampled_from(["NCHW"]), epsilon=st.floats(min_value=1e-5, max_value=1e-2), **mu.gcs) @settings(deadline=None, max_examples=50) def test_spatialbn_train_mode_gradient_check( self, size, input_channels, batch_size, seed, order, epsilon, gc, dc): op = core.CreateOperator( "SpatialBN", ["X", "scale", "bias", "mean", "var"], ["Y", "mean", "var", "saved_mean", "saved_var"], order=order, is_test=False, epsilon=epsilon, ) np.random.seed(seed) scale = np.random.rand(input_channels).astype(np.float32) + 0.5 bias = np.random.rand(input_channels).astype(np.float32) - 0.5 mean = np.random.randn(input_channels).astype(np.float32) var = np.random.rand(input_channels).astype(np.float32) + 0.5 X = np.random.rand( batch_size, input_channels, size, size).astype(np.float32) - 0.5 if order == "NHWC": X = X.swapaxes(1, 2).swapaxes(2, 3) for input_to_check in [0, 1, 2]: # dX, dScale, dBias self.assertGradientChecks(gc, op, [X, scale, bias, mean, var], input_to_check, [0]) if __name__ == "__main__": unittest.main()
Save
cmd:
run