anon-iclr-submission/benchname-bug-localization huggingface dataset:
Repository: keras-team/keras
Issue: NASNet error using custom input shape without top layer

https://github.com/keras-team/keras/blob/07e13740fd181fc3ddec7d9a594d8a08666645f6/keras/applications/nasnet.py#L174-L180

Shouldn't the parameter `require_flatten` uses `include_top` value instead of constant `True`? 
Using `True` makes custom shaped input invalid when using size that isn't the `default_size` with `include_top = False`
Checked several other models such as efficientnet_v2 and xception, they all use `include_top` as value instead of `True`

Changed files:
keras/applications/applications_test.py, keras/applications/nasnet.py

diff --git a/keras/applications/applications_test.py b/keras/applications/applications_test.py
index 0f99cf07f3..9c2128b366 100644
--- a/keras/applications/applications_test.py
+++ b/keras/applications/applications_test.py
@@ -176,6 +176,16 @@ class ApplicationsTest(tf.test.TestCase, parameterized.TestCase):
             self.assertShapeEqual(output_shape, (None, None, None, last_dim))
         backend.clear_session()
 
+    @parameterized.parameters(*MODEL_LIST)
+    def test_application_notop_custom_input_shape(self, app, last_dim):
+        output_shape = _get_output_shape(
+            lambda: app(
+                weights="imagenet", include_top=False, input_shape=(224, 224, 3)
+            )
+        )
+
+        self.assertEqual(output_shape[-1], last_dim)
+
     @parameterized.parameters(MODEL_LIST)
     def test_application_pooling(self, app, last_dim):
         output_shape = _get_output_shape(
diff --git a/keras/applications/nasnet.py b/keras/applications/nasnet.py
index 99a6604ffd..58295c49a9 100644
--- a/keras/applications/nasnet.py
+++ b/keras/applications/nasnet.py
@@ -188,7 +188,7 @@ def NASNet(
         default_size=default_size,
         min_size=32,
         data_format=backend.image_data_format(),
-        require_flatten=True,
+        require_flatten=include_top,
         weights=weights,
     )
Repository: keras-team/keras
Issue: EfficentNets no longer train on non-float32 inputs

**System information**
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow): yes
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu 18.04
- TensorFlow installed from (source or binary): Pip `tf-nightly`
- TensorFlow version (use command below): 2.10.0-dev20220409
- Python version: 3.7.3
- GPU model and memory: N/A - reproducible on CPU, GPU, and TPU

**Describe the problem**.
[This PR](https://github.com/keras-team/keras/pull/16032/files) merged to solve [an issue with efficientnet normalisation](https://github.com/tensorflow/tensorflow/issues/49930) hardcoded a set of float values into the efficientnet architecture.

These magic numbers are fixed to float32 when running in graph mode, and will raise an exception as soon as the network is called on float16 or bfloat16 inputs. [bfloat16 inputs are recommended when training on TPUs](https://cloud.google.com/tpu/docs/bfloat16#improving_performance_with_bfloat16) 

**Describe the current behavior**.
An exception is raised whenever a keras efficientnet is trained on a non-float32 input

**Describe the expected behavior**.
An exception is not raised whenever a keras efficientnet is trained on a non-float32 input



- Do you want to contribute a PR? (yes/no): yes
- Briefly describe your candidate solution(if contributing):  Replace the hardcoded graph constants with:

`x = layers.Rescaling(1. / tf.math.sqrt(IMAGENET_STDDEV_RGB))(x)`

**Standalone code to reproduce the issue**.

```python
import tensorflow as tf
from tensorflow.keras.applications import efficientnet as efn

tf.keras.mixed_precision.set_global_policy("mixed_bfloat16")

ds = (
    tf.data.Dataset.from_tensor_slices(
        (
            tf.ones([1, 224, 224, 3], dtype=tf.bfloat16),
            tf.ones([1, 1000], dtype=tf.float32),
        )
    )
    .repeat()
    .batch(batch_size=1)
)

e = efn.EfficientNetB0()
e.compile(loss="binary_crossentropy")
e.fit(ds, steps_per_epoch=1, epochs=1)
```

Changed files:
keras/applications/efficientnet.py

diff --git a/keras/applications/efficientnet.py b/keras/applications/efficientnet.py
index d364f5698c..0a2b8fee3b 100644
--- a/keras/applications/efficientnet.py
+++ b/keras/applications/efficientnet.py
@@ -331,7 +331,7 @@ def EfficientNet(
     # normalize the input, we need to divide another sqrt(var) to match the
     # original implementation.
     # See https://github.com/tensorflow/tensorflow/issues/49930 for more details
-    x = x / tf.math.sqrt(IMAGENET_STDDEV_RGB)
+    x = layers.Rescaling(1. / tf.math.sqrt(IMAGENET_STDDEV_RGB))(x)
 
   x = layers.ZeroPadding2D(
       padding=imagenet_utils.correct_pad(x, 3),
Repository: keras-team/keras
Issue: Unexpected outputs from MaxPooling2D layer


**System information**.
- Have I written custom code (as opposed to using a stock example script provided in Keras): Yes
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Google Colab
- TensorFlow installed from (source or binary): pip install
- TensorFlow version (use command below): 2.8.0
- Python version: 3.7.12
- Bazel version (if compiling from source):
- GPU model and memory: using CPU
- Exact command to reproduce: 

```
input_shape = (10,10,32,256)
x = keras.layers.Input(input_shape[1:])
layer_stack = [
keras.layers.MaxPooling2D(pool_size=(2,2), padding="same", strides=(2,2)),
]
layer_input = x
for layer in layer_stack:
  y = layer(layer_input)
  layer_input = y

model = keras.Model(x,y)
model.summary()
import numpy as np
x = np.random.rand(*input_shape)
x[:] = np.NaN
res = model.predict(x)
```

**Describe the problem**.
MaxPooling2D layer does not give correct results for NaN inputs.

**Describe the current behavior**.
MaxPooling2D layer outputs a matrix of large negative values, i.e. `-3.4028235e+38` when a matrix of NaN is passed as inputs.

**Describe the expected behavior**.
Normally in max pooling, maximum value of patches of an input is output. And in the case of NaN matrix as inputs, outputs should be a matrix of NaN.

**[Contributing](https://github.com/keras-team/keras/blob/master/CONTRIBUTING.md)**.

- Do you want to contribute a PR? (yes/no): no
- If yes, please read [this page](https://github.com/keras-team/keras/blob/master/CONTRIBUTING.md) for instructions
- Briefly describe your candidate solution(if contributing):

**Standalone code to reproduce the issue**.


https://colab.research.google.com/drive/13SEcY5Lzj9fLQTv-JSNWA7cgnirNWnh6?usp=sharing#scrollTo=gZUgM5985nJs




Changed files:
keras/engine/training.py

diff --git a/keras/engine/training.py b/keras/engine/training.py
index 70b44fab78..7285a00336 100644
--- a/keras/engine/training.py
+++ b/keras/engine/training.py
@@ -1962,6 +1962,10 @@ class Model(base_layer.Layer, version_utils.ModelVersionSelector):
     """
     base_layer.keras_api_gauge.get_cell('predict').set(True)
     version_utils.disallow_legacy_graph('Model', 'predict')
+    if tf_utils.np.isnan(x).any() or tf_utils.np.isinf(x).any():
+      raise ValueError(
+          f'Unsupported input data format. Received: {tf_utils.np.sum(x)} in '
+          'input data. Was expecting a numeric data.')
     self._check_call_args('predict')
     _disallow_inside_tf_function('predict')
Repository: keras-team/keras
Issue: EfficientNetV2 does not match google implementation

Hi,
I may be wrong, but checking the efficientnetv2 implementation I think there is a difference with the [google one](https://github.com/google/automl/blob/387d5ddb92bb8fbbec4b012e5636a81ea65fffda/efficientnetv2/effnetv2_model.py)
The  ["survival_probability"](https://github.com/keras-team/keras/blob/d8fcb9d4d4dad45080ecfdd575483653028f8eda/keras/applications/efficientnet_v2.py#L990) is defined as `survival_probability=drop_connect_rate * b / blocks` but b is set to zero, while according to the [google implementation](https://github.com/google/automl/blob/387d5ddb92bb8fbbec4b012e5636a81ea65fffda/efficientnetv2/effnetv2_model.py#L619) it should increase with the "number" of the block.

I think that line should be replaced with:
`survival_probability=drop_connect_rate * i / blocks` 
where i is the counter of the for loop


Changed files:
keras/applications/efficientnet_v2.py

diff --git a/keras/applications/efficientnet_v2.py b/keras/applications/efficientnet_v2.py
index a329ed23e1..6a1b5be8d0 100644
--- a/keras/applications/efficientnet_v2.py
+++ b/keras/applications/efficientnet_v2.py
@@ -991,6 +991,7 @@ def EfficientNetV2(
           name="block{}{}_".format(i + 1, chr(j + 97)),
           **args,
       )(x)
+      b += 1
 
   # Build top
   top_filters = round_filters(
Repository: keras-team/keras
Issue: Some tests misusing assertTrue for comparisons

`assertTrue` is not for comparing arguments, should use `assertEqual` for that.

The developer's intent of the test was to compare argument 1 with argument 2, which is not happening. Really what is happening is the test is passing because first argument is truthy. The correct method to use is assertEqual. [more details](https://codereview.doctor/features/python/best-practice/avoid-misusing-unittest-assert-true)

https://github.com/keras-team/keras/blob/b96518a22bfd92a29811e507dec0b34248a8a3f5/keras/mixed_precision/loss_scale_optimizer_test.py#L1170

I found this issue automatically, see other issues [here](https://codereview.doctor/keras-team/keras)

Changed files:
keras/mixed_precision/loss_scale_optimizer_test.py

diff --git a/keras/mixed_precision/loss_scale_optimizer_test.py b/keras/mixed_precision/loss_scale_optimizer_test.py
index 2569c9a2d3..ef6853132b 100644
--- a/keras/mixed_precision/loss_scale_optimizer_test.py
+++ b/keras/mixed_precision/loss_scale_optimizer_test.py
@@ -1167,7 +1167,7 @@ class LossScaleOptimizerTest(tf.test.TestCase, parameterized.TestCase):
     self.assertEqual(self._eval_if_tensor(opt.inner_optimizer.momentum), 0.5)
     self.assertEqual(self.evaluate(opt.loss_scale), 2.)
     self.assertEqual(opt.dynamic_growth_steps, 3.)
-    self.assertTrue(opt.dynamic, 4.)
+    self.assertTrue(opt.dynamic)
     if lso_type in ('v1', 'v2'):
       # Deserializing a LossScaleOptimizerV1 results in a V2 LossScaleOptimizer.
       self.assertEqual(type(opt), loss_scale_optimizer.LossScaleOptimizer)
Repository: keras-team/keras
Issue: tf.keras.layers.Conv2D seems to accept 0 as the value of filters by mistake.

**System information**.
- Have I written custom code (as opposed to using a stock example script provided in Keras): No
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10
- TensorFlow installed from (source or binary): 2.7.0
- Python version: 3.8

Please refer to tensorflow/python/keras/layers/convolutional.py, lines 139-141:
```python
 if filters is not None and filters < 0:
      raise ValueError(f'Received a negative value for `filters`.'
                       f'Was expecting a positive value, got {filters}.')
```
The error message says that the filters expects a positive value. It seems that the validation code  should be "filters <= 0".

Changed files:
keras/layers/convolutional/base_conv.py

diff --git a/keras/layers/convolutional/base_conv.py b/keras/layers/convolutional/base_conv.py
index bcab3847d2..1782306415 100644
--- a/keras/layers/convolutional/base_conv.py
+++ b/keras/layers/convolutional/base_conv.py
@@ -118,9 +118,10 @@ class Conv(Layer):
 
     if isinstance(filters, float):
       filters = int(filters)
-    if filters is not None and filters < 0:
-      raise ValueError(f'Received a negative value for `filters`.'
-                       f'Was expecting a positive value. Received {filters}.')
+    if filters is not None and filters <= 0:
+      raise ValueError('Invalid value for argument `filters`. '
+                       'Expected a strictly positive value. '
+                       f'Received filters={filters}.')
     self.filters = filters
     self.groups = groups or 1
     self.kernel_size = conv_utils.normalize_tuple(