diff --git a/lab1/Part1_TensorFlow.ipynb b/lab1/Part1_TensorFlow.ipynb index e9e43b1f..55d80c67 100644 --- a/lab1/Part1_TensorFlow.ipynb +++ b/lab1/Part1_TensorFlow.ipynb @@ -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", diff --git a/mitdeeplearning/lab1.py b/mitdeeplearning/lab1.py index 19d448a3..9ff0b658 100644 --- a/mitdeeplearning/lab1.py +++ b/mitdeeplearning/lab1.py @@ -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