From 065c8887d33a734e1aea676f1a48dac18ed4fefd Mon Sep 17 00:00:00 2001 From: Pierre Bonami Date: Wed, 4 Dec 2024 18:37:59 +0100 Subject: [PATCH] That was what was needed for softmax in keras --- notebooks/adversarial/adversarial_keras.ipynb | 4 ++-- src/gurobi_ml/keras/keras.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/notebooks/adversarial/adversarial_keras.ipynb b/notebooks/adversarial/adversarial_keras.ipynb index 9eeb629f..d6d1dbb0 100644 --- a/notebooks/adversarial/adversarial_keras.ipynb +++ b/notebooks/adversarial/adversarial_keras.ipynb @@ -91,7 +91,7 @@ " tf.keras.layers.InputLayer((28 * 28,)),\n", " tf.keras.layers.Dense(50, activation=\"relu\"),\n", " tf.keras.layers.Dense(50, activation=\"relu\"),\n", - " tf.keras.layers.Dense(10),\n", + " tf.keras.layers.Dense(10, activation=\"softmax\"),\n", " ]\n", ")" ] @@ -257,7 +257,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.11.10" }, "license": { "full_text": "# Copyright © 2023 Gurobi Optimization, LLC\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n# ==============================================================================" diff --git a/src/gurobi_ml/keras/keras.py b/src/gurobi_ml/keras/keras.py index a132b6d2..9dc8c518 100644 --- a/src/gurobi_ml/keras/keras.py +++ b/src/gurobi_ml/keras/keras.py @@ -77,7 +77,7 @@ def __init__(self, gp_model, predictor, input_vars, output_vars=None, **kwargs): if isinstance(step, keras.layers.Dense): config = step.get_config() activation = config["activation"] - if activation not in ("relu", "linear"): + if activation not in ("relu", "softmax", "linear"): raise NoModel(predictor, f"Unsupported activation {activation}") elif isinstance(step, keras.layers.ReLU): if step.negative_slope != 0.0: