MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _RunAndVerify

Method _RunAndVerify

tensorflow/python/kernel_tests/lrn_op_test.py:57–94  ·  view source on GitHub ↗
(self, dtype)

Source from the content-addressed store, hash-verified

55 return output
56
57 def _RunAndVerify(self, dtype):
58 with self.cached_session(use_gpu=True):
59 # random shape
60 shape = np.random.randint(1, 16, size=4)
61 # Make depth at least 2 to make it meaningful
62 shape[3] += 1
63 p = array_ops.placeholder(dtype, shape=shape)
64 # random depth_radius, bias, alpha, beta. cuDNN requires depth_radius to
65 # be in [1, 7].
66 lrn_depth_radius = np.random.randint(1, min(8, shape[3]))
67
68 bias = 1.0 + np.random.rand()
69 alpha = 2.0 * np.random.rand()
70 # cuDNN requires beta >= 0.01.
71 beta = 0.01 + 2.0 * np.random.rand()
72 lrn_t = nn.local_response_normalization(
73 p,
74 name="lrn",
75 depth_radius=lrn_depth_radius,
76 bias=bias,
77 alpha=alpha,
78 beta=beta)
79 params = {p: np.random.rand(*shape).astype("f")}
80 result = lrn_t.eval(feed_dict=params)
81 expected = self._LRN(
82 params[p],
83 lrn_depth_radius=lrn_depth_radius,
84 bias=bias,
85 alpha=alpha,
86 beta=beta)
87 err = np.amax(np.abs(result - expected))
88 print("LRN error for bias ", bias, "alpha ", alpha, " beta ", beta, " is ",
89 err)
90 if dtype == dtypes.float32:
91 self.assertTrue(err < 1e-4)
92 else:
93 self.assertTrue(err < 1e-2)
94 self.assertShapeEqual(expected, lrn_t)
95
96 @test_util.run_deprecated_v1
97 def testCompute(self):

Callers 1

testComputeMethod · 0.95

Calls 7

_LRNMethod · 0.95
randMethod · 0.80
assertShapeEqualMethod · 0.80
minFunction · 0.50
cached_sessionMethod · 0.45
placeholderMethod · 0.45
evalMethod · 0.45

Tested by

no test coverage detected