Skip to content

Instantly share code, notes, and snippets.

Owl-Tensorflow Converter Example: MNIST CNN

This example is a example of MNIST-based CNN.

  • Step 1 : running OCaml script tfgraph_inf.ml, which generates a file tf_convert_mnist.pbtxt in current directory.
  • Step 2 : make sure tf_convert_mnist.pbtxt and tfgraph_inf.py in the same graph; make sure Tensorflow/numpy etc. is installed.
  • Step 3 : execute python tf_converter_mnist.py, and the expected output in screen is an array of size [100], each element is a boolean value. There is also an value to indicate the inference accuracy.

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

@jzstark
jzstark / #readme.md
Last active May 4, 2019 18:10
An implementation of InceptionV3 network with Owl

InceptionV3

InceptionV3 is one of Google’s latest effort to do image recognition. This is a standard task in computer vision, where models try to classify entire images into 1000 classes, like "Zebra", "Dalmatian", and "Dishwasher". Compared with previous DNN models, InceptionV3 has one of the most complex networks architectures in computer vision models. The original paper of this network is here.

Usage

This gist implements an InceptionV3 service in Owl, and provides simple interfaces to use. Here is an example:

#zoo "9428a62a31dbea75511882ab8218076f"
#!/usr/bin/env owl
open Owl
module N = Dense.Ndarray.S
let preprocess img =
let img = N.copy img in (*!!!*)
let r = N.get_slice [[];[];[];[0]] img in
let r = N.sub_scalar r 123.68 in
open Printf
let () =
for i = 0 to Array.length Sys.argv - 1 do
printf "[%i] %s\n" i Sys.argv.(i)
done;;
@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 / _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").

@jzstark
jzstark / dune
Created February 5, 2019 19:43
Serialise a TF Variable in OCaml
(executable
(name main)
(libraries ocaml-protoc))