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

Tensorflow can support pyspark API...? #90

Closed
srinivasugaddam opened this issue Jun 9, 2018 · 2 comments · Fixed by #92
Closed

Tensorflow can support pyspark API...? #90

srinivasugaddam opened this issue Jun 9, 2018 · 2 comments · Fixed by #92

Comments

@srinivasugaddam
Copy link

Hi,
may i know the Tensorflow can support pyspark API...? i it's supports please provide me the connector.
thanks,
srinivas.

@skavulya
Copy link
Contributor

Thanks @joyeshmishra!

@srinivasugaddam Here is a short example of how to use the connector with PySpark.

Run PySpark with the spark_connector in the jars argument as shown below:

$SPARK_HOME/bin/pyspark --jars target/spark-connector_2.11-1.8.0.jar

Here is the README example translated to Python.

from pyspark.sql.types import *

path = "test-output.tfrecord"

fields = [StructField("id", IntegerType()), StructField("IntegerCol", IntegerType()), StructField("LongCol", LongType()), StructField("FloatCol", FloatType()), StructField("DoubleCol", DoubleType()), StructField("VectorCol", ArrayType(DoubleType(), True)), StructField("StringCol", StringType())]
schema = StructType(fields)

test_rows = [[11, 1, 23, 10.0, 14.0, [1.0, 2.0], "r1"], [21, 2, 24, 12.0, 15.0, [2.0, 2.0], "r2"]]
rdd = spark.sparkContext.parallelize(test_rows)
df = spark.createDataFrame(rdd, schema)
df.write.format("tfrecords").option("recordType", "Example").save(path)

df = spark.read.format("tfrecords").option("recordType", "Example").load(path)
df.show()

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

Successfully merging a pull request may close this issue.

3 participants