Closed hhijazi closed 1 year ago
Thanks for the question @hhijazi. My colleague @juan-campos has tried:
onnx_model = onnx.load(‘MatMul_Add.onnx’)
network_definition = load_onnx_neural_network(onnx_model)
without getting issues. Are you including variable bounds? Perhaps the issue is with these.
I did the following:
model = onnx.load("MatMul_Add.onnx")
net = load_onnx_neural_network(model)
formulation = FullSpaceNNFormulation(net)
mip = pyo.ConcreteModel()
mip.nn = OmltBlock()
mip.nn.build_formulation(formulation)
@hhijazi I think the issue is that your model contains ReLU activations. In this case for the MIP reformulation you would need to add some bounds for the inputs. For example I tried :
input_bounds = {}
for i in range(2):
input_bounds[i] = (0, 1)
model = onnx.load("MatMul_Add.onnx")
network_definition = load_onnx_neural_network(model, None, input_bounds)
mip = pyo.ConcreteModel()
mip.nn = OmltBlock()
mip.nn.build_formulation(formulation)
mip.obj = pyo.Objective(expr=(-(mip.nn.outputs[0])))
pyo.SolverFactory('gurobi', solver_io="python").solve(mip, tee=True)
and it works. I hope this helps, if not let me know
Juan
Ok, thanks Juan! It would be nice to specify this in the doc or the Readme, or perhaps I just missed it...
I get the following error when trying to read the attached onnx file:
File "/usr/local/lib/python3.10/site-packages/omlt/neuralnet/activations/relu.py", line 51, in bigm_relu_activation_constraint layer_block.z[output_index].setub(max(0, ub)) TypeError: '>' not supported between instances of 'NoneType' and 'int'
MatMul_Add.onnx.zip