@@ -99,27 +99,46 @@ Keras
9999They can be formulated in a Gurobi model with the function
100100:py:func: `add_keras_constr <gurobi_ml.keras.add_keras_constr> `.
101101
102- Currently, only two types of layers are supported:
103-
104- * `Dense layers <https://keras.io/api/layers/core_layers/dense/ >`_ (possibly
105- with `relu ` activation),
106- * `ReLU layers <https://keras.io/api/layers/activation_layers/relu/ >`_ with
107- default settings.
102+ Supported layers and notes:
103+
104+ - `Dense <https://keras.io/api/layers/core_layers/dense/ >`_ with activation
105+ ``relu `` or ``linear ``.
106+ - `ReLU <https://keras.io/api/layers/activation_layers/relu/ >`_ with default
107+ settings (no negative_slope/threshold/max_value variations).
108+ - `Conv2D <https://keras.io/api/layers/convolution_layers/convolution2d/ >`_
109+ with activation ``relu `` or ``linear `` and padding ``valid `` only (no
110+ ``same `` padding). Strides are supported.
111+ - `MaxPooling2D <https://keras.io/api/layers/pooling_layers/max_pooling2d/ >`_
112+ with padding ``valid `` only.
113+ - `Flatten <https://keras.io/api/layers/reshaping_layers/flatten/ >`_.
114+ - `Dropout <https://keras.io/api/layers/regularization_layers/dropout/ >`_ is
115+ accepted but ignored at inference time (treated as identity).
116+
117+ Input tensors for CNNs use channels-last layout (NHWC). Flatten converts 4D
118+ NHWC tensors to 2D (batch, features).
108119
109120PyTorch
110121-------
111122
112-
113- In PyTorch, only :external+torch:py:class: `torch.nn.Sequential ` objects are
114- supported.
115-
116- They can be formulated in a Gurobi model with the function
117- :py:func: `add_sequential_constr <gurobi_ml.torch.sequential.add_sequential_constr> `.
118-
119- Currently, only two types of layers are supported:
120-
121- * :external+torch:py:class: `Linear layers <torch.nn.Linear> `,
122- * :external+torch:py:class: `ReLU layers <torch.nn.ReLU> `.
123+ In PyTorch, :external+torch:py:class: `torch.nn.Sequential ` models are supported
124+ via :py:func: `add_sequential_constr <gurobi_ml.torch.sequential.add_sequential_constr> `.
125+
126+ Supported layers and notes:
127+
128+ - :external+torch:py:class: `Linear <torch.nn.Linear> `.
129+ - :external+torch:py:class: `ReLU <torch.nn.ReLU> `.
130+ - :external+torch:py:class: `Conv2d <torch.nn.Conv2d> ` with padding equivalent
131+ to ``valid `` only (no non-zero padding or ``same ``), strides supported.
132+ - :external+torch:py:class: `MaxPool2d <torch.nn.MaxPool2d> ` with padding
133+ equivalent to ``valid `` only.
134+ - :external+torch:py:class: `Flatten <torch.nn.Flatten> `.
135+ - :external+torch:py:class: `Dropout <torch.nn.Dropout> ` is accepted and
136+ ignored at inference time (identity).
137+
138+ Input tensors for CNNs are provided as NHWC variables. Internally, inputs are
139+ converted to NCHW for PyTorch evaluation and converted back for error checks.
140+ The first Linear after a Flatten layer is adjusted to account for PyTorch’s
141+ NCHW flatten order so that predictions match exactly.
123142
124143XGBoost
125144-------
0 commit comments