我已经花了相当多的时间在堆栈溢出上挖掘,否则寻找答案,但找不到任何东西
大家好,
我正在使用Keras运行Tensorflow.我90%肯定我安装了Tensorflow GPU,有没有办法检查我做了哪个安装?
我试图从Jupyter笔记本运行一些CNN模型,我注意到Keras在CPU上运行模型(检查任务管理器,CPU为100%).
我尝试从tensorflow网站运行此代码:
# Creates a graph.
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# Runs the op.
print(sess.run(c))
Run Code Online (Sandbox Code Playgroud)
这就是我得到的:
MatMul: (MatMul): /job:localhost/replica:0/task:0/cpu:0
2017-06-29 17:09:38.783183: I c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\common_runtime\simple_placer.cc:847] MatMul: (MatMul)/job:localhost/replica:0/task:0/cpu:0
b: (Const): /job:localhost/replica:0/task:0/cpu:0
2017-06-29 17:09:38.784779: I c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\common_runtime\simple_placer.cc:847] b: (Const)/job:localhost/replica:0/task:0/cpu:0
a: (Const): /job:localhost/replica:0/task:0/cpu:0
2017-06-29 17:09:38.786128: I c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\common_runtime\simple_placer.cc:847] a: …Run Code Online (Sandbox Code Playgroud) 我不断看到一些用户说不建议使用带有可选的集合/是不好的做法。我找不到太多关于为什么这是不好的做法的信息,所以我在这里。
如果重要的话,在我的特定情况下,我有一个带有 2 个方法的 JpaRepository。一Optional<List> getValues()又一秒List getDefaultValues(),如下所示:
public interface someRepository extends JpaRepository<x, y> {
Optional<List> getValues();
List getDefaultValues();
}
Run Code Online (Sandbox Code Playgroud)
这个想法是这些值可能不存在,所以我想强制方法调用者这样做,.orElse(getDefaultValues())这样就不会返回空列表。我还认为这比仅仅做这样的事情更整洁:
List list = getValues();
if (list.isEmpty()) {
list = getDefaultValues();
}
Run Code Online (Sandbox Code Playgroud)
如有任何反馈,我们将不胜感激。
编辑:我意识到我的例子并不是最适合这个问题,正如下面的答案所指出的。但是,我仍然想了解为什么Optional<List>有些人认为这是不好的做法。
这个问题并没有真正回答我的问题。