Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to inference tensorflow model in spark? #3

Open
harryprince opened this issue Jul 7, 2019 · 2 comments
Open

How to inference tensorflow model in spark? #3

harryprince opened this issue Jul 7, 2019 · 2 comments

Comments

@harryprince
Copy link

harryprince commented Jul 7, 2019

https://github.com/yahoo/TensorFlowOnSpark/wiki/Scala-Inference-API#inference-via-tfos-scala-api

References

@harryprince
Copy link
Author

harryprince commented Jul 12, 2019

predict tfrecord mode

import com.yahoo.tensorflowonspark.Inference

var conf = Inference.Config(export_dir: String = "${TFoS_HOME}/mnist_export",
                    input: String = "${TFoS_HOME}/mnist/tfr/test",
                    schema_hint: StructType = new StructType(struct<image:array<float>,label:array<float>>),
                    input_mapping: Map[String, String] = {"image": "inputs/x", "label": "inputs/y_"},
                    output_mapping: Map[String, String] = {"prediction": "prediction", "layer/hidden_layer/Relu": "features"},
                    output: String = "${TFoS_HOME}/predictions",
                    verbose: Boolean = false)

Inference.run(sc, conf)

@harryprince
Copy link
Author

harryprince commented Jul 12, 2019

predict data.frame mode

config.export_dir means model file path

import com.yahoo.tensorflowonspark.TFModel

    val model = new TFModel().setModel(config.export_dir)
                              .setInputMapping(config.input_mapping)
                              .setOutputMapping(config.output_mapping)

    // transform the input DataFrame
    // Note: we're currently dropping input columns for simplicity, you can retrieve them as Tensors if needed.
    val predDF = model.transform(df)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant