All Projects → FluxML → FluxJS.jl

FluxML / FluxJS.jl

Licence: other
I heard you like compile times

Programming Languages

julia
2034 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to FluxJS.jl

Fluxible
A pluggable container for universal flux applications.
Stars: ✭ 1,811 (+4111.63%)
Mutual labels:  flux
Multi Tenancy
Flux v1: Manage a multi-tenant cluster with Flux and Kustomize
Stars: ✭ 180 (+318.6%)
Mutual labels:  flux
Flooks
🍸 A state manager for React Hooks
Stars: ✭ 201 (+367.44%)
Mutual labels:  flux
Influxdb Client Python
InfluxDB 2.0 python client
Stars: ✭ 165 (+283.72%)
Mutual labels:  flux
Transformers.jl
Julia Implementation of Transformer models
Stars: ✭ 173 (+302.33%)
Mutual labels:  flux
Bedrock
Build a Node web app with user authentication, security, and more in under 10 minutes. Now supports React Hot Loading for super-fast development. 👌
Stars: ✭ 187 (+334.88%)
Mutual labels:  flux
Suas Ios
Unidirectional data flow architecture implementation for iOS, macOS, tvOS and watchOS
Stars: ✭ 147 (+241.86%)
Mutual labels:  flux
Blazor Fluxor
DEPRECATED PROJECT. See FLUXOR
Stars: ✭ 216 (+402.33%)
Mutual labels:  flux
Reactor Addons
Official modules for the Reactor project
Stars: ✭ 175 (+306.98%)
Mutual labels:  flux
Deox
Functional Type-safe Flux Standard Utilities
Stars: ✭ 200 (+365.12%)
Mutual labels:  flux
Retalk
🐤 The Simplest Redux
Stars: ✭ 168 (+290.7%)
Mutual labels:  flux
Geometricflux.jl
Geometric Deep Learning for Flux
Stars: ✭ 175 (+306.98%)
Mutual labels:  flux
Metalhead.jl
Computer vision models for Flux
Stars: ✭ 191 (+344.19%)
Mutual labels:  flux
Redux Zero
A lightweight state container based on Redux
Stars: ✭ 1,977 (+4497.67%)
Mutual labels:  flux
Tinystate
A tiny, yet powerful state management library for Angular
Stars: ✭ 207 (+381.4%)
Mutual labels:  flux
Firedux
🔥 🐣 Firebase + Redux for ReactJS
Stars: ✭ 148 (+244.19%)
Mutual labels:  flux
Typescript Webpack React Redux Boilerplate
React and Redux with TypeScript
Stars: ✭ 182 (+323.26%)
Mutual labels:  flux
Denormalizr
Denormalize data normalized with normalizr
Stars: ✭ 231 (+437.21%)
Mutual labels:  flux
Smitty
Tiny flux implementation built on mitt
Stars: ✭ 210 (+388.37%)
Mutual labels:  flux
K8s Gitops
GitOps principles to define kubernetes cluster state via code. Community around [email protected] is on discord: https://discord.gg/7PbmHRK
Stars: ✭ 192 (+346.51%)
Mutual labels:  flux

Build Status

Flux.JS

Run Flux models in the browser, via tensorflow.js.

Note that if you get errors running this package, you may need to run Pkg.checkout("ASTInterpreter2").

JS Output

You can see what Flux.JS sees with @code_js, which works like @code_typed or @code_native. Flux.JS simply accepts a function of arrays along with example inputs, and generates JavaScript code for you. Here's the simplest possible example:

julia> x = rand(10)
10-element Array{Float64,1}:
 0.299338
 
 0.267917

julia> @code_js identity(x)
let model = (function () {
  let math = tf;
  function model(kinkajou) {
    return kinkajou;
  };
  model.weights = [];
  return model;
})();
flux.fetchWeights("model.bson").then((function (ws) {
  return model.weights = ws;
}));

You can see that there's some setup code as Flux.JS expects to load some weights for a model. But the core of it is this function, which is exactly like the identity function in Julia.

function model(kinkajou) {
  return kinkajou;
};

Let's try something more interesting; f takes two arguments and multiplies them.

julia> f(W,x) = W*x

julia> @code_js f(rand(5,10),rand(10))
let model = (function () {
  let math = tf;
  function model(bear, giraffe) {
    return math.matrixTimesVector(bear, giraffe);
  };
  model.weights = [];
  return model;
})();
flux.fetchWeights("model.bson").then((function (ws) {
  return model.weights = ws;
}));

Because Flux models are just Julia functions, we can use the same macro with them too. You'll now notice that the weights are being used.

julia> m = Chain(Dense(10,5,relu),Dense(5,2),softmax)

julia> @code_js m(x)
let model = (function () {
  let math = tf;
  function badger(eland) {
    return math.add(math.matrixTimesVector(model.weights[0], eland), model.weights[1]);
  };
  function chimpanzee(mongoose) {
    return math.relu(math.add(math.matrixTimesVector(model.weights[2], mongoose), model.weights[3]));
  };
  function model(shark) {
    return math.softmax(badger(chimpanzee(shark)));
  };
  model.weights = [];
  return model;
})();
flux.fetchWeights("model.bson").then((function (ws) {
  return model.weights = ws;
}));

There is also early support for RNNs (we compile stateful models directly, no unrolling).

julia> m = Chain(RNN(10,5))

julia> @code_js m(x)
let model = (function () {
  let math = tf;
  let init = [0.017732, 0.00991122, -0.00712077, -0.00161244, -0.00232475];
  let states = init.slice();
  function nightingale(seal, mongoose) {
    return [seal, mongoose];
  };
  function cat(horse) {
    let weasel = math.tanh(math.add(math.add(math.matrixTimesVector(model.weights[0], horse), math.matrixTimesVector(model.weights[1], states[0])), model.weights[2]));
    let coati = nightingale(weasel, weasel);
    states[0] = coati[1];
    return coati[2];
  };
  function model(fish) {
    return cat(fish);
  };
  model.reset = (function () {
    states = init.slice();
    return;
  });
  model.weights = [];
  return model;
})();
flux.fetchWeights("model.bson").then((function (ws) {
  return model.weights = ws;
}));

In general, the more useful entry point to the package is FluxJS.compile.

julia> FluxJS.compile("mnist", m, rand(10))

This will produce two files in the current directory: (1) mnist.js, which contains the same JavaScript code as above; (2) mnist.bson, which contains the model weights in a JS-loadable format.

Browser Setup

Firstly, you'll need the following scripts in your <head>. The flux.js script can be found here.

<head>
  <script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]"></script>
  <script src="https://unpkg.com/bson/browser_build/bson.js"></script>
  <script src="flux.js"></script> <!-- Or embed the script directly -->
</head>

From here, you can either link the generated code as another script, or embed it directly. In real applications you'll most likely want to wait on the fetchWeights promise, to avoid trying to use the model before it's ready.

<script>
let model = (function () {
  let math = tf;
  function model(kinkajou) {
    return kinkajou;
  };
  model.weights = [];
  return model;
})();
flux.fetchWeights("model.bson").then((function (ws) {
  return model.weights = ws;
}));
</script>

In the page, you can run the model from the dev tools.

> x = tf.tensor([1,2,3,4,5,6,7,8,9,10])
  Tensor {isDisposed: false, size: 10, shape: Array(1), dtype: "float32", strides: Array(0), …}
> await model(x).data()
  Float32Array(25) [0.0262143611907959, -0.04852187633514404, ]

See the tensorflow.js docs for more information on how to work with its tensor objects.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].