-
Hi, I want to validate a number of models and pick the best one, here's how my scala code looks like: lazy val features: NDList
val classifier: AbstractBlock
val parentDir: File
private def evaluateModel(subdirectory: File) =
Using(Model newInstance "TimeSeriesClassifier") { model =>
val path = Path.of(subdirectory.getAbsolutePath)
model.setBlock(classifier)
model.load(path)
Using(this getPredictor model) { predictor =>
val predictions = predictor.predict(features).head
(doEvaluate(predictions, subdirectory), subdirectory)
}
}
def bestModelFile: (Double, File) =
parentDir.listFiles.toList
.filter(_.isDirectory)
.map(evaluateModel)
.map(_.get.get)
.maxBy(_._1) Basically The problem is that memory usage grows very fast and program soon crashes with out of memory error, it looks like each model resources are kept in place despite it being closed on each method call. Any hints on how this can be fixed? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I was able to pin it down further, here's a simplified code: val model = Model.newInstance("TimeSeriesClassifier")
val path = Path.of(dir + "200/")
model.setBlock(classifier)
model.load(path)
val predictor = model.newPredictor(new NoopTranslator, Device.cpu)
val features = list.get(0).toType(DataType.FLOAT32, false).get("-40:").asNDList
predictor.predict(features)
predictor.predict(features)
predictor.predict(features)
predictor.predict(features)
predictor.predict(features)
predictor.predict(features)
predictor.predict(features)
predictor.close()
model.close()
Thread.sleep(10000) That row of |
Beta Was this translation helpful? Give feedback.
-
Turned out I should also close a |
Beta Was this translation helpful? Give feedback.
Turned out I should also close a
manager
which is used to create afeatures
NDList. My solution is to create a submanager for each iteration and then close it once prediction is obtained.