我在 java 上遇到了一个关于 tf 的小问题。我用 python(1.8.0 版)重新训练了我的新类别模型,我试图用 Java(Intellij、Maven 项目、Tensorflow 1.1.0 版)识别图像,我收到以下错误。
java.lang.IllegalArgumentException: NodeDef mentions attr 'dilations' not in Op<name=Conv2D; signature=input:T, filter:T -> output:T; attr=T:type,allowed=[DT_HALF, DT_FLOAT, DT_DOUBLE]; attr=strides:list(int); attr=use_cudnn_on_gpu:bool,default=true; attr=padding:string,allowed=["SAME", "VALID"]; attr=data_format:string,default="NHWC",allowed=["NHWC", "NCHW"]>; NodeDef: module_apply_default/InceptionV3/InceptionV3/Conv2d_1a_3x3/Conv2D = Conv2D[T=DT_FLOAT, data_format="NHWC", dilations=[1, 1, 1, 1], padding="VALID", strides=[1, 2, 2, 1], use_cudnn_on_gpu=true](module_apply_default/hub_input/Sub, module_apply_default/InceptionV3/InceptionV3/Conv2d_1a_3x3/Conv2D/ReadVariableOp). (Check whether your GraphDef-interpreting binary is up to date with your GraphDef-generating binary.).
我将 Maven 中的 tf 版本更改为 1.8.0,以便与 python 版本相同,然后我得到了这个
java.lang.IllegalArgumentException: No Operation named [DecodeJpeg/contents] in the Graph
代码行: Tensor result = s.runner().feed("DecodeJpeg/contents", image).fetch("softmax").run().get(0)) { h
当我使用 2015 年 12 月的预训练初始模型图而不是我的时,一切都运行顺利,没有错误。有谁知道这里发生了什么,我该如何解决?我真的很感激任何答案:D 谢谢!
从错误消息中,这就是我收集的信息:
使用 1.8.0 创建模型但使用 1.1.0 加载模型失败并显示Check whether your GraphDef-interpreting binary is up to date with your GraphDef-generating binary.
错误,因为 1.8.0 二进制文件保存的图形使用了 1.1.0 以外的功能。因此,您应该让 Java 程序使用与生成图形的二进制文件相同或更高版本的 TensorFlow。
第二条错误消息表明模型中输入张量的名称与预训练模型中的名称不同。您想DecodeJpeg/contents
用适当的名称替换Java 程序中的字符串。很难说它会是什么,因为这取决于你的程序的细节。但是,如果您能找出在 Python 中提供给feed_dict
参数的张量的名称Session.run
,那么这就是您在 Java 中提供的名称。
希望有帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句