使用占位符通过 CPU/GPU 获得不同的价值

编程入门 行业动态 更新时间:2024-10-09 13:23:00
本文介绍了使用占位符通过 CPU/GPU 获得不同的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

当我运行下面的代码时,我想我得到了错误的结果.
超过 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屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 02:09:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1402398.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:价值   CPU   GPU

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!