gpt4 book ai didi

hadoop - 用pyspark将图像写为序列文件的值

转载 作者:行者123 更新时间:2023-12-02 21:14:11 24 4
gpt4 key购买 nike

我正在使用pyspark编写序列文件,关键是图像文件名,值是由字节字符串表示的图像

from PIL import Image

def get_image(filename):
s = StringIO()
im=io.imread(filename)
io.imsave(s, im)
return [(filename, s)]

rdd = sc.parallelize(filenames)
rdd.flatMap(get_image).saveAsSequenceFile("/user/myname/output")

但pyspark引发异常,表明泡菜不支持该格式
Caused by: net.razorvine.pickle.InvalidOpcodeException: opcode not implemented: OBJ
at net.razorvine.pickle.Unpickler.dispatch(Unpickler.java:224)
at net.razorvine.pickle.Unpickler.load(Unpickler.java:85)
at net.razorvine.pickle.Unpickler.loads(Unpickler.java:98)
at org.apache.spark.api.python.SerDeUtil$$anonfun$pythonToJava$1$$anonfun$apply$1.apply(SerDeUtil.scala:151)
at org.apache.spark.api.python.SerDeUtil$$anonfun$pythonToJava$1$$anonfun$apply$1.apply(SerDeUtil.scala:150)
at scala.collection.Iterator$$anon$13.hasNext(Iterator.scala:371)
at scala.collection.Iterator$$anon$10.hasNext(Iterator.scala:308)
at scala.collection.Iterator$class.foreach(Iterator.scala:727)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
at scala.collection.generic.Growable$class.$plus$plus$eq(Growable.scala:48)
at scala.collection.mutable.ArrayBuffer.$plus$plus$eq(ArrayBuffer.scala:103)
at scala.collection.mutable.ArrayBuffer.$plus$plus$eq(ArrayBuffer.scala:47)
at scala.collection.TraversableOnce$class.to(TraversableOnce.scala:273)
at scala.collection.AbstractIterator.to(Iterator.scala:1157)
at scala.collection.TraversableOnce$class.toBuffer(TraversableOnce.scala:265)
at scala.collection.AbstractIterator.toBuffer(Iterator.scala:1157)
at scala.collection.TraversableOnce$class.toArray(TraversableOnce.scala:252)
at scala.collection.AbstractIterator.toArray(Iterator.scala:1157)
at org.apache.spark.rdd.RDD$$anonfun$take$1$$anonfun$28.apply(RDD.scala:1298)
at org.apache.spark.rdd.RDD$$anonfun$take$1$$anonfun$28.apply(RDD.scala:1298)
at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:1850)
at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:1850)
at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:66)
at org.apache.spark.scheduler.Task.run(Task.scala:88)
at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:214)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
... 1 more

最佳答案

当您尝试编码/解码python类/对象以进行序列化时,将使用用于腌制的OBJ操作码。就我而言,我无意将对象写入序列文件,因此对我而言,解决方法是修复该错误。

对于整个生态系统,问题在于spark uses Pyrolite 4.13直到version 4.17才引入OBJ编码/解码。至于该怎么办,我想您有几个选择:

  • 通过请求请求或github问题说服 Spark 维护者使用更高版本的Pyrolite。
  • 使用该版本的Pyrolite生成自己的Spark版本
  • 不要将类/对象写入序列文件。
  • 关于hadoop - 用pyspark将图像写为序列文件的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39286897/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com