deepjavalibrary / djl

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

issue while loading paddlezoo MobileNetV3 (params issue) #1176

Closed hakmesyo closed 3 years ago

hakmesyo commented 3 years ago

Description

According to the https://docs.djl.ai/master/docs/paddlepaddle/how_to_create_paddlepaddle_model.html, i would like to utilize mobilenetv3. I download the model and then zip folder mobilenet including two files "models and params" as mobilenet.zip. Then i provide the zip path in my os and give the mobilenet as

        Criteria<Image, Classifications> criteria;
        try {
            translator = ImageClassificationTranslator.builder()
                    .addTransform(new Resize(IMAGE_WIDTH, IMAGE_HEIGHT))
                    .addTransform(new ToTensor()) // HWC -> CHW div(255)
                    .addTransform(
                            new Normalize(
                                    new float[]{0.5f, 0.5f, 0.5f},
                                    new float[]{1.0f, 1.0f, 1.0f}))
                    .addTransform(nd -> nd.flip(0)) // RGB -> GBR
                    .build();
            criteria = Criteria.builder()
                    .optApplication(Application.CV.IMAGE_CLASSIFICATION)
                    .setTypes(Image.class, Classifications.class)
                    .optModelPath(Paths.get("models/mobilenet.zip"))
                    .optModelName("mobilenet")
                    .optTranslator(translator)
                    .build();
            model = criteria.loadModel();

at criteria.loadModel() something went wrong and exception was raised

java.io.FileNotFoundException: Parameter file with prefix: 58cef0a19dbf1b67648f54a5cfa5df2d not found in: C:\Users\cezerilab.djl.ai\cache\repo\model\undefined\ai\djl\localmodelzoo\58cef0a19dbf1b67648f54a5cfa5df2d

how can i resolve this issue? Parameter file with prefix means actually what?

Thanks for your cooperations.

Regards.

Expected Behavior

(what's the expected behavior?)

Error Message

Ağu 19, 2021 11:25:05 PM cezeri.matrix.CMatrix setModelForInference SEVERE: null java.io.FileNotFoundException: Parameter file with prefix: 58cef0a19dbf1b67648f54a5cfa5df2d not found in: C:\Users\cezerilab.djl.ai\cache\repo\model\undefined\ai\djl\localmodelzoo\58cef0a19dbf1b67648f54a5cfa5df2d at ai.djl.mxnet.engine.MxModel.load(MxModel.java:98) at ai.djl.repository.zoo.BaseModelLoader.loadModel(BaseModelLoader.java:156) at ai.djl.repository.zoo.Criteria.loadModel(Criteria.java:174) at cezeri.matrix.CMatrix.setModelForInference(CMatrix.java:8959) at cezeri.deep_learning.ai.djl.examples.denemeler.CMatrixPattern.predictPistachioWithMobileNetV3(CMatrixPattern.java:380) at cezeri.deep_learning.ai.djl.examples.denemeler.CMatrixPattern.main(CMatrixPattern.java:42)

Exception in thread "main" java.lang.NullPointerException at cezeri.matrix.CMatrix.predictWithLabel(CMatrix.java:9022) at cezeri.deep_learning.ai.djl.examples.denemeler.CMatrixPattern.predictPistachioWithMobileNetV3(CMatrixPattern.java:387) at cezeri.deep_learning.ai.djl.examples.denemeler.CMatrixPattern.main(CMatrixPattern.java:42) C:\Users\cezerilab\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1 BUILD FAILED (total time: 2 seconds)

How to Reproduce?

(If you developed your own code, please provide a short script that reproduces the error. For existing examples, please provide link.)

Steps to reproduce

(Paste the commands you ran that produced the error.)

1. 2.

What have you tried to solve it?

1. 2.

Environment Info

Please run the command ./gradlew debugEnv from the root directory of DJL (if necessary, clone DJL first). It will output information about your system, environment, and installation that can help us debug your issue. Paste the output of the command below:

PASTE OUTPUT HERE
frankfliu commented 3 years ago

You need specify engine in your criteria:

criteria = Criteria.builder()
                    .setTypes(Image.class, Classifications.class)
                    .optEngine("PaddlePaddle")
                    .optModelPath(Paths.get("models/mobilenet.zip"))
                    .optModelName("mobilenet")
                    .optTranslator(translator)
                    .build();

In your class path, you included MXNet and PaddlePaddle, MXNet is the default engine. criteria will try to use MXNet to load the model if you didn't specify engine in the criteria

hakmesyo commented 3 years ago

Thanks frankfliu very much,

Almost previous problem was addressed. But now i encounter another error messages and i dont know why this occur. Appreciate your help. Below error messages were thrown when i call predictor.predict command in

public String predictWithLabel() {
    Image img = ImageFactory.getInstance().fromImage(this.image);
    Classifications predictResult = null;
    try {
        predictResult = predictor.predict(img);
    } catch (TranslateException ex) {
        Logger.getLogger(CMatrix.class.getName()).log(Level.SEVERE, null, ex);
    }
    String predictedLabel = predictResult.topK(1).toString().split(",")[0].split(":")[1].replace('"', ' ').trim();
    return predictedLabel;
}

Regards.

SEVERE: null ai.djl.translate.TranslateException: ai.djl.engine.EngineException: MXNet engine call failed: MXNetError: Check failed: param.size[0] > 0 (0 vs. 0) : Input width should be greater than 0, but got 0

Stack trace: File "C:\Users\Administrator\kimbergz\b4\src\operator\image./resize-inl.h", line 100

at ai.djl.inference.Predictor.batchPredict(Predictor.java:170)
at ai.djl.inference.Predictor.predict(Predictor.java:118)
at cezeri.matrix.CMatrix.predictWithLabel(CMatrix.java:9023)
at cezeri.deep_learning.ai.djl.examples.denemeler.CMatrixPattern.predictPistachioWithMobileNetV3(CMatrixPattern.java:387)
at cezeri.deep_learning.ai.djl.examples.denemeler.CMatrixPattern.main(CMatrixPattern.java:42)

Caused by: ai.djl.engine.EngineException: MXNet engine call failed: MXNetError: Check failed: param.size[0] > 0 (0 vs. 0) : Input width should be greater than 0, but got 0 Stack trace: File "C:\Users\Administrator\kimbergz\b4\src\operator\image./resize-inl.h", line 100

at ai.djl.mxnet.jna.JnaUtils.checkCall(JnaUtils.java:1930)
at ai.djl.mxnet.jna.JnaUtils.imperativeInvoke(JnaUtils.java:519)
at ai.djl.mxnet.jna.FunctionInfo.invoke(FunctionInfo.java:72)
at ai.djl.mxnet.engine.MxNDManager.invoke(MxNDManager.java:325)
at ai.djl.mxnet.engine.MxNDManager.invoke(MxNDManager.java:343)
at ai.djl.mxnet.engine.MxNDArrayEx.resize(MxNDArrayEx.java:887)
at ai.djl.modality.cv.util.NDImageUtils.resize(NDImageUtils.java:63)
at ai.djl.modality.cv.transform.Resize.transform(Resize.java:63)
at ai.djl.translate.Pipeline.transform(Pipeline.java:171)
at ai.djl.modality.cv.translator.BaseImageTranslator.processInput(BaseImageTranslator.java:84)
at ai.djl.modality.cv.translator.BaseImageTranslator.processInput(BaseImageTranslator.java:42)
at ai.djl.inference.Predictor.processInputs(Predictor.java:200)
at ai.djl.inference.Predictor.batchPredict(Predictor.java:160)
... 4 more

Exception in thread "main" java.lang.NullPointerException at cezeri.matrix.CMatrix.predictWithLabel(CMatrix.java:9027) at cezeri.deep_learning.ai.djl.examples.denemeler.CMatrixPattern.predictPistachioWithMobileNetV3(CMatrixPattern.java:387) at cezeri.deep_learning.ai.djl.examples.denemeler.CMatrixPattern.main(CMatrixPattern.java:42) C:\Users\cezerilab\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1 BUILD FAILED (total time: 1 second)

frankfliu commented 3 years ago

@hakmesyo It looks like you provided an invalid image, the image size is 0x0

hakmesyo commented 3 years ago

yes but when i debug the project

Image img = ImageFactory.getInstance().fromImage(this.image);

this.image is valid and it is a type of BufferedImage and i can visualize it. And img also has width and height values different from 0x0

you can see it below

image

frankfliu commented 3 years ago

Can you check what size you are resizing to ?

hakmesyo commented 3 years ago

Huge thanks, i made a mistake on resize method as you mentioned, and now when i fixed it everything run well.

hakmesyo commented 3 years ago

issue is resolved