Giter Club home page Giter Club logo

tensorspace-team / tensorspace Goto Github PK

View Code? Open in Web Editor NEW
5.0K 135.0 440.0 1.1 GB

Neural network 3D visualization framework, build interactive and intuitive model in browsers, support pre-trained deep learning models from TensorFlow, Keras, TensorFlow.js

Home Page: https://tensorspace.org

License: Apache License 2.0

JavaScript 99.69% HTML 0.30% Shell 0.02%
deep-learning tensorflow keras tfjs 3d visualization threejs machine-learning nerual-network

tensorspace's Introduction

TensorSpace.js

Present Tensor in Space

English | 中文

npm version license badge dependencies badge dependencies badge dependencies badge build gitter

TensorSpace is a neural network 3D visualization framework built using TensorFlow.js, Three.js and Tween.js. TensorSpace provides Keras-like APIs to build deep learning layers, load pre-trained models, and generate a 3D visualization in the browser. From TensorSpace, it is intuitive to learn what the model structure is, how the model is trained and how the model predicts the results based on the intermediate information. After preprocessing the model, TensorSpace supports to visualize pre-trained model from TensorFlow, Keras and TensorFlow.js.

Fig. 1 - Interactive LeNet created by TensorSpace

Table of Content

Motivation

TensorSpace is a neural network 3D visualization framework designed for not only showing the basic model structure, but also presenting the processes of internal feature abstractions, intermediate data manipulations and final inference generations.

By applying TensorSpace API, it is more intuitive to visualize and understand any pre-trained models built by TensorFlow, Keras, TensorFlow.js, etc. TensorSpace introduces a way for front end developers to be involved in the deep learning ecosystem. As an open source library, TensorSpace team welcomes any further development on visualization applications.

  • Interactive -- Use Layer API to build interactive model in browsers.
  • Intuitive -- Visualize the information from intermediate inferences.
  • Integrative -- Support pre-trained models from TensorFlow, Keras, TensorFlow.js.

Getting Started

Fig. 2 - TensorSpace Workflow

1. Install TensorSpace

Install in the Basic Case

  • Step 1: Download Dependencies

Download dependencies build files TensorFlow.js (tf.min.js), Three.js (three.min.js), Tween.js (tween.min.js), TrackballControls (TrackballControls.js).

  • Step 2: Download TensorSpace

Download TensorSpace build file tensorspace.min.js from Github, NPM, TensorSpace official website or CDN:

<!-- Replace "VERSION" with the version you want to use. -->
<script src="https://cdn.jsdelivr.net/npm/tensorspace@VERSION/dist/tensorspace.min.js"></script>
  • Step 3: Include Build Files

Include all build files in web page.

<script src="tf.min.js"></script>
<script src="three.min.js"></script>
<script src="tween.min.js"></script>
<script src="TrackballControls.js"></script>
<script src="tensorspace.min.js"></script>

Install in the Progressive Framework

  • Step 1: Install TensorSpace

    • Option 1: NPM
    npm install tensorspace
    • Option 2: Yarn
    yarn add tensorspace
  • Step 2: Use TensorSpace

import * as TSP from 'tensorspace';

Checkout this Angular example for more information.

2. Preprocess the Pre-trained Model

Before applying TensorSpace to visualize the pre-trained model, there is an important pipeline - TensorSpace model preprocessing ( Checkout this article for more information about TensorSpace preprocessing ). We can use TensorSpace Converter to quickly complete the TensorSpace Preprocessing.

For example, if we have a tf.keras model in hand, we can use the following TensorSpace-Converter conversion script to convert a tf.keras model to the TensorSpace compatible format:

$ tensorspacejs_converter \
    --input_model_from="tensorflow" \
    --input_model_format="tf_keras" \
    --output_layer_names="padding_1,conv_1,maxpool_1,conv_2,maxpool_2,dense_1,dense_2,softmax" \
    ./PATH/TO/MODEL/tf_keras_model.h5 \
    ./PATH/TO/SAVE/DIR

Note:

  • Make sure to install tensorspacejs pip package, and setup a TensorSpace-Converter runtime environment before using TensorSpace-Converter to preprocess the pre-trained model.
  • Based on different training libraries, we provide different preprocessing tutorials: TensorFlow Tutorial, Keras Tutorial, TensorFlow.js Tutorial.
  • Checkout TensorSpace-Converter Repo for more information about TensorSpace-Converter.

Fig. 3 - TensorSpace-Converter Usage

3. Using TensorSpace to Visualize the Model

If TensorSpace is installed successfully and the pre-trained deep learning model is preprocessed, let's create an interactive 3D TensorSpace model.

For convenience, we will use the the resources from this repository's HelloWorld directory, which includes preprocessed TensorSpace compatible LeNet model and sample input data ("5") as an example to illustrate this step. All source code can be found in helloworld.html.

First, we need to new a TensorSpace model instance:

let container = document.getElementById( "container" );
let model = new TSP.models.Sequential( container );

Next, based on the LeNet structure: Input + Padding2D + 2 X (Conv2D & Maxpooling) + 3 X (Dense), build the Topology of the TensorSpace model:

model.add( new TSP.layers.GreyscaleInput() );
model.add( new TSP.layers.Padding2d() );
model.add( new TSP.layers.Conv2d() );
model.add( new TSP.layers.Pooling2d() );
model.add( new TSP.layers.Conv2d() );
model.add( new TSP.layers.Pooling2d() );
model.add( new TSP.layers.Dense() );
model.add( new TSP.layers.Dense() );
model.add( new TSP.layers.Output1d({
    outputs: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
}) );

Last, we should load our preprocessed TensorSpace compatible model and use init() method to create the TensorSpace model:

model.load({
    type: "tensorflow",
    url: './PATH/TO/MODEL/model.json'
});
model.init(function(){
    console.log("Hello World from TensorSpace!");
});

We can get the following Fig. 3 model in the browser if everything looks good.

Fig. 4 - LeNet model without any input data

We provide a extracted file which is a handwritten "5" as the input of our model: (online demo)

model.init(function() {
    model.predict( image_5 );
});

We put the predict( image_5 ) method in the callback function of init() to ensure the prediction is after the initialization complete.

Click the CodePen logo to try it in CodePen:   

Fig. 5 - LeNet model with input data "5"

Example

  • LeNet [ TensorFlow.js model ]

➡ Live Demo

Fig. 6 - Interactive LeNet created by TensorSpace

  • AlexNet [ TensorFlow model ]

➡ Live Demo

Fig. 7 - Interactive AlexNet created by TensorSpace

  • Yolov2-tiny [ TensorFlow model ]

➡ Live Demo

Fig. 8 - Interactive Yolov2-tiny created by TensorSpace

  • ResNet-50 [ Keras model ]

➡ Live Demo

Fig. 9 - Interactive ResNet-50 created by TensorSpace

  • Vgg16 [ Keras model ]

➡ Live Demo

Fig. 10 - Interactive Vgg16 created by TensorSpace

  • ACGAN [ Keras model ]

➡ Live Demo

Fig. 11 - Interactive ACGAN created by TensorSpace

  • MobileNetv1 [ Keras model ]

➡ Live Demo

Fig. 12 - Interactive MobileNetv1 created by TensorSpace

  • Inceptionv3 [ Keras model ]

➡ Live Demo

Fig. 13 - Interactive Inceptionv3 created by TensorSpace

  • LeNet Training Visualization [ TensorFlow.js dynamic model ]

Visualize the LeNet Training Process with TensorSpace.js and TensorFlow.js.

➡ Live Demo

Fig. 14 - LeNet Training 3D Visualization

View models locally

As some models above are extremely large, view them locally may be a good choice.

  • Step 1: clone TensorSpace Repo
git clone https://github.com/tensorspace-team/tensorspace.git
  • Step 2:

Open "html" file in examples folder in local web server.

Documentation

Contributors

Thanks goes to these wonderful people (emoji key):


syt123450

💻 🎨 📖 💡

Chenhua Zhu

💻 🎨 💡

YaoXing Liu

💻 🎨 💡

Qi(Nora)

💻 🎨

Dylan Schiemann

📝

BoTime

💻 📖 💡

Kamidi Preetham

📖

Wade Penistone

📖

Contact

If you have any issue or doubt, feel free to contact us by:

License

Apache License 2.0

Next Episode

TensorSpace-VR

Present Neural Network in VR

Fig. 15 - TensorSpace VR Demo

tensorspace's People

Contributors

botime avatar charlesliuyx avatar dylans avatar kageryuuu avatar lq3297401 avatar syt123450 avatar zchholmes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tensorspace's Issues

Coordinate shape of Dense layer

Try to change the single linear structure of the Dense layer to other compatible or other visual-friendly shape.

It is used to avoid the case like when we have a dense layer 4096, it is difficult to see the model compare with the length of dense layer. Camera and other auto-fitting feature may be affected.

Create documentation structure

Create tutorial documentation with proper structure
including:

  • 1. General introduction (Readme.md)
  • 2. Specific example (tf.keras) on how to preprocess models
    • 1. general introduction on model preprocessing;
    • 2. building/loading model (use LeNet as an example);
    • 3. encapsulate multiple intermediate outputs model;
    • 4. convert to tfjs compatable model;

Other examples:

  • TensorFlow (General)
  • Keras
  • TensorFlow.js

Add control for layer animation ratio

Now the animation time for layer animation is 2 seconds, this animation time may be too short or too long in some cases. Let user can configuration animation time in model configuration or in each layer configuration.

Find a way to detect layer type/class from tfjs model

From the loaded tfjs model (json+weights), we'd better to find the way to catch the layer types.

Now we can catch other configurations, such as output_shape, filter, stride etc.

If we can find the layer type/class, we can keep the process on the auto-generation from a target tfjs model for applying tsp API.

ResNet50 model

  • Preprocess ResNet50 model
  • Apply TensorSpace API to preprocessed model

Auto layer creation for tfjs model

Automatically read layer configuration from tfjs model, create and add tensorspace layers for model.

In this way, users only need to create Sequential model, do not need to create and configure the layers.

Close button configuration

Add the feature which can change the config of the close button.

Include but not limit on enable or not, displayable or not etc.

Dense layer optimization

If there is too many units in dense layer, the dense layer will be too long, we need to figure out a strategy to optimize it.

Optimize camera position

Now the camera responsive position looks a little bit weird in some cases, for example, 1 layer, 2 layers or 3 layers. Optimize camera position strategy and fix this bug.

Callback for loader

Add onComplete callback for loader. User can trigger its own function when load model complete.

Design the UI prototyle

Version 0.0 UI design draft.

  • Page structure
  • Landing page UI (Ongoing)
  • Document page UI

To be done before 09/12/2018

Remove hook system

The implementation of layer route do not need hook system any more, remove it from source code.

Merge functions for Layers

Implement merge function for Tensorspace, support all merge function in keras including:

  • Add3d
  • Substract3d
  • Multiply3d
  • Average3d
  • Maximum3d
  • Concatenate3d
  • Dot3d
  • Add2d
  • Substract2d
  • Multiply2d
  • Average2d
  • Maximum2d
  • Concatenate2d
  • Dot2d
  • Add1d
  • Substract1d
  • Multiply1d
  • Average1d
  • Maximum1d
  • Concatenate1d
  • Dot1d

Implement new function for auto-fitting shapes of different layers

To implement a function which can auto-fitting the given number of feature map centers.

It should follow the strategy like:

  1. sqrt(), if it's a perfect squre. e.g. if 1024, return 32x32;
  2. rectangle which as close as a square. e.g. if 24, return 4x6 instead of 3x8;
  3. squre/rectangle with less empty slot. e.g. if 47, return 7x7 with 2 empty slots;

Configure for opacity

The default opacity is 0.3 as Constant, support configure for opacity in layer and model.

Find a way to move camera along the model

It's too difficult to check detail if the layer is too far from the center (i.e. the layer is close to the two ends).

A proper way to move the camera along the model, or at least provide a way to visualize the layers close to both ends is necessary.

Fix hover error log

Hover on layer sometimes show error log, may be caused by last layer's status.

Supplement more layers

tensorspace API is going to support all keras layers, the layers is going to implement including:

  • conv2dTranspose
  • Cropping1d
  • Cropping2d
  • Activation1d
  • Activation2d
  • Activation3d
  • depthwiseConv2d

Add functional layer

Add function layer1d, layer2d, layer3d. Users can use these these functional layer to build any kind of layer they like.

  • layer1d
  • layer2d
  • layer3d

Construct network examples

More network examples build with Tensorspace, add interesting examples to "examples" folder:

  • Resnet 50
  • Dense net
  • Acgan generative model
  • pix2pix - Picture style transfer
  • Yolo v3-tiny
  • Mobilenet v1
  • Inceptionv3
  • SqueezeNet
  • ...

Yolo output layer

Add yolo output layer, with selectable channel to get output data from callback function.

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.