MCPcopy Index your code
hub / github.com/ddbourgin/numpy-ml / test_SkipConnectionIdentityModule

Function test_SkipConnectionIdentityModule

numpy_ml/tests/test_nn.py:1692–1819  ·  view source on GitHub ↗
(N=15)

Source from the content-addressed store, hash-verified

1690
1691
1692def test_SkipConnectionIdentityModule(N=15):
1693 from numpy_ml.neural_nets.modules import SkipConnectionIdentityModule
1694 from numpy_ml.neural_nets.activations import Tanh, ReLU, Sigmoid, Affine
1695
1696 N = np.inf if N is None else N
1697
1698 np.random.seed(12345)
1699
1700 acts = [
1701 (Tanh(), nn.Tanh(), "Tanh"),
1702 (Sigmoid(), nn.Sigmoid(), "Sigmoid"),
1703 (ReLU(), nn.ReLU(), "ReLU"),
1704 (Affine(), TorchLinearActivation(), "Affine"),
1705 ]
1706
1707 i = 1
1708 while i < N + 1:
1709 n_ex = np.random.randint(2, 10)
1710 in_rows = np.random.randint(2, 25)
1711 in_cols = np.random.randint(2, 25)
1712 n_in = np.random.randint(2, 5)
1713 n_out = n_in
1714 f_shape1 = (
1715 min(in_rows, np.random.randint(1, 5)),
1716 min(in_cols, np.random.randint(1, 5)),
1717 )
1718 f_shape2 = (
1719 min(in_rows, np.random.randint(1, 5)),
1720 min(in_cols, np.random.randint(1, 5)),
1721 )
1722 s1 = np.random.randint(1, 5)
1723 s2 = np.random.randint(1, 5)
1724
1725 # randomly select an activation function
1726 act_fn, torch_fn, act_fn_name = acts[np.random.randint(0, len(acts))]
1727
1728 X = random_tensor((n_ex, in_rows, in_cols, n_in), standardize=True)
1729
1730 p1 = calc_pad_dims_2D(X.shape, X.shape[1:3], f_shape1, s1)
1731 if p1[0] != p1[1] or p1[2] != p1[3]:
1732 continue
1733
1734 p2 = calc_pad_dims_2D(X.shape, X.shape[1:3], f_shape2, s2)
1735 if p2[0] != p2[1] or p2[2] != p2[3]:
1736 continue
1737
1738 p1 = (p1[0], p1[2])
1739 p2 = (p2[0], p2[2])
1740
1741 # initialize SkipConnectionIdentity module
1742 L1 = SkipConnectionIdentityModule(
1743 out_ch=n_out,
1744 kernel_shape1=f_shape1,
1745 kernel_shape2=f_shape2,
1746 stride1=s1,
1747 stride2=s2,
1748 act_fn=act_fn,
1749 epsilon=1e-5,

Callers

nothing calls this directly

Calls 13

forwardMethod · 0.95
backwardMethod · 0.95
extract_gradsMethod · 0.95
TanhClass · 0.90
SigmoidClass · 0.90
ReLUClass · 0.90
AffineClass · 0.90
random_tensorFunction · 0.90
calc_pad_dims_2DFunction · 0.90

Tested by

no test coverage detected