def test_regularizator(self): # make sure its the same as tensorflow x = np.array([-1., 2., 3., 4.]) reg = 0.2 l1_reg = tf.keras.regularizers.l1(l=reg) l2_reg = tf.keras.regularizers.l2(l=reg) tf_x = l1_reg(tf.convert_to_tensor(x)) tf_x_2 = l2_reg(tf.convert_to_tensor(x)) astroNN_x = l1(x, l1=reg) astroNN_x_2 = l2(x, l2=reg) npt.assert_array_almost_equal(tf_x.eval(session=get_session()), astroNN_x) npt.assert_array_almost_equal(tf_x_2.eval(session=get_session()), astroNN_x_2)
def test_regularizator(self): # make sure its the same as tensorflow x = np.array([-1., 2., 3., 4.]) reg = 0.2 astroNN_x = l1(x, l1=reg) astroNN_x_2 = l2(x, l2=reg) with tf.device("/cpu:0"), context.eager_mode(): l1_reg = tf.keras.regularizers.l1(l=reg) l2_reg = tf.keras.regularizers.l2(l=reg) tf_x = l1_reg(tf.convert_to_tensor(x)) tf_x_2 = l2_reg(tf.convert_to_tensor(x)) npt.assert_array_almost_equal(tf_x.numpy(), astroNN_x) npt.assert_array_almost_equal(tf_x_2.numpy(), astroNN_x_2)