Skip to content

Latest commit

 

History

History
81 lines (62 loc) · 4.52 KB

README.adoc

File metadata and controls

81 lines (62 loc) · 4.52 KB

TensorFlow + Infinispan + Ceph demo

The main purpose of this demo is to illustrate how to connect TensorFlow, Infinispan and Ceph. However, it also shows how to connect various parts of the application (even written in different languages) and pass the data through whole application stack using Infinispan.

Usage

The demo uses MNIST data sample. From the user perspective, user selects a test image in a custom application and once he clicks on the image, the result (which number is on the image) is immediately shown together with original image in the web application.

app

How it works

High level architecture is on the figure bellow.

demo arch

Data flow is as follows:

  • The test data sample is loaded into the simple MNIST data browser writtein in Qt/C++.

  • Upon the user click on the selected image, image is sent to the Infinispan server via REST.

  • Once the data arrives into Infinispan, custom cache event (containing image ID and its byte content) is sent to TensorFlow classifier - a separate application which contains remote Infinispan client and TF classifier itself.

  • The result is sent back to Infinispan.

  • Having the result, Infinispan notifies NodeJS application listening for the new results, which sends the result of the classification together with original image to the web brower of the user.

  • Behind the scene, Infinispan offloads the data into Ceph data store as the amount of data grows. Eviction policy is set to keep 5 most recent entries in Infispan, rest is moved into the Ceph as new data arrivies.

Setup

Prerequisities

To be able to build and run the demo, you will need following components installed:

  • TensorFlow (tested with TenforFlow 0.11)

  • javacpp-presets (tested with javacpp-presets 0.11.0-1.3.1-SNAPSHOT)

  • Qt framework (tested with Qt 5.7)

  • Infinispan server (tested with 9.0.0.Alpha4)

  • NodeJS (tested with Fedora NodeJS package nodejs-4.6.1-6)

  • Ceph (tested with Fedora Ceph packages 10.2.4-2, installed by ceph-deploy-1.5.32-2)

Preparing the data

You need to download at least test MNIST data sample (t10k-images-idx3-ubyte.gz, you can download it here), put it into /tmp/mnist/data/ and unpack. If you store it in diffrent location, just change the path in qt-sender/src/mnist/main.cpp.

Training neural network

The app also expects that the neural network is already trained and saved in TF checkpoint file. For training NN and creating checkpoint file you can use script img-classifier/src/main/python/nn2h.py. Simply run the script, it will download required data automatically. Once the NN is trained, checkpoint file is store in /tmp/my-model/nn2h.ckpt. You should see success rate of the NN on the standard output.

Building the app

You need to build following pieces:

  • Infinispan server converter in hr-server-converter by simple mvn clean package. Copy the resulting bits (target/hr-server-converter-0.0.1-SNAPSHOT.jar) into $ISPN_HOME/standalone/deployments.

  • TF classifier app in img-classifier again by simple mvn clean package

  • Build MNIST sender app in qt-sender by

mkdir build && cd build
/opt/qt/5.7/gcc_64/bin/qmake ../mnist-sender.pro
make
  • Clone Infinispan Ceph Cachestore and build it by mvn package -Puberjar. Copy the resulting bits (target/infinispan-cachestore-ceph-1.0-SNAPSHOT-jar-with-dependencies.jar) into $ISPN_HOME/standalone/deployments.

  • Download NodeJS dependencies by runing npm install in nodejs-consumer dir or wherever you want to run this app.

Configuring the app

  • Copy conf/standalone.xml into $ISPN_HOME/standalone/configuration.

  • In standalone.xml find element <store class="org.infinispan.persistence.ceph.CephStore"> and setup correct IP addres of the Ceph monitor and credentials in properties of this element.

Running the app

To avoid problems, start the pieces of the app in the following order:

  • Start Ceph data store.

  • Start Infinispan server.

  • Run TF classifier in img-classifier by java -Djava.library.path=/opt/lib/tensorflow/r0.11 -jar target/tf-ispn-classifier-0.0.1-SNAPSHOT.jar

  • Run NodeJs app

  • Run mnist-sender in qt-sender/build

  • Start the web browser and connect to http://localhost:3000