2481069ed4
* chore: adding numpy backend * creview comments * review comments * chore: adding math * chore: adding random module * chore: adding ranndom in init * review comments * chore: adding numpy and nn for numpy backend * chore: adding generic pool, max, and average pool * chore: adding the conv ops * chore: reformat code and using jax for conv and pool * chore: added self value * chore: activation tests pass * chore: adding post build method * chore: adding necessaity methods to the numpy trainer * chore: fixing utils test * chore: fixing losses test suite * chore: fix backend tests * chore: fixing initializers test * chore: fixing accuracy metrics test * chore: fixing ops test * chore: review comments * chore: init with image and fixing random tests * chore: skipping random seed set for numpy backend * chore: adding single resize image method * chore: skipping tests for applications and layers * chore: skipping tests for models * chore: skipping testsor saving * chore: skipping tests for trainers * chore:ixing one hot * chore: fixing vmap in numpy and metrics test * chore: adding a wrapper to numpy sum, started fixing layer tests * fix: is_tensor now accepts numpy scalars * chore: adding draw seed * fix: warn message for numpy masking * fix: checking whether kernel are tensors * chore: adding rnn * chore: adding dynamic backend for numpy * fix: axis cannot be None for normalize * chore: adding jax resize for numpy image * chore: adding rnn implementation in numpy * chore: using pytest fixtures * change: numpy import string * chore: review comments * chore: adding numpy to backend list of github actions * chore: remove debug print statements
34 lines
1.0 KiB
Python
34 lines
1.0 KiB
Python
import numpy as np
|
|
import pytest
|
|
import tensorflow as tf
|
|
|
|
import keras_core
|
|
from keras_core import backend
|
|
from keras_core.testing import test_case
|
|
from keras_core.utils import rng_utils
|
|
|
|
|
|
class TestRandomSeedSetting(test_case.TestCase):
|
|
@pytest.mark.skipif(
|
|
backend.backend() == "numpy",
|
|
reason="Numpy backend does not support random seed setting.",
|
|
)
|
|
def test_set_random_seed(self):
|
|
def get_model_output():
|
|
model = keras_core.Sequential(
|
|
[
|
|
keras_core.layers.Dense(10),
|
|
keras_core.layers.Dropout(0.5),
|
|
keras_core.layers.Dense(10),
|
|
]
|
|
)
|
|
x = np.random.random((32, 10)).astype("float32")
|
|
ds = tf.data.Dataset.from_tensor_slices(x).shuffle(32).batch(16)
|
|
return model.predict(ds)
|
|
|
|
rng_utils.set_random_seed(42)
|
|
y1 = get_model_output()
|
|
rng_utils.set_random_seed(42)
|
|
y2 = get_model_output()
|
|
self.assertAllClose(y1, y2)
|