cog-imperial / OMLT

Represent trained machine learning models as Pyomo optimization formulations
Other
257 stars 56 forks source link

Need assistance with integrating a pre-trained neural network into Pyomo model using OMLT #119

Closed harshita1999 closed 9 months ago

harshita1999 commented 12 months ago

Hello, I'm new to OMLT and I'm encountering an issue while trying to utilize a pre-trained neural network with a Pyomo model using OMLT. The problem arises when I call the build_formulation function. I have attempted two approaches: one using the load_onnx_neural_network function without input bounds, and the other with input bounds. Unfortunately, both attempts result in errors. I have included the relevant code snippet, the pre-trained neural network in ONNX format, and the error messages. Any guidance or suggestions to resolve this issue and ensure the proper execution of the code would be greatly appreciated. [rho.zip](https://github.com/cog-imperial/OMLT/files/12063083/rho.zip) (All the 4 files mentioned are present in the zipped folder

juan-campos commented 11 months ago

Hello @harshita1999 . I think the problem is that your onnx model defined the input and every other layer not as a one dimensional vector but as a two dimensional one with the first dimension equal to 1.

If instead of defining the bounds of your input as: input_bounds=[(-big_m,big_m)]*latent_space

it is defined as a dictionary with the key a tuple representing the 2-dim index: input_bounds = {} for i in range(latent_space): input_bounds[(0,i)] = (-big_m, big_m)

It should work now. Let me know if this helps.

Juan Campos