Skip to content

Instantly share code, notes, and snippets.

@jzstark
Last active January 11, 2020 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jzstark/6dfed11c521fb2cd286f2519fb88d3bf to your computer and use it in GitHub Desktop.
Save jzstark/6dfed11c521fb2cd286f2519fb88d3bf to your computer and use it in GitHub Desktop.
An Inception Example in Owl

Inception_example

An example showing how to use the InceptionV3 neural network (defined in this gist) to do image classification on Owl, with only a few lines of code. Please refer to this Gist for more details. Enjoy!

#!/usr/bin/env owl
open Owl
(* Import InceptionV3 Library *)
#zoo "9428a62a31dbea75511882ab8218076f"
let img = "/path/to/you/image.png";;
let _ =
(* Path to your image; here we use the "panda.png"
* in this gist as example.
*)
let img = Owl_zoo_path.extend_zoo_path "panda.png" in
(* Image classification *)
let labels = InceptionV3.infer img in
(* Get top-5 human-readable output in the format of JSON string, or...*)
let top = 5 in
let labels_json = InceptionV3.to_json ~top labels in
(* an array of tuples. Each tuple contains a category (string) and
* its inferred probability (float), ranging from 1 to 100.
*)
let labels_tuples = InceptionV3.to_tuples labels in
(* (Optional) Pretty-print the results *)
Printf.printf "\nTop %d Predictions:\n" top;
Array.iteri (fun i x ->
let cls, prop = x in
Printf.printf "Prediction #%d (%.2f%%) : %s\n" i (prop *. 100.) cls;
) labels_tuples
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment