Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lab1 dense layer output assertion #118

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lab1/Part1_TensorFlow.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,11 @@
" y = # TODO\n",
" return y\n",
"\n",
"# Since layer parameters are initialized randomly, we will set a random seed for reproducibility\n",
"tf.random.set_seed(1)\n",
"# Since layer parameters are initialized randomly, we will set random seed for reproducibility \n",
"# and make operations deterministic\n",
"tf.keras.utils.set_random_seed(1)\n",
"tf.config.experimental.enable_op_determinism()\n",
"\n",
"layer = OurDenseLayer(3)\n",
"layer.build((1,2))\n",
"x_input = tf.constant([[1,2.]], shape=(1,2))\n",
Expand Down
4 changes: 2 additions & 2 deletions mitdeeplearning/lab1.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def test_batch_func_next_step(func, args):
return True

def test_custom_dense_layer_output(y):
true_y = np.array([[0.2697859, 0.45750418, 0.66536945]],dtype='float32')
true_y = np.array([[0.27064407, 0.1826951, 0.50374055]],dtype='float32')
assert tf.shape(y).numpy().tolist() == list(true_y.shape), "[FAIL] output is of incorrect shape. expected {} but got {}".format(true_y.shape, y.numpy().shape)
np.testing.assert_almost_equal(y.numpy(), true_y, decimal=7, err_msg="[FAIL] output is of incorrect value. expected {} but got {}".format(y.numpy(), true_y), verbose=True)
np.testing.assert_almost_equal(y.numpy(), true_y, decimal=7, err_msg="[FAIL] output is of incorrect value. expected {} but got {}".format(true_y,y.numpy()), verbose=True)
print("[PASS] test_custom_dense_layer_output")
return True