Giter Site home page Giter Site logo

tensorflowinference.jl's Introduction

TensorFlowInference.jl

Easy access to ready made TensorFlow models in Julia. Currently the focus is on running inference, loading a trained model is very easy, and use the inference results from Julia. Supports the latest TensorFlow versions (2.15), and can be made to support older versions, since the Julia code relies on the C API. You can use all of the TensorFlow C API which is huge, but there are convenience methods to get you started.

Examples:

using TensorFlowInference
using MLDatasets 


testset = MNIST(:test)

testsetMatrix = testset.features


graph = TF_NewGraph();
status = TF_NewStatus();
saved_model_dir = "mnist/";


session = simpleLoadSessionFromSavedModel(saved_model_dir, graph, status)


printOutput(graph)

inputValues = testsetMatrix
graphInputName = "serving_default_flatten_1_input"
graphOutputName = "StatefulPartitionedCall"

outputMatrix = simpleSessionRun(session, graph, status, inputValues, graphInputName, graphOutputName)


To save a model, use the following Python example Code:

import numpy as np
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers, Sequential
from tensorflow.keras.layers import Dense, LSTM, InputLayer, Bidirectional, TimeDistributed, Embedding, Activation
from tensorflow.keras.optimizers import Adam

mnist = tf.keras.datasets.mnist

(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0

model = tf.keras.models.Sequential([
  tf.keras.layers.Flatten(input_shape=(28, 28)),
  tf.keras.layers.Dense(128, activation='relu'),
  tf.keras.layers.Dropout(0.2),
  tf.keras.layers.Dense(10)
])

predictions = model(x_train[:1]).numpy()
predictions

loss_fn = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)

loss_fn(y_train[:1], predictions).numpy()
model.compile(optimizer='adam',
              loss=loss_fn,
              metrics=['accuracy'])
model.fit(x_train, y_train, epochs=5)
model.evaluate(x_test,  y_test, verbose=2)



tf.saved_model.save(model, "/mydirectory/mnist")



tensorflowinference.jl's People

Contributors

stensmo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.