Skip to content

Commit

Permalink
Add support for yolov8.
Browse files Browse the repository at this point in the history
  • Loading branch information
litan committed Oct 14, 2024
1 parent 177c823 commit 86dba5f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/main/scala/net/kogics/kojo/aiapp/ObjectDetector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ import scala.util.Using
import ai.djl.modality.cv.output.DetectedObjects
import ai.djl.modality.cv.Image
import ai.djl.repository.zoo.Criteria
import org.bytedeco.javacv.Java2DFrameUtils
import org.bytedeco.opencv.opencv_core.Mat

class ObjectDetector(modelDir: String) {
val (model, predictor) = {
println("Loading 'object detection' model...")
val translatorFactory = modelDir match {
case s if s.contains("yolov5") => new ai.djl.modality.cv.translator.YoloV5TranslatorFactory()
case s if s.contains("yolov8") => new ai.djl.modality.cv.translator.YoloV8TranslatorFactory()
case _ => throw new RuntimeException("Unknown object detection model")
}

import scala.jdk.CollectionConverters._
val args: Map[String, AnyRef] = Map(
Expand All @@ -22,15 +26,15 @@ class ObjectDetector(modelDir: String) {
"resize" -> Boolean.box(true),
"rescale" -> Boolean.box(true),
"optApplyRatio" -> Boolean.box(true),
"threshold" -> Double.box(0.4),
"threshold" -> Double.box(0.6),
)

val criteria =
Criteria
.builder()
.setTypes(classOf[Image], classOf[DetectedObjects])
.optModelPath(Paths.get(modelDir))
.optTranslatorFactory(new ai.djl.modality.cv.translator.YoloV5TranslatorFactory())
.optTranslatorFactory(translatorFactory)
.optArguments(args.asJava)
.build()

Expand Down

0 comments on commit 86dba5f

Please sign in to comment.