.. only:: html
.. note::
:class: sphx-glr-download-link-note
Click :ref:`here ` to download the full example code
.. rst-class:: sphx-glr-example-title
.. _sphx_glr_Examples_1_TensorflowExample.py:
Tensorflow Example
====================
Top contributors (to current version):
- Christopher Lazarus
- Kyle Julian
This file is part of the Marabou project.
Copyright (c) 2017-2019 by the authors listed in the file AUTHORS
in the top-level source directory) and their institutional affiliations.
All rights reserved. See the file COPYING in the top-level source
directory for licensing information.
.. code-block:: default
from maraboupy import Marabou
import numpy as np
This network has inputs x0, x1, and was trained to create outputs that approximate
y0 = abs(x0) + abs(x1), y1 = x0^2 + x1^2
.. code-block:: default
filename = "../../resources/tf/frozen_graph/fc1.pb"
network = Marabou.read_tf(filename)
Or, you can specify the operation names of the input and output operations.
The default chooses the placeholder operations as input and the last operation as output
.. code-block:: default
inputNames = ['Placeholder']
outputName = 'y_out'
network = Marabou.read_tf(filename = filename, inputNames = inputNames, outputName = outputName)
Get the input and output variable numbers; [0] since first dimension is batch size
.. code-block:: default
inputVars = network.inputVars[0][0]
outputVars = network.outputVars[0]
Set input bounds on both input variables
.. code-block:: default
network.setLowerBound(inputVars[0],-10.0)
network.setUpperBound(inputVars[0], 10.0)
network.setLowerBound(inputVars[1],-10.0)
network.setUpperBound(inputVars[1], 10.0)
Set output bounds on the second output variable
.. code-block:: default
network.setLowerBound(outputVars[1], 194.0)
network.setUpperBound(outputVars[1], 210.0)
Call to C++ Marabou solver
.. code-block:: default
vals, stats = network.solve("marabou.log")
.. rst-class:: sphx-glr-timing
**Total running time of the script:** ( 0 minutes 0.000 seconds)
.. _sphx_glr_download_Examples_1_TensorflowExample.py:
.. only :: html
.. container:: sphx-glr-footer
:class: sphx-glr-footer-example
.. container:: sphx-glr-download sphx-glr-download-python
:download:`Download Python source code: 1_TensorflowExample.py <1_TensorflowExample.py>`
.. container:: sphx-glr-download sphx-glr-download-jupyter
:download:`Download Jupyter notebook: 1_TensorflowExample.ipynb <1_TensorflowExample.ipynb>`
.. only:: html
.. rst-class:: sphx-glr-signature
`Gallery generated by Sphinx-Gallery `_