Skip to content

Instantly share code, notes, and snippets.

@jzstark
jzstark / _Readme.md
Last active February 18, 2019 18:11
Owl-Tensorflow Converter Example: Oscillator

Owl-Tensorflow Converter Example: Oscillator

This example is provided by @tachukao. It is a simple example of learning a periodic oscillator and the initial condition.

  • Step 1 : running OCaml script oscillator.ml, which generates a file oscillator.pbtxt in current directory. Depending on n_steps, this step might take a bit long
  • Step 2 : make sure oscillator.pbtxt and oscillator.py in the same graph; make sure Tensorflow/numpy etc. is installed.
  • Step 3 : execute python oscillator.py, and the expected output in screen is a float number.

Here we only assume the python script writer knows where to find the output node (in collection "result") and the placeholder names (x0 and a).

@jzstark
jzstark / _Readme.md
Last active February 14, 2019 19:44
Owl-Tensorflow Converter Example: Higher-Order Derivatives

Owl-Tensorflow Converter Example: Higher-Order Derivatives

In this gist, we first defines a function f0, then construct the computation graph of from the first to the fourth derivative by calling diff function from Owl's Algorithmic Differentiation module. This computation graph is then passed to Tensorflow for executation.

This is a recreation of a exsiting Owl AD module example. See the doc for more details.

  • Step 1 : running OCaml script tf_convert_diff.ml, which generates a file tf_convert_diff.pbtxt in current directory.
  • Step 2 : make sure tf_convert_diff.pbtxt and tf_convert_diff.py in the same graph; make sure Tensorflow/numpy etc. is installed.
  • Step 3 : execute python tf_convert_diff.py, and the expected output is a saved image tf_convert_diff.png in the current directory.
@jzstark
jzstark / _Readme.md
Last active February 14, 2019 14:46
A simple DNN inference example of owl-tensorflow cgraph convert

Owl-Tensorflow Converter Example: MNIST DNN Inference

This gist shows an demonstration of how to define a DNN and express it as computation graph in Owl, and then conduct inference in Tensorflow.

  • Step 1 : running OCaml script mnist_inf_example.ml, which generates a file test_cgraph_cnn.pbtxt in current directory.
  • Step 2 : make sure test_cgraph_cnn.pbtxt and mnist_inf_example.py in the same graph; make sure Tensorflow/numpy etc. is installed.
  • Step 3 : execute python mnist_inf_example.py, and the expected printed output is a loss value that is close to 2.3.

Here we only assume the python script writer knows where to find the output node (in collection "result") and the placeholder names (xt and yt).

@jzstark
jzstark / dune
Created February 5, 2019 19:43
Serialise a TF Variable in OCaml
(executable
(name main)
(libraries ocaml-protoc))
@jzstark
jzstark / _Readme.md
Last active February 14, 2019 14:45
A initial simple example of owl-tensorflow cgraph convert

Owl-Tensorflow Converter

This gist shows an initial simple demonstration of how to define a computation graph in Owl, and then execute it in Tensorflow.

  • Step 1 : running OCaml script tf_converter.ml, which generates a file test_cgraph.pbtxt
  • Step 2 : make sure test_cgraph.pbtxt and exec_cgraph.py in the same graph; make sure Tensorflow/numpy etc. is installed.
  • Step 3 : execute python exec_cgraph.py, and the expected printed output is a 3x3 matrix.

Here we only assume the python script writer knows where to find the output node (in collection "result").

## Change the definition of MNSIT network with full DNN
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import math
import os
import sys
import time
## Only save network structure; loss and train_op created after loading.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import math
import os
import sys
import time
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import math
import os
import sys
import time
import tensorflow as tf
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import math
import os
import sys
import time
import tensorflow as tf