kotlindl icon indicating copy to clipboard operation
kotlindl copied to clipboard

The predict method should be thread safe

Open asad-awadia opened this issue 2 years ago • 2 comments

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?

asad-awadia avatar Oct 01 '21 18:10 asad-awadia

@zaleslaw

asad-awadia avatar Oct 01 '21 18:10 asad-awadia

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.

zaleslaw avatar Oct 04 '21 09:10 zaleslaw