Using Tensorflow models with Java




[ad_1]

In this video, we train a model in python and use it in java. Looking into how to build TensorFlow
from the source, some new concepts in the latest code from the TensorFlow team and talk about the prediction
accuracy.

Github repository:
https://github.com/kalaspuffar/tensorflow-mnist-test

Please follow me on twitter
http://twitter.com/kalaspuffar

Learn more about machine learning at Coursera with Andrew Ng’
Machine Learning: Master the Fundamentals.
https://click.linksynergy.com/fs-bin/click?id=ohL0tLSi3XQ&offerid=759505.248&type=3&subid=0

My merchandise:
https://teespring.com/stores/daniel-persson

#tensorflow #bazel #java

Source


[ad_2]

Comment List

  • Daniel Persson
    January 12, 2021

    blessing , most people use python instead of java , but i only know java .

  • Daniel Persson
    January 12, 2021

    Can I convert LSTM-keras model to TF.lite?

  • Daniel Persson
    January 12, 2021

    What IDE are you using?

  • Daniel Persson
    January 12, 2021

    Daniel can you make course about zero to advanced on java language? (about tensorflow)

  • Daniel Persson
    January 12, 2021

    can we train a model using tensorflow java?

  • Daniel Persson
    January 12, 2021

    Do we have object detection api in java that used pre trained model?

  • Daniel Persson
    January 12, 2021

    Thanks for the tutorial! Wish there were more people making tutorials on TF with Java. There were some mistakes like unnecessary code at 20:00 where you used two arrays instead of just one, and I should point out that saving the model as binary (12:00) is a lot faster and results in a smaller file, but you really were a great help!

  • Daniel Persson
    January 12, 2021

    how do I get the height and width of the object and also its Point

  • Daniel Persson
    January 12, 2021

    Dude, it is completely false statement that you said you can't train tensorflow with Java. Please edit your video otherwise this is not going to be helpful.

    The way Java api works with training is by using a "Builder pattern": https://www.tensorflow.org/api_docs/java/reference/org/tensorflow/OperationBuilder

    You create tensors with:
    https://www.tensorflow.org/api_docs/java/reference/org/tensorflow/Tensor

    And then you add inputs/labels with the OperationBuilder .addInput method and build your graph.

    Again, using OperationBuilder you can add your initial random weights, deltas, sigmoids etc into the graph.

    Finally you feed your graph into session and train with run method:
    https://www.tensorflow.org/api_docs/java/reference/org/tensorflow/Session.Run

  • Daniel Persson
    January 12, 2021

    yo Daniel Persson I have solve the problem to load models created with tensorflow.contrib.learn.learn.DNNClassifier.

    you can check it here http://stackoverflow.com/questions/43598953/loading-sklearn-model-in-java-model-created-with-dnnclassifier-in-python

    (I found the right input using tensorboard and looking to the graph )

    (my nick there is rjpg)I have answer myself… you can give a like to my answer if you want 🙂

    I am sure a video about this will have many visualizations

  • Daniel Persson
    January 12, 2021

    hello. I was not able to load the model in java yet …

    I have created, trained and saved a tensorflow model using python

    classifier = learn.DNNClassifier(hidden_units=[10, 20, 5], n_classes=5 ,feature_columns=feature_columns ,model_dir= model_dir )

    The model files are in :

    D:javaworkspaceAPIJavaSampleCodetfModelsdnnMadelSave

    files :

    checkpoint
    events.out.tfevents.1492792287.BIRINHOS-PC
    graph.pbtxt
    model.ckpt-1.data-00000-of-00001
    model.ckpt-1.index
    model.ckpt-1.meta
    model.ckpt-100.data-00000-of-00001
    model.ckpt-100.index
    model.ckpt-100.meta

    in Java I have the line code :

    SavedModelBundle.load("D:/java/workspace/APIJavaSampleCode/tfModels/dnn/MadelSave");

    The result error is :

    Exception in thread "main" org.tensorflow.TensorFlowException: SavedModel not found in export directory: D:/java/workspace/APIJavaSampleCode/tfModels/dnn/MadelSave at org.tensorflow.SavedModelBundle.load(Native Method) at org.tensorflow.SavedModelBundle.load(SavedModelBundle.java:38) at tensorflow.HelloTF.main(HelloTF.java:32)

  • Daniel Persson
    January 12, 2021

    Hey Daniel, would you mind helping me set up a project in eclipse to get going?

  • Daniel Persson
    January 12, 2021

    This is exactly what i was looking for, Thank you verymuch.
    Its soo bad that we cant train model from java, I am looking for something to train, use model and retrain the model with feedback. 🙁

  • Daniel Persson
    January 12, 2021

    Thank you for the video I had the same problem with windows 😉

Write a comment