Skip to content

Instantly share code, notes, and snippets.

Avatar

J. Roger Zhao jzstark

View GitHub Profile
View test.ml
open Owl
open Algodiff.D
let rec desc ?(eta=F 0.01) ?(eps=1e-6) f x =
let g = (diff f) x in
if (unpack_flt g) < eps then x
else desc ~eta ~eps f Maths.(x - eta * g)
View example_08.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Owl - OCaml Scientic and Engineering Computing</title>
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
@jzstark
jzstark / Readme.md
Created Sep 17, 2019
Owl-Tensorflow Converter Examples
View Readme.md
@jzstark
jzstark / Readme.md
Last active Sep 25, 2019
Simple MNIST neural network (MirageOS)
View Readme.md

Files:

  • config.ml: MirageOS configuration file.
  • simple_mnist.ml: main logic of MNIST neural network.
  • simple_mnist_weight.ml: pre-trained weights of the neural network.

Information:

  • Weight file size: 146KB.
  • Model test accuracy: 92%.
  • MirageOS: compile with Unix backend. The generated binary is 10MB. The other backends are not tested yet.
View Readme.md

How I think Algodiff Works

To train a network, we need to first use train_generic:

let train_generic ?state ?params ?(init_model=true) nn x y =
    if init_model = true then init nn;
    let f = forward nn in
    let b = backward nn in
    let u = update nn in
@jzstark
jzstark / Readme.md
Last active Sep 16, 2019
Simple MNIST neural network
View Readme.md

Files:

  • simple_mnist.ml: main logic of MNIST neural network.
  • simple_mnist_weight.ml: pre-trained weights of the neural network.

Information:

  • Weight file size: 146KB.
  • Model test accuracy: 92%.
  • MirageOS: compile with Unix backend. The generated binary is 10MB. The other backends are not tested yet. Here is the MirageOS version of this simple MNIST.

Usage:

View _readme.md

Owl-Tensorflow Converter Example: MNIST CNN Training

This example is a example of MNIST-based CNN.

  • Step 1 : running OCaml script tfgraph_train.ml, which generates a file tf_convert_mnist.pbtxt in current directory.
  • Step 2 : make sure tf_convert_mnist.pbtxt and tfgraph_train.py in the same graph; make sure Tensorflow/numpy etc. is installed.
  • Step 3 : execute python tf_converter_mnist.py, and the expected output on screen is the training progress. After each 100 steps, loss value and model accuracy will be shown.

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

View _readme.md

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).

View print_param.ml
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 Feb 18, 2019
Owl-Tensorflow Converter Example: Oscillator
View _Readme.md

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).

You can’t perform that action at this time.