tensorflow / tensorflow/java

Unexpected problem in creating a tensor on saved model session.

未关闭
#397 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Java
星标
928
派生
227
PR 合并指标
30 天内没有已合并 PR

描述

System information

  • OS Platform and Distribution: Linux Ubuntu 20.04 x64
  • TensorFlow installed from: pip for Python 3.9; Maven for Java
  • TensorFlow version : 2.7.0 on Python; 0.3.3 on Java
  • Java version : openjdk 11.0.11 2021-04-20
  • Python version : 3.9
  • CUDA/cuDNN version: cuda_11.5.r11.5/compiler.30411180_0
  • GPU model and memory: Nvidia Geforce 960m

Describe the current behavior
The model (a Keras Sequential) is saved using python's "tf.saved_model.save". This model is then loaded in Java using SavedModelBundle from which the related graph is extracted. Then and Ops is created using this graph. When trying to create a tensor using .constant method, an exception is thrown on line 413, /core/op/Constant.java saying

Duplicate node name in graph: 'Const'

I checked my graph nodes using getNodeList of MetaGraph and there is only one node named "Const".

Describe the expected behavior
Successful creation of Tensor as there is no duplicate in the graph nodes.
Code to reproduce the issue

SavedModelBundle model = SavedModelBundle.load("/path/to/model");
Graph graph = model.graph();
MetaGraphDef mataGF = model.metaGraphDef();
var nodes = mataGF.getGraphDef().getNodeList().toArray();
Ops tf = Ops.create(graph);
double[] labels = {0.52,0.65,0.23,0.54,0.65,0.16,0.97};
var input = tf.constant(labels);

Other info / logs
Here is a list of all the 37 nodes. Only node 31 is called Const;
image

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

使用 issue 中的 SavedModelBundle、Graph、Ops 和 tf.constant 重现该失败,然后检查第 413 行附近的 core/op/Constant.java,并将 MetaGraphDef 中的图节点与 Ops 使用的图进行比较。当可以从已保存模型的图创建所提供的 labels 张量,且不会出现重复节点错误时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
java
领域
machine-learning
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。