kotlindl
kotlindl copied to clipboard
The predict method should be thread safe
val modelHub =
TFModelHub(cacheDirectory = File("cache/pretrainedModels"))
val model = modelHub[TFModels.CV.ResNet50]
model.use {
for (i in 1..8) {
val imageFile = getFileFromResource("datasets/vgg/image$i.jpg")
val recognizedObject = it.predictObject(imageFile = imageFile)
println(recognizedObject)
val top5 = it.predictTopKObjects(imageFile = imageFile, topK = 5)
println(top5.toString())
}
}
Is the predict* function thread safe?
@zaleslaw
I suggest thinking that this is not a thread-safe method and the whole model. We are planning to work on it in the 0.5-0.6 releases and write in docs about thread-safety guarantees.
Also, we could use under the hood different runtimes with different thread-safety in the proposed low-level API and need to protect it against race conditions on the framework level.