首页 > 解决方案 > deeplearning4j 预期的模型类名 Model(找到 Functional)

问题描述

deeplearning4j 返回“预期的模型类名称模型(发现功能)。” 尝试加载 keras 模型时。当尝试按顺序加载它时也会发生同样的情况。

Python :

from tensorflow.keras.applications.resnet50 import ResNet50
from tensorflow.keras.preprocessing import image
from tensorflow.keras.applications.resnet50 import preprocess_input, decode_predictions
import numpy as np
model = ResNet50(weights='imagenet')
model.save("resnet50.h5")

爪哇(弹簧)

public INDArray useModel(String name, Long id) throws Exception{
    File file= new File("src/main/uploads/image.jpg");
    String resnet = "src/main/uploads/model/resnet50.h5";
    ComputationGraph model = KerasModelImport.importKerasModelAndWeights(resnet);
    NativeImageLoader loader = new NativeImageLoader(224, 224, 3);
    INDArray image = loader.asMatrix(file);
    INDArray[] output = model.output(image);
    return output[0];

}

mavn 部门:

<dependency>
        <groupId>org.deeplearning4j</groupId>
        <artifactId>deeplearning4j-modelimport</artifactId>
        <version>1.0.0-beta7</version>
    </dependency>
    <dependency>
        <groupId>org.deeplearning4j</groupId>
        <artifactId>deeplearning4j-core</artifactId>
        <version>1.0.0-beta7</version>
    </dependency>
    <dependency>
        <groupId>org.nd4j</groupId>
        <artifactId>nd4j-native-platform</artifactId>
        <version>1.0.0-beta7</version>
    </dependency>
    <dependency>
        <groupId>org.datavec</groupId>
        <artifactId>datavec-data-image</artifactId>
        <version>1.0.0-beta7</version>
    </dependency>

任何解决问题的帮助或对另一个图书馆的指导将不胜感激,

标签: javaspringtensorflowkerasdeeplearning4j

解决方案


当我尝试使用 DPL4J 加载我的模型时,我遇到了同样的问题。

我通过在 python 上降级 tensorflow 并重新训练我的模型解决了这个问题。然后我在Java上使用了加载的文件。


推荐阅读