diff --git a/keras_core/activations/activations.py b/keras_core/activations/activations.py index dbf23a56b..b24229876 100644 --- a/keras_core/activations/activations.py +++ b/keras_core/activations/activations.py @@ -416,6 +416,7 @@ def mish(x): - [Misra, 2019](https://arxiv.org/abs/1908.08681) """ + x = backend.convert_to_tensor(x) return Mish.static_call(x) diff --git a/keras_core/backend/torch/math.py b/keras_core/backend/torch/math.py index 9dd3aa872..dd4ccb2d1 100644 --- a/keras_core/backend/torch/math.py +++ b/keras_core/backend/torch/math.py @@ -58,7 +58,7 @@ def logsumexp(x, axis=None, keepdims=False): max_x = torch.max(x) return torch.log(torch.sum(torch.exp(x - max_x))) + max_x - max_x = torch.max(x, dim=axis, keepdim=True).values + max_x = torch.amax(x, dim=axis, keepdim=True) result = ( torch.log(torch.sum(torch.exp(x - max_x), dim=axis, keepdim=True)) + max_x diff --git a/keras_core/backend/torch/numpy.py b/keras_core/backend/torch/numpy.py index 8a12e13d7..9050964f9 100644 --- a/keras_core/backend/torch/numpy.py +++ b/keras_core/backend/torch/numpy.py @@ -134,6 +134,8 @@ def append( def arange(start, stop=None, step=1, dtype=None): dtype = to_torch_dtype(dtype) + if stop is None: + return torch.arange(end=start, dtype=dtype) return torch.arange(start, stop, step=step, dtype=dtype) diff --git a/keras_core/constraints/constraints_test.py b/keras_core/constraints/constraints_test.py index 28b55ebdd..9323446d1 100644 --- a/keras_core/constraints/constraints_test.py +++ b/keras_core/constraints/constraints_test.py @@ -1,5 +1,6 @@ import numpy as np +from keras_core import backend from keras_core import constraints from keras_core import testing @@ -35,12 +36,14 @@ class ConstraintsTest(testing.TestCase): def test_unit_norm(self): constraint_fn = constraints.UnitNorm() output = constraint_fn(get_example_array()) + output = backend.convert_to_numpy(output) l2 = np.sqrt(np.sum(np.square(output), axis=0)) self.assertAllClose(l2, 1.0) def test_min_max_norm(self): constraint_fn = constraints.MinMaxNorm(min_value=0.2, max_value=0.5) output = constraint_fn(get_example_array()) + output = backend.convert_to_numpy(output) l2 = np.sqrt(np.sum(np.square(output), axis=0)) self.assertFalse(l2[l2 < 0.2]) self.assertFalse(l2[l2 > 0.5 + 1e-6]) diff --git a/keras_core/layers/preprocessing/normalization_test.py b/keras_core/layers/preprocessing/normalization_test.py index 15bbdcf12..a72ed3472 100644 --- a/keras_core/layers/preprocessing/normalization_test.py +++ b/keras_core/layers/preprocessing/normalization_test.py @@ -68,6 +68,7 @@ class NormalizationTest(testing.TestCase, parameterized.TestCase): layer.adapt(data) self.assertTrue(layer.built) output = layer(x) + output = backend.convert_to_numpy(output) self.assertAllClose(np.var(output, axis=0), 1.0, atol=1e-5) self.assertAllClose(np.mean(output, axis=0), 0.0, atol=1e-5) @@ -84,6 +85,7 @@ class NormalizationTest(testing.TestCase, parameterized.TestCase): layer.adapt(data) self.assertTrue(layer.built) output = layer(x) + output = backend.convert_to_numpy(output) self.assertAllClose(np.var(output, axis=(0, 3)), 1.0, atol=1e-5) self.assertAllClose(np.mean(output, axis=(0, 3)), 0.0, atol=1e-5) diff --git a/keras_core/layers/preprocessing/random_brightness_test.py b/keras_core/layers/preprocessing/random_brightness_test.py index 9b28811f4..905195ce4 100644 --- a/keras_core/layers/preprocessing/random_brightness_test.py +++ b/keras_core/layers/preprocessing/random_brightness_test.py @@ -1,6 +1,7 @@ import numpy as np import tensorflow as tf +from keras_core import backend from keras_core import layers from keras_core import testing @@ -36,6 +37,7 @@ class RandomBrightnessTest(testing.TestCase): inputs = np.random.randint(0, 255, size=(224, 224, 3)) output = layer(inputs) diff = output - inputs + diff = backend.convert_to_numpy(diff) self.assertTrue(np.amin(diff) >= 0) self.assertTrue(np.mean(diff) > 0) @@ -45,6 +47,7 @@ class RandomBrightnessTest(testing.TestCase): inputs = np.random.randint(0, 255, size=(224, 224, 3)) output = layer(inputs) diff = output - inputs + diff = backend.convert_to_numpy(diff) self.assertTrue(np.amax(diff) <= 0) self.assertTrue(np.mean(diff) < 0) diff --git a/keras_core/operations/operation_test.py b/keras_core/operations/operation_test.py index 11920c338..73e438e7a 100644 --- a/keras_core/operations/operation_test.py +++ b/keras_core/operations/operation_test.py @@ -9,7 +9,8 @@ from keras_core.operations import operation class OpWithMultipleInputs(operation.Operation): def call(self, x, y, z=None): - return x + 2 * y + 3 * z + return 3 * z + x + 2 * y + # Order of operations issue with torch backend def compute_output_spec(self, x, y, z=None): return keras_tensor.KerasTensor(x.shape, x.dtype)