add tests for ImageTagsPrediction
This commit is contained in:
parent
80dd84d657
commit
ac7615356f
5 changed files with 107 additions and 1 deletions
|
@ -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
|
||||
|
|
106
src/test/kotlin/ai/ImageTagsPredictionTests.kt
Normal file
106
src/test/kotlin/ai/ImageTagsPredictionTests.kt
Normal file
|
@ -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
|
||||
)
|
||||
}
|
||||
|
||||
}
|
BIN
src/test/resources/ai/timisoara-bega.jpg
Normal file
BIN
src/test/resources/ai/timisoara-bega.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.6 MiB |
BIN
src/test/resources/ai/timisoara-threes.jpg
Normal file
BIN
src/test/resources/ai/timisoara-threes.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 724 KiB |
BIN
src/test/resources/ai/timisoara-water-tower.jpg
Normal file
BIN
src/test/resources/ai/timisoara-water-tower.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 MiB |
Loading…
Reference in a new issue