新手怎么做电商在哪个网站,泉州建设工程开标网站,我要创业找项目,厦门网站建设方案服务bug:描述
在进行tensorflow进行搭建CNN网络时#xff0c;在定义CNN的py文件中调用cnn模型#xff0c;运行正常#xff0c;但是在其他py文件中进行时就出现问题 ValueError: Tensor(“Variable:0” dtypefloat32_ref) must be from the same graph as Tensor(“Reshape:0”,…bug:描述
在进行tensorflow进行搭建CNN网络时在定义CNN的py文件中调用cnn模型运行正常但是在其他py文件中进行时就出现问题 ValueError: Tensor(“Variable:0” dtypefloat32_ref) must be from the same graph as Tensor(“Reshape:0”, shape(?, 2 8, 28, 1), dtypefloat32) bug分析 由报错可以看出意思就是两个tensor张量应该来自同一个计算图中在另外一个文件运行默认是另一个计算图了所以计算图不一样导致报错 bug解决 创建一个计算图将同一个计算图的变量都在同一个计算图下进行定义 修改前代码
# placeholder占位符X tf.placeholder(tf.float32, [None, IMAGE_HEIGHT * IMAGE_WIDTH])Y tf.placeholder(tf.float32, [None, MAX_CAPTCHA * CHAR_SET_LEN])keep_prob tf.placeholder(tf.float32)
修复后代码
graph tf.Graph() #定义计算图with graph.as_default():# placeholder占位符X tf.placeholder(tf.float32, [None, IMAGE_HEIGHT * IMAGE_WIDTH])Y tf.placeholder(tf.float32, [None, MAX_CAPTCHA * CHAR_SET_LEN])keep_prob tf.placeholder(tf.float32) 注在涉及到张量的地方添加上 with graph.as_default()即可 参考 解决ValueError: Tensor(Variable:0 dtypefloat32_ref) must be from the same graph as Tensor(Reshape:_四平先森的博客-CSDN博客#解决django中调用CNN模型出现ValueError: Tensor(“Variable:0” dtypefloat32_ref) must be from the same graph as Tensor(“Reshape:0”, shape(?, 2 8, 28, 1), dtypefloat32)的问题TOC在同一个.py文件中可以实现不会报错在外部的.py文件中调用预测...https://blog.csdn.net/llsplsp/article/details/105420453