1

我正在尝试在使用 Spark 和 HDFS 的 Scala 项目中使用Smile。为了模型的可重用性,我需要将它们写入 HDFS。

现在我正在使用写入对象,预先检查路径是否存在,如果不存在则创建它(否则它会抛出 FileNotFoundException):

import java.nio.file.Paths

val path: String = "hdfs:/my/hdfs/path"
val outputPath: Path = Paths.get(path)
val outputFile: File = outputPath.toFile
if(!outputFile.exists()) {
  outputFile.getParentFile().mkdirs();  // This is a no-op if it exists
  outputFile.createNewFile();
}
write(mySmileModel, path)

但这会在本地创建路径“hdfs:/my/hdfs/path”并将模型写入其中,而不是实际写入 HDFS。
请注意,使用 spark 模型及其保存方法有效:

mySparkModel.save("hdfs:/my/hdfs/path")

因此我的问题是:如何将微笑模型写入 HDFS?
同样,如果我设法将模型写入 HDFS,我可能还会想知道如何从 HDFS 读取模型。

谢谢!

4

0 回答 0