cog-imperial / OMLT

Represent trained machine learning models as Pyomo optimization formulations
Other
262 stars 57 forks source link

[WIP] New NetworkDefinition with CNN support #14

Closed fracek closed 2 years ago

fracek commented 2 years ago

This is the code I mentioned during our last meeting that changes how networks are defined. This is still a WIP but now I think I'm ready for feedback.

A couple of things to notice:

I didn't have time to check the tests so the best way to run an example is to run the _test.py script I included (and will delete for the final PR).

jalving commented 2 years ago

I'll take a look at this soon. For testing, it looks like one test changed back to import optml and the others errored out because we need to setup networkx as a dependency.

fracek commented 2 years ago

I updated how OMLT generates neural network formulations. I think the best file to view how the new api looks like is this one https://github.com/cog-imperial/OMLT/blob/onnx-cnn/tests/neuralnet/test_relu.py

Basically, users can override how layers/activations are generated by specifying a new callable object (either a function or a class that implements __call__).

codecov[bot] commented 2 years ago

Codecov Report

Merging #14 (c3cd367) into main (a89dca7) will decrease coverage by 26.47%. The diff coverage is 79.25%.

Impacted file tree graph

@@             Coverage Diff             @@
##             main      #14       +/-   ##
===========================================
- Coverage   91.10%   64.62%   -26.48%     
===========================================
  Files          15       23        +8     
  Lines         854     1077      +223     
  Branches      147      154        +7     
===========================================
- Hits          778      696       -82     
- Misses         51      360      +309     
+ Partials       25       21        -4     
Impacted Files Coverage Δ
src/omlt/io/keras_reader.py 8.00% <8.00%> (ø)
src/omlt/io/onnx.py 47.61% <38.88%> (-44.78%) :arrow_down:
src/omlt/block.py 54.86% <50.00%> (-37.87%) :arrow_down:
src/omlt/neuralnet/layers/full_space.py 60.60% <60.60%> (ø)
src/omlt/neuralnet/layer.py 62.87% <62.87%> (ø)
src/omlt/neuralnet/network_definition.py 89.65% <88.23%> (-4.99%) :arrow_down:
src/omlt/io/onnx_parser.py 93.16% <93.16%> (ø)
src/omlt/neuralnet/formulation.py 96.82% <96.82%> (ø)
src/omlt/neuralnet/activations/relu.py 96.87% <96.87%> (ø)
src/omlt/formulation.py 89.09% <100.00%> (+0.85%) :arrow_up:
... and 12 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update a89dca7...c3cd367. Read the comment docs.

fracek commented 2 years ago

I disabled the input/output tests and reduced space ones since they're being reworked on. I will increase coverage in the coming days.