'not able to use ai.djl.modality.cv.util.BufferedImageUtils in my application
I am new to AI technology .I dded every DJL which are required to my project . But when I go to use ai.djl.modality.cv.util.BufferedImageUtils. I am not able to import it in my project.It show me an error create local variable BuffredImageUtils.
Unresolved reference: BufferedImageUtils
here all my graddle depedency I added in my Project
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.springframework.boot") version "2.5.4"
id("io.spring.dependency-management") version "1.0.11.RELEASE"
kotlin("jvm") version "1.5.21"
kotlin("plugin.spring") version "1.5.21"
}
group = "com.main"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_11
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
implementation("org.springframework.boot:spring-boot-starter-web")
// https://mvnrepository.com/artifact/commons-io/commons-io
implementation("commons-io:commons-io:2.6")
// https://mvnrepository.com/artifact/ai.djl/api
implementation("ai.djl:api:0.9.0")
// https://mvnrepository.com/artifact/ai.djl.tensorflow/tensorflow-api
implementation("ai.djl.tensorflow:tensorflow-api:0.9.0")
// https://mvnrepository.com/artifact/ai.djl.tensorflow/tensorflow-engine
implementation("ai.djl.tensorflow:tensorflow-engine:0.9.0")
// https://mvnrepository.com/artifact/net.java.dev.jna/jna
implementation("net.java.dev.jna:jna:5.8.0")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
// https://mvnrepository.com/artifact/ai.djl.tensorflow/tensorflow-native-auto
runtimeOnly("ai.djl.tensorflow:tensorflow-native-auto:2.3.1")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "11"
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
DJLConfig.kt
package com.main.xrayaiapplication.config
import ai.djl.modality.Classifications
import ai.djl.modality.cv.util.NDImageUtils
import ai.djl.ndarray.NDArray
import ai.djl.ndarray.NDList
import ai.djl.translate.Batchifier
import ai.djl.translate.Translator
import ai.djl.translate.TranslatorContext
import org.springframework.context.annotation.Configuration
import java.awt.image.BufferedImage
@Configuration
class DjlConfig{
class XrayTranslator: Translator<BufferedImage,Classifications> {
override fun processInput(ctx: TranslatorContext?, input: BufferedImage?): NDList {
var array: NDArray? = BufferedImageUtils.toNDArray(
ctx.ndManager, input, NDImageUtils.Flag.COLOR
)
array = NDImageUtils.resize(array, 224).div(255.0f)
return NDList(array)
}
override fun processOutput(ctx: TranslatorContext?, list: NDList?): Classifications {
TODO("Not yet implemented")
}
override fun getBatchifier(): Batchifier {
TODO("Not yet implemented")
}
}
}
I get error exact at this line
var array: NDArray? = BufferedImageUtils.toNDArray(
Not able to access the DJL AI features , and contents
Solution 1:[1]
The BufferedImageUtils
has been removed in newer version fo DJL api. You need to use ImageFactory
instead:
ImageFactory factory = ImageFactory.getInstance();
# Image image = factory.fromFile(Paths.get("..."));
# Image image = factory.fromUrl("...");
Image image = factory.fromImage(bufferedImage);
NDArray array = image.toNDArray(ctx.getManager());
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Frank Liu |