Package: tensorcraft
TensorCraftThe TensorCraft is a HTTP server that servesKerasmodels using TensorFlow runtime.Currently TensorCraft is in beta, client and server API may change in the
future versions.This server solves such problems as:Versioning of models.Warehousing of models.Enabling CI/CD for machine-learning models.InstallationInstallation Using SnapThis is the recommended way to installtensorcraft. Simply run the following
command:snapinstalltensorcraft--devmode--edge
snapstarttensorcraftInstallation Using DockerTensorCraft can be used as a Docker container. The major note on this approach is
thattensorflowlibrary that is installed into the Docker image is not compiled
with support of AVX instructions or GPU.dockerpullnetrack/tensorcraft:latestIn order to start the container, run the following command:dockerrun-it-p5678:5678/tcpnetrack/tensorcraftYou can optinally specify volume to persist models between restarts of conatiner:dockerrun-it-p5678:5678/tcp-vtensorcraft:/var/run/tensorcraftnetrack/tensorcraftInstallation Using PyPiInstall latest version from pypi repository.pipinstalltensorcraftUsing TensorCraftKeras RequirementsOne of the possible ways of usingtensorcraftis publising model snapshots to
the server on each epoch end.fromkeras.modelsimportSequentialfromkeras.layersimportDense,Activationfromtensorcraft.callbacksimportModelCheckpointmodel=keras.Sequential()model.add(Dense(32,input_dim=784))model.add(Activation('relu'))model.compile(optimizer='sgd',loss='binary_crossentropy')model.fit(x_train,y_train,callbacks=[ModelCheckpoint(verbose=1)],epochs=100)Currently,tensorcraftsupports only models in the TensorFlow Saved Model, therefore
in order to publish Keras model, it must be saved as Saved Model at first.Considering the following Keras model:fromtensorflowimportkerasfromtensorflow.kerasimportlayersinputs=keras.Input(shape=(8,),name='digits')x=layers.Dense(4,activation='relu',name='dense_1')(inputs)x=layers.Dense(4,activation='relu',name='dense_2')(x)outputs=layers.Dense(2,activation='softmax',name='predictions')(x)model=keras.Model(inputs=inputs,outputs=outputs,name='3_layer_mlp')Save it using theexport_saved_modelfunction from the 2.0 TensorFlow API:keras.experimental.export_saved_model(model,"3_layer_mlp")Starting ServerTo start server runservercommand:sudotensorcraftserverBy default it starts listeningunsecuredport on localhost athttp://localhost:5678.Default configuration saves models to/var/lib/tensorcraftdirectory. Apart of
that server requires access to/var/rundirectory in order to save pid file
there.Pushing New ModelNote, both client and server oftensorcraftapplication share the same code
base. This implies the need to install a lot of server dependencies for a
client. This will be improved in uncoming versions.Once model saved in directory, pack it usingtarutility. For instance, this
is how it will look like for3_layer_mlpmodel from the previous example:tar-cf3_layer_mlp.tar3_layer_mlpNow the model packed into the archive can be pushed to the server under the
arbitrary tag:tensorcraftpush--name3_layer_mlp--tag0.0.13_layer_mlp.tarListing Available ModelsYou can list all available models on the server using the following command:tensorcraftlistAfter the execution oflistcommand you'll see to available models:3_layer_mlp:0.0.1
3_layer_mlp:latestThis is the features oftensorcraftserver, each published model name results in
creation ofmodel group. Each model group has it'slatesttag, that references
thelatest pushed model.Removing ModelRemove of the unused model can be performed in usingremovecommand:tensorcraftremove--name3_layer_mlp--tag0.0.1Execution ofremovecommands results in the remove of the model itself, and
the model group, when is is the last model in the group.Using ModelIn order to use the pushed model,tensorcraftexposes REST API. An example query
to the server looks like this:curl-XPOSThttps://localhost:5678/models/3_layer_mlp/0.0.1/predict-d\'{"x": [[1.0, 2.1, 1.43, 4.43, 12.1, 3.2, 1.44, 2.3]]}'LicenseThe code and docs are released under theApache 2.0 license.