Skip to content

Commit a0339f4

Browse files
committed
Temporary
1 parent 327d178 commit a0339f4

File tree

5 files changed

+180
-251
lines changed

5 files changed

+180
-251
lines changed

Generate_keras_test_network.ipynb

Lines changed: 126 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,54 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": null,
5+
"execution_count": 12,
66
"id": "c8d57e80-9075-4d63-bc36-f9aaad08ea2f",
77
"metadata": {},
88
"outputs": [],
99
"source": [
10-
"import tensorflow as tf"
10+
"import keras"
1111
]
1212
},
1313
{
1414
"cell_type": "code",
15-
"execution_count": null,
15+
"execution_count": 13,
16+
"id": "90fa4efb-f9d5-40fb-8e4a-5e3ed1094740",
17+
"metadata": {},
18+
"outputs": [
19+
{
20+
"data": {
21+
"text/plain": [
22+
"'3.7.0'"
23+
]
24+
},
25+
"execution_count": 13,
26+
"metadata": {},
27+
"output_type": "execute_result"
28+
}
29+
],
30+
"source": [
31+
"keras.__version__"
32+
]
33+
},
34+
{
35+
"cell_type": "code",
36+
"execution_count": 14,
1637
"id": "5d98d000-661e-4495-bef0-49c5eb180aff",
1738
"metadata": {},
1839
"outputs": [],
1940
"source": [
20-
"nn = tf.keras.models.Sequential(\n",
41+
"nn = keras.models.Sequential(\n",
2142
" [\n",
22-
" tf.keras.layers.InputLayer((8,)),\n",
23-
" tf.keras.layers.Dense(30, activation='relu'),\n",
24-
" tf.keras.layers.Dense(1),\n",
43+
" keras.layers.InputLayer((8,)),\n",
44+
" keras.layers.Dense(30, activation='relu'),\n",
45+
" keras.layers.Dense(1),\n",
2546
" ]\n",
2647
")"
2748
]
2849
},
2950
{
3051
"cell_type": "code",
31-
"execution_count": null,
52+
"execution_count": 15,
3253
"id": "ba3cf3ee-bd25-4180-95c0-2ff42d858a34",
3354
"metadata": {},
3455
"outputs": [],
@@ -38,29 +59,29 @@
3859
},
3960
{
4061
"cell_type": "code",
41-
"execution_count": null,
62+
"execution_count": 16,
4263
"id": "247bd200-8026-4f08-8739-9aabb3c37e99",
4364
"metadata": {},
4465
"outputs": [],
4566
"source": [
4667
"(X_train, y_train), (X_test, y_test) = tf.keras.datasets.california_housing.load_data(\n",
47-
" version=\"large\"\n",
68+
" version=\"small\"\n",
4869
")\n"
4970
]
5071
},
5172
{
5273
"cell_type": "code",
53-
"execution_count": null,
74+
"execution_count": 18,
5475
"id": "a29325dd-1ab1-4cce-81c0-2528e892adb6",
5576
"metadata": {},
5677
"outputs": [],
5778
"source": [
58-
"normalize = tf.keras.layers.Normalization(axis=-1)"
79+
"normalize = keras.layers.Normalization(axis=-1)"
5980
]
6081
},
6182
{
6283
"cell_type": "code",
63-
"execution_count": null,
84+
"execution_count": 19,
6485
"id": "cbecbd91-e100-4568-9424-efd9e3b6d5fc",
6586
"metadata": {},
6687
"outputs": [],
@@ -72,18 +93,106 @@
7293
},
7394
{
7495
"cell_type": "code",
75-
"execution_count": null,
96+
"execution_count": 21,
7697
"id": "5656d2da-ee2d-4a8f-aef3-65876c20193b",
7798
"metadata": {},
99+
"outputs": [
100+
{
101+
"name": "stdout",
102+
"output_type": "stream",
103+
"text": [
104+
"Epoch 1/20\n",
105+
"\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 36ms/step - loss: 51257974784.0000 - val_loss: 48780189696.0000\n",
106+
"Epoch 2/20\n",
107+
"\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 34ms/step - loss: 51058966528.0000 - val_loss: 48779857920.0000\n",
108+
"Epoch 3/20\n",
109+
"\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 30ms/step - loss: 56175738880.0000 - val_loss: 48779501568.0000\n",
110+
"Epoch 4/20\n",
111+
"\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 28ms/step - loss: 48874921984.0000 - val_loss: 48779141120.0000\n",
112+
"Epoch 5/20\n",
113+
"\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 25ms/step - loss: 52104830976.0000 - val_loss: 48778752000.0000\n",
114+
"Epoch 6/20\n",
115+
"\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 41ms/step - loss: 53767278592.0000 - val_loss: 48778342400.0000\n",
116+
"Epoch 7/20\n",
117+
"\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 25ms/step - loss: 51997323264.0000 - val_loss: 48777920512.0000\n",
118+
"Epoch 8/20\n",
119+
"\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 34ms/step - loss: 52127023104.0000 - val_loss: 48777490432.0000\n",
120+
"Epoch 9/20\n",
121+
"\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 31ms/step - loss: 55014318080.0000 - val_loss: 48777023488.0000\n",
122+
"Epoch 10/20\n",
123+
"\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 27ms/step - loss: 50627502080.0000 - val_loss: 48776540160.0000\n",
124+
"Epoch 11/20\n",
125+
"\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 28ms/step - loss: 52081172480.0000 - val_loss: 48776024064.0000\n",
126+
"Epoch 12/20\n",
127+
"\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 21ms/step - loss: 55939633152.0000 - val_loss: 48775487488.0000\n",
128+
"Epoch 13/20\n",
129+
"\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 34ms/step - loss: 51670016000.0000 - val_loss: 48774975488.0000\n",
130+
"Epoch 14/20\n",
131+
"\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 26ms/step - loss: 55131279360.0000 - val_loss: 48774389760.0000\n",
132+
"Epoch 15/20\n",
133+
"\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 30ms/step - loss: 51200266240.0000 - val_loss: 48773820416.0000\n",
134+
"Epoch 16/20\n",
135+
"\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 30ms/step - loss: 53789458432.0000 - val_loss: 48773218304.0000\n",
136+
"Epoch 17/20\n",
137+
"\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 29ms/step - loss: 50551488512.0000 - val_loss: 48772616192.0000\n",
138+
"Epoch 18/20\n",
139+
"\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 28ms/step - loss: 50127593472.0000 - val_loss: 48771956736.0000\n",
140+
"Epoch 19/20\n",
141+
"\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 31ms/step - loss: 48622862336.0000 - val_loss: 48771301376.0000\n",
142+
"Epoch 20/20\n",
143+
"\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 30ms/step - loss: 53927636992.0000 - val_loss: 48770617344.0000\n"
144+
]
145+
},
146+
{
147+
"data": {
148+
"text/plain": [
149+
"<keras.src.callbacks.history.History at 0x7eb858fa50>"
150+
]
151+
},
152+
"execution_count": 21,
153+
"metadata": {},
154+
"output_type": "execute_result"
155+
}
156+
],
157+
"source": [
158+
"nn.fit(X_train, y_train, epochs=20, validation_data=(X_test, y_test))"
159+
]
160+
},
161+
{
162+
"cell_type": "code",
163+
"execution_count": 22,
164+
"id": "128b1ba9-55e9-4d78-9b31-d2a0da9bb165",
165+
"metadata": {},
78166
"outputs": [],
79167
"source": [
80-
"nn.fit(X_train, y_train, epochs=100, validation_data=(X_test, y_test))"
168+
"nn.save('toto.keras')"
169+
]
170+
},
171+
{
172+
"cell_type": "code",
173+
"execution_count": 24,
174+
"id": "9c820767-db55-48ba-8dd3-675d06fb5c3d",
175+
"metadata": {},
176+
"outputs": [
177+
{
178+
"data": {
179+
"text/plain": [
180+
"<Sequential name=sequential_1, built=True>"
181+
]
182+
},
183+
"execution_count": 24,
184+
"metadata": {},
185+
"output_type": "execute_result"
186+
}
187+
],
188+
"source": [
189+
"keras.saving.load_model('toto.keras')"
81190
]
82191
},
83192
{
84193
"cell_type": "code",
85194
"execution_count": null,
86-
"id": "128b1ba9-55e9-4d78-9b31-d2a0da9bb165",
195+
"id": "68653ae3-8f6a-4359-be49-b0049e1e0d5b",
87196
"metadata": {},
88197
"outputs": [],
89198
"source": []
@@ -105,7 +214,7 @@
105214
"name": "python",
106215
"nbconvert_exporter": "python",
107216
"pygments_lexer": "ipython3",
108-
"version": "3.11.10"
217+
"version": "3.11.2"
109218
},
110219
"license": {
111220
"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# =============================================================================="

src/gurobi_ml/modeling/neuralnet/activations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def __init__(self):
140140
if not _HAS_NLEXPR:
141141
raise NoModel(self, "Can't use logistic activation without Gurobi ≥ 12.0")
142142

143-
def mip_model(self, layer, predict_function='predict_proba', **kwargs):
143+
def mip_model(self, layer, predict_function="predict_proba", **kwargs):
144144
"""MIP model for logistic activation on a layer.
145145
146146
Parameters
@@ -181,7 +181,7 @@ class SoftMax:
181181
def __init__(self):
182182
pass
183183

184-
def mip_model(self, layer, predict_function='predict_proba', **kwargs):
184+
def mip_model(self, layer, predict_function="predict_proba", **kwargs):
185185
"""MIP model for SoftMax activation on a layer.
186186
187187
Parameters

src/gurobi_ml/sklearn/mlpregressor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def __init__(
198198
clean_predictor=False,
199199
**kwargs,
200200
):
201-
assert predictor.out_activation_ in ("identity", )
201+
assert predictor.out_activation_ in ("identity",)
202202
SKRegressor.__init__(
203203
self,
204204
predictor,

0 commit comments

Comments
 (0)