diff --git a/src/main/kotlin/dev/nuculabs/imagetagger/ai/ImageTagsPrediction.kt b/src/main/kotlin/dev/nuculabs/imagetagger/ai/ImageTagsPrediction.kt index 3a08e0d..383c103 100644 --- a/src/main/kotlin/dev/nuculabs/imagetagger/ai/ImageTagsPrediction.kt +++ b/src/main/kotlin/dev/nuculabs/imagetagger/ai/ImageTagsPrediction.kt @@ -12,7 +12,7 @@ import javax.imageio.ImageIO /** * ImageTagsPrediction is a specialized class that predicts an Image's tags */ -class ImageTagsPrediction private constructor() { +class ImageTagsPrediction { private val logger: Logger = Logger.getLogger("InfoLogging") private var ortEnv: OrtEnvironment = OrtEnvironment.getEnvironment() private var ortSession: OrtSession diff --git a/src/test/kotlin/ai/ImageTagsPredictionTests.kt b/src/test/kotlin/ai/ImageTagsPredictionTests.kt new file mode 100644 index 0000000..5d3a00c --- /dev/null +++ b/src/test/kotlin/ai/ImageTagsPredictionTests.kt @@ -0,0 +1,106 @@ +package ai + +import dev.nuculabs.imagetagger.ai.ImageTagsPrediction +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import java.io.File +import javax.imageio.ImageIO + +class ImageTagsPredictionTests { + private val imageTagsPrediction: ImageTagsPrediction = ImageTagsPrediction.getInstance() + + @Test + fun testPredictTagsForBufferedImage_TimisoaraBega() { + val timisoaraBega = ImageTagsPredictionTests::class.java.getResource("timisoara-bega.jpg") + val tags = imageTagsPrediction.predictTags(ImageIO.read(timisoaraBega)) + assertEquals( + listOf( + "lake", + "nature", + "no people", + "outdoors", + "reflection", + "river", + "sky", + "tranquil", + "tree", + "water" + ), tags + ) + } + + @Test + fun testPredictTagsForBufferedImage_TimisoaraThrees() { + val timisoaraBega = ImageTagsPredictionTests::class.java.getResource("timisoara-threes.jpg") + val tags = imageTagsPrediction.predictTags(ImageIO.read(timisoaraBega)) + assertEquals( + listOf("day", "forest", "growth", "nature", "no people", "outdoors", "plant", "tree"), tags + ) + } + + @Test + fun testPredictTagsForBufferedImage_TimisoaraWaterTower() { + val timisoaraBega = ImageTagsPredictionTests::class.java.getResource("timisoara-water-tower.jpg") + val tags = imageTagsPrediction.predictTags(ImageIO.read(timisoaraBega)) + assertEquals( + listOf( + "architecture", + "building exterior", + "built structure", + "day", + "history", + "no people", + "outdoors", + "travel destinations" + ), tags + ) + } + + @Test + fun testPredictTagsForInputStream_TimisoaraBega() { + val image = ImageTagsPredictionTests::class.java.getResource("timisoara-bega.jpg") + val tags = imageTagsPrediction.predictTags(File(image!!.toURI()).inputStream()) + assertEquals( + listOf( + "lake", + "nature", + "no people", + "outdoors", + "reflection", + "river", + "sky", + "tranquil", + "tree", + "water" + ), tags + ) + } + + @Test + fun testPredictTagsForInputStream__TimisoaraThrees() { + val image = ImageTagsPredictionTests::class.java.getResource("timisoara-threes.jpg") + val tags = imageTagsPrediction.predictTags(File(image!!.toURI()).inputStream()) + assertEquals( + listOf("day", "forest", "growth", "nature", "no people", "outdoors", "plant", "tree"), tags + ) + } + + @Test + fun testPredictTagsForInputStream_TimisoaraWaterTower() { + val image = ImageTagsPredictionTests::class.java.getResource("timisoara-water-tower.jpg") + val tags = imageTagsPrediction.predictTags(File(image!!.toURI()).inputStream()) + assertEquals( + listOf( + "architecture", + "building exterior", + "built structure", + "day", + "history", + "no people", + "outdoors", + "travel destinations" + ), tags + ) + } + +} \ No newline at end of file diff --git a/src/test/resources/ai/timisoara-bega.jpg b/src/test/resources/ai/timisoara-bega.jpg new file mode 100644 index 0000000..daf59ac Binary files /dev/null and b/src/test/resources/ai/timisoara-bega.jpg differ diff --git a/src/test/resources/ai/timisoara-threes.jpg b/src/test/resources/ai/timisoara-threes.jpg new file mode 100644 index 0000000..b18dbf7 Binary files /dev/null and b/src/test/resources/ai/timisoara-threes.jpg differ diff --git a/src/test/resources/ai/timisoara-water-tower.jpg b/src/test/resources/ai/timisoara-water-tower.jpg new file mode 100644 index 0000000..b4777ab Binary files /dev/null and b/src/test/resources/ai/timisoara-water-tower.jpg differ