Git Product home page Git Product logo

Comments (11)

lyhue1991 avatar lyhue1991 commented on May 29, 2024

提交spark任务时需要加入以下配置

--conf spark.serializer=org.apache.spark.serializer.KryoSerializer 

--conf spark.kryo.referenceTracking=true 

from eat_tensorflow2_in_30_days.

boluoyu avatar boluoyu commented on May 29, 2024

@lyhue1991 这个没有用吧,KryoSerializer 本身要求是要实现这个接口才行,SavedModelBundle 本身没有实现这个接口,即使加上了这些配置一样会报错,不知道作者是怎么做到,能否贴出来所有代码出来参考一下?

from eat_tensorflow2_in_30_days.

lyhue1991 avatar lyhue1991 commented on May 29, 2024

项目中就是全部代码呢。没有任何隐瞒。

你对KryoSerializer 的作用方式的理解可能和我有些不同。我理解它的作用是用来替代java自带的序列化方法的。--conf spark.kryo.referenceTracking=true 由于我们加了这条配置,而我们的主object有 extends Serializable这个声明,所以object下所有的变量和方法都会继承这个序列化特征。

from eat_tensorflow2_in_30_days.

ifeela avatar ifeela commented on May 29, 2024

测试过 可以用
val bundle = tf.SavedModelBundle.load(
"/Users/carol/dev/java/voiceTag/src/main/resources/models/gender_2_0.96",
"serve"
)
val conf = new SparkConf().setMaster("local").setAppName("TfRDD")
.set("spark.executor.memory", "2g")
.set("spark.executor.cores", "2")
.set("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
.set("spark.kryo.referenceTracking", "true")

val spark = SparkSession.builder().config(conf=conf).enableHiveSupport().getOrCreate()

val sc = spark.sparkContext
val broads = sc.broadcast(bundle)

val sess = broads.value.session()
val x = tf.Tensor.create(arr)
val y =  sess.runner().feed("serving_default_inputs:0", x)
  .fetch("StatefulPartitionedCall:0").run().get(0)

val result = Array.ofDim[Float](y.shape()(0).toInt,y.shape()(1).toInt)
y.copyTo(result)

from eat_tensorflow2_in_30_days.

boluoyu avatar boluoyu commented on May 29, 2024

@ifeela 多谢了,可以跑,之前设置 conf 有问题导致的

from eat_tensorflow2_in_30_days.

shuaidan0412 avatar shuaidan0412 commented on May 29, 2024

最后在集群上跑成功了么

from eat_tensorflow2_in_30_days.

boluoyu avatar boluoyu commented on May 29, 2024

最后在集群上跑成功了么

成功了

from eat_tensorflow2_in_30_days.

myelinji avatar myelinji commented on May 29, 2024

模型文件能放到集群吗?这个是不是只能本地加载模型文件?

from eat_tensorflow2_in_30_days.

16pk avatar 16pk commented on May 29, 2024

我在local模式下能够执行代码,但是在yarn-client或cluster模式下都会报java.lang.NoClassDefFoundError: Could not initialize class org.tensorflow.SavedModelBundle错误

from eat_tensorflow2_in_30_days.

boluoyu avatar boluoyu commented on May 29, 2024

@myelinji 模型文件需要下载到临时目录进行加载

from eat_tensorflow2_in_30_days.

mokundong avatar mokundong commented on May 29, 2024

local 模式下了能跑成功,在yarn cluster模式下,session.run() 会线程阻塞

from eat_tensorflow2_in_30_days.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.