deepjavalibrary / djl

An Engine-Agnostic Deep Learning Framework in Java
https://djl.ai
Apache License 2.0
4.07k stars 650 forks source link

Unable to create NDList from NDArray inside Mutable Map #2346

Closed AbhishekBose closed 1 year ago

AbhishekBose commented 1 year ago

Hello Team, As seen in the picture below Screenshot 2023-01-26 at 2 36 38 AM

I have the variable called resultMap which contains a key called resized_img with the value being a resized NDArray. Now in my processInput I am trying to take this array and put in an NDList for the inference to happen, in this manner

override def processInput(ctx: TranslatorContext, input: Map[String,Any]): NDList = {
    val resultMap: Map[String,Any] = preProcessor.apply(input, ctx, false);
    val result = new NDList(resultMap.get("resized_img").asInstanceOf[NDArray])
    result
  }

But I am constantly getting the following error java.lang.ClassCastException: scala.Some cannot be cast to ai.djl.ndarray.NDArray

And If I don't put an explicit asInstanceOf the new NDList() call doesn't except the value.

How do you recommend we do this?

The idea is to always have a map containing String, [Different types] and then create the NDList dynamically before moving in for the inference.

@frankfliu Please help

frankfliu commented 1 year ago

Can you print out the class name of resultMap.get("resized_img") before you cast it to NDArray? It looks like your resultMap.get("resized_img") returns scala.Some, should you call resultMap.get("resized_img").get() before cast?

github-actions[bot] commented 1 year ago

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.