java - 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>
任何解决问题的帮助或对另一个图书馆的指导将不胜感激,
解决方案
当我尝试使用 DPL4J 加载我的模型时,我遇到了同样的问题。
我通过在 python 上降级 tensorflow 并重新训练我的模型解决了这个问题。然后我在Java上使用了加载的文件。
推荐阅读
- python - 无法让我的刮刀完成循环以用完所有关键字
- python - 如何使用 Numba 加速此功能?
- c++ - 从 OpenGL 应用程序中提取颜色/深度缓冲区
- android - 使用房间的动态订单
- javascript - 无法在“文档”上执行“querySelector”:“#traveller[36350015][date_of_birth(3i)]”不是有效的选择器
- ios - UICollectionView 具有可扩展评论/回复的方法
- mysql - 由于mysql数据中的无效延续字节如何捕获UnicodeDecodeError
- perl - Perl:获取(未解析的)符号链接路径
- python - 在 Python 中的相对路径上创建目录并在绝对路径中运行
- python - 在我的井字游戏中,我在哪里合并没有人赢过