deeplearning4j预期的模型类名model(找到Functional)



深度学习4j返回"需要模型类名model(找到Functional("当尝试加载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")

java(spring(

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-deps:

<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>

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

当我试图使用DPL4J加载我的模型时,无论是功能性的还是序列性的,我都遇到了同样的问题。

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

相关内容

最新更新