cog-imperial / OMLT

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

Error encountered with the code example in the readme #76

Closed DKenefake closed 2 years ago

DKenefake commented 2 years ago

Hello, I was trying to run the example code provided in the ReadMe and encountered errors when using omlt.io.load_keras_sequential to load the NN into the network definition. It seems that the versioning of TensorFlow changes how some variables are stored and perhaps a version number of TensorFlow needs to be specified in the requires field of setup.cfg.

Here is the error output from the readme example.

Version numbers for the relevant packages, this is running on a windows 10 desktop. packages:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
C:\Users\DUSTIN~1.KEN\AppData\Local\Temp/ipykernel_7852/3182238221.py in <module>
     34 #multiple formulations of a neural network are possible
     35 #this uses the default NeuralNetworkFormulation object
---> 36 formulation = FullSpaceNNFormulation(net)
     37 
     38 #build the formulation on the OMLT block

C:\tools\Anaconda3\envs\new_base\lib\site-packages\omlt\neuralnet\nn_formulation.py in __init__(self, network_structure, layer_constraints, activation_constraints)
     68 
     69         # TODO: Change these to exceptions.
---> 70         network_inputs = list(self.__network_definition.input_nodes)
     71         assert len(network_inputs) == 1, 'Multiple input layers are not currently supported.'
     72         network_outputs = list(self.__network_definition.output_nodes)

C:\tools\Anaconda3\envs\new_base\lib\site-packages\omlt\neuralnet\network_definition.py in input_layers(self)
     68     def input_layers(self):
     69         """Return an iterator over the input layers"""
---> 70         for layer_id, in_degree in self.__graph.in_degree():
     71             if in_degree == 0:
     72                 yield self.__layers_by_id[layer_id]

TypeError: cannot unpack non-iterable int object
ThebTron commented 2 years ago

Apologies for the late reply!

I couldn't reproduce the error on Ubuntu with the package versions you mentioned.

I believe another OMLT dev reached out to you to check if the compatibility with Windows 10 was the problem, and you mentioned that you got it working on a different Windows 10 machine. So I think the problem is either with the particular Windows machine you tried first or with Tensorflow 2.3 on Windows 10.

I will close this issue for now, but please feel free to submit another issue if you run into the same problem again.

Thanks again for your feedback!