使用占位符通过 CPU/GPU 获得不同的价值 [英] Getting different value with placeholder over CPU/GPU

查看:32
本文介绍了使用占位符通过 CPU/GPU 获得不同的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行下面的代码时,我想我得到了错误的结果.
超过 GPU

 将 tensorflow 导入为 tfsess = tf.Session()a = tf.placeholder(tf.float32)b = tf.placeholder(tf.float32)adder_node = a + b打印(sess.run(adder_node,{a:3,b:4.5}))打印(sess.run(adder_node, {a: [1, 3], b: [2, 4]}))

<块引用>

输出:
3.0
[ 1. 3.]

我认为真正的结果应该是;
7.5
[ 3. 7.]

超过 CPU

 将 tensorflow 导入为 tfsess = tf.Session()使用 tf.device('/cpu:0'):a = tf.placeholder(tf.float32)b = tf.placeholder(tf.float32)adder_node = a + b打印(sess.run(adder_node,{a:3,b:4.5}))打印(sess.run(adder_node, {a: [1, 3], b: [2, 4]}))

<块引用>

输出:
7.5
[ 1. 3.]

Tensorflow 版本:
'1.3.0'
Python 版本:
Python 2.7.12

当我在 CPU 和 GPU 上运行时,我得到了不同的结果.提前致谢,任何帮助将不胜感激...

解决方案

我编译了你的代码,得到了真实的结果.我也在用张量流版本:'1.3.0'蟒蛇版本:Python 2.7.12

代码和结果截图

When I run at below code, I think I am getting the wrong results.
OVER GPU

import tensorflow as tf
sess = tf.Session()
a = tf.placeholder(tf.float32)
b = tf.placeholder(tf.float32)
adder_node = a + b
print(sess.run(adder_node, {a: 3, b: 4.5}))
print(sess.run(adder_node, {a: [1, 3], b: [2, 4]}))

Output:
3.0
[ 1. 3.]

I think the true result should be;
7.5
[ 3. 7.]

OVER CPU

import tensorflow as tf
sess = tf.Session()
with tf.device('/cpu:0'):
    a = tf.placeholder(tf.float32)
    b = tf.placeholder(tf.float32)
    adder_node = a + b
print(sess.run(adder_node, {a: 3, b: 4.5}))
print(sess.run(adder_node, {a: [1, 3], b: [2, 4]}))

Output:
7.5
[ 1. 3.]

Tensorflow Version:
'1.3.0'
Python Version:
Python 2.7.12

I am getting different results when I run over CPU and GPU. Thanks in advance, any help would be appreciated...

解决方案

I compiled your code and I got the true result. I am also using Tensorflow Version: '1.3.0' Python Version: Python 2.7.12

Screenshot of the code and result

这篇关于使用占位符通过 CPU/GPU 获得不同的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆