我在 Scala 中有一個示例代碼庫,我使用 OpenCV 和 ScalaPy 進行一些影像分類。這是代碼位:
def loadImage(imagePath: String): Image = {
// 0. Load the image and extract class label where a path to the image is assumed to be
// /path/to/dataset/{class}/{image}.jpg
val matrix: Mat = imread(imagePath)
val label = imagePath.split("")
// 1. Run the loaded image through the preprocessors, resulting in a feature vector
//val preProcessedImagesWithLabels = Seq(new ImageResizePreProcessor(appCfg)).map(preProcessor => (preProcessor.preProcess(matrix), label))
val preProcessedImagesWithLabels = Seq(new ImageResizePreProcessor(appCfg)).map(preProcessor => preProcessor.preProcess(matrix))
np.asarray(preProcessedImagesWithLabels)
}
然而,它失敗的原因是它找不到 NumPy 的隱式轉換器:
[error] /home/joesan/Projects/Private/ml-projects/object-classifier/src/main/scala/com/bigelectrons/animalclassifier/ImageLoader.scala:10:34: not found: type NumPy
[error] val np = py.module("numpy").as[NumPy]
除了進口還有什么預期?
"me.shadaj" %% "scalapy-numpy" % "0.1.0",
"me.shadaj" %% "scalapy-core" % "0.5.0",
uj5u.com熱心網友回復:
嘗試使用最新的“開發”版本的 scalapy-numpy: 0.1.0 6-14ca0424
因此,更改 sbt 構建:
libraryDependencies = "me.shadaj" %% "scalapy-numpy" % "0.1.0 6-14ca0424"
我嘗試使用菊石這個腳本:
import me.shadaj.scalapy.numpy.NumPy
import me.shadaj.scalapy.py
val np = py.module("numpy").as[NumPy]
它似乎找到了NumPy預期的
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/344678.html
