OMLT Main Example: Pyomo build_formation function fails #127
-
I tried testing the main OMLT example using a Keras model. The only code I replaced is defining the Keras model "nn". Loading the Keras model into an OMLT network definition and creating the formulation worked. Then this example fails when calling build_formulation. Has anyone else tested this and seen this error? ERROR: Rule failed when initializing variable for Var nn.scaled_inputs with KeyError Traceback (most recent call last) File /local_disk0/.ephemeral_nfs/envs/pythonEnv-270249cb-9f79-4e2c-a55c-4f7dd0a7b838/lib/python3.10/site-packages/omlt/block.py:89, in OmltBlockData.build_formulation(self, formulation) File /local_disk0/.ephemeral_nfs/envs/pythonEnv-270249cb-9f79-4e2c-a55c-4f7dd0a7b838/lib/python3.10/site-packages/omlt/neuralnet/nn_formulation.py:106, in FullSpaceNNFormulation._build_formulation(self)
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Issue may be due to the formulation and using ReLu functions. Will look more into OMLT example notebooks. |
Beta Was this translation helpful? Give feedback.
Hi @bspiveyxom. Thank you for your comment. It seems that your neural network takes in 8 inputs but your scaled_input_bounds dictionary and your scaling object specify information for only 1 variable. For example, if you have the same mean, std_dev, and bounds for all 8 input variables, try:
inputs_to_nn = 8
scaler = OffsetScaling(offset_inputs=[scale_x[0] for i in range(inputs_to_nn)], factor_inputs=[scale_x[1] for i in range(inputs_to_nn)], offset_outputs=[scale_y[0]], factor_outputs=[scale_y[1]])
scaled_input_bounds = {i: (0, 5) for i in range(inputs_to_nn)}