如何解决deeplearning4j期望的模型类名称Model发现Functional
deeplearning4j返回“预期的模型类名称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部门:
<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上使用了加载的文件。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。