- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我只是不知道出了什么问题......我之前尝试过 InteractiveSession() 并传递了一个显式 session ,但这个错误没有得到解决......我是 tensorflow 的新手......请帮忙。
cost=-tf.reduce_sum(y*tf.log(y_))
train_step=tf.train.AdamOptimizer(LEARNING_RATE).minimize(cost)
correct_pred=tf.equal(tf.argmax(y,1),tf.argmax(y_,1))
accuracy = tf.reduce_mean(tf.cast(correct_pred, 'float'))
predict=tf.argmax(y,1)
这是我的 session
train_accuracies = []
validation_accuracies = []
x_range = []
num_examples=train_images.shape[0]
init=tf.global_variables_initializer()
minibatches=random_mini_batches(train_images,train_labels,
mini_batch_size = BATCH_SIZE)
display_step=1
init = tf.initialize_all_variables()
with tf.Session().as_default() as sess:
sess.run(init)
for epoch in range(TRAINING_ITERATIONS):
for minibatch in minibatches:
(minibatch_X,minibatch_Y)=minibatch
if epoch%display_step == 0 or (epoch+1) == TRAINING_ITERATIONS:
train_accuracy = accuracy.eval(session=sess,feed_dict={x:minibatch_X,
y: minibatch_Y,
keep_prob: 1.0})
if(VALIDATION_SIZE):
validation_accuracy = accuracy.eval(session=sess,feed_dict={ x: validation_images[0:BATCH_SIZE],
y: validation_labels[0:BATCH_SIZE],
keep_prob: 1.0})
print('training_accuracy / validation_accuracy => %.2f / %.2f for step %d'%(train_accuracy, validation_accuracy, epoch))
validation_accuracies.append(validation_accuracy)
else:
print('training_accuracy => %.4f for step %d'%(train_accuracy, epoch))
train_accuracies.append(train_accuracy)
x_range.append(epoch)
# increase display_step
if epoch%(display_step*10) == 0 and epoch:
display_step *= 10
# train on batch
sess.run(train_step, feed_dict={x: minibatch_X, y:minibatch_Y, keep_prob: DROPOUT})
并生成以下错误
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-63-910bbc0840b2> in <module>
18 train_accuracy = accuracy.eval(session=sess,feed_dict={x:minibatch_X,
19 y: minibatch_Y,
---> 20 keep_prob: 1.0})
21 if(VALIDATION_SIZE):
22 validation_accuracy = accuracy.eval(session=sess,feed_dict={ x:
validation_images[0:BATCH_SIZE],
/opt/conda/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py in eval(self,
feed_dict, session)
788
789 """
--> 790 return _eval_using_default_session(self, feed_dict, self.graph, session)
791
792 def experimental_ref(self):
/opt/conda/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py in
_eval_using_default_session(tensors, feed_dict, graph, session)
5307 else:
5308 if session.graph is not graph:
-> 5309 raise ValueError("Cannot use the given session to evaluate tensor: "
5310 "the tensor's graph is different from the session's "
5311 "graph.")
ValueError: Cannot use the given session to evaluate tensor: the tensor's graph is different
from the session's graph.
请建议如何使用两个 session 以及如何解决此问题。主要问题是我尝试将 session 作为 eval(session=sess) 传递,但它不起作用。意思是我用的计算图和accuracy tensor的图不一样
最佳答案
我已经重新创建了由于可能的方式导致的错误,并且还提供了修复。
在代码中提供了更多注释,以便更清楚地了解错误和修复。
注意 - 我使用了相同的代码并稍作调整来重新创建错误原因的可能性并修复相同的错误。
最佳修复代码出现在这个答案的末尾。
错误代码 1 -默认 session 和使用在另一个图中创建的变量时出错
%tensorflow_version 1.x
import tensorflow as tf
g = tf.Graph()
with g.as_default():
x = tf.constant(1.0) # x is created in graph g
with tf.Session().as_default() as sess:
y = tf.constant(2.0) # y is created in TensorFlow's default graph!!!
print(y.eval(session=sess)) # y was created in TF's default graph, and is evaluated in
# default session, so everything is ok.
print(x.eval(session=sess)) # x was created in graph g and it is evaluated in session s
# which is tied to graph g, but it is evaluated in
# session s which is tied to graph g => ERROR
输出-
2.0
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-5-f35cb204cf59> in <module>()
10 print(y.eval(session=sess)) # y was created in TF's default graph, and is evaluated in
11 # default session, so everything is ok.
---> 12 print(x.eval(session=sess)) # x was created in graph g and it is evaluated in session s
13 # which is tied to graph g, but it is evaluated in
14 # session s which is tied to graph g => ERROR
1 frames
/tensorflow-1.15.2/python3.6/tensorflow_core/python/framework/ops.py in _eval_using_default_session(tensors, feed_dict, graph, session)
5402 else:
5403 if session.graph is not graph:
-> 5404 raise ValueError("Cannot use the given session to evaluate tensor: "
5405 "the tensor's graph is different from the session's "
5406 "graph.")
ValueError: Cannot use the given session to evaluate tensor: the tensor's graph is different from the session's graph.
错误代码 2 -默认图形 session 和使用在默认图形中创建的变量时出错
%tensorflow_version 1.x
import tensorflow as tf
g = tf.Graph()
with g.as_default():
x = tf.constant(1.0) # x is created in graph g
with tf.Session(graph=g).as_default() as sess:
print(x.eval(session=sess)) # x was created in graph g and it is evaluated in session s
# which is tied to graph g, so everything is ok.
y = tf.constant(2.0) # y is created in TensorFlow's default graph!!!
print(y.eval()) # y was created in TF's default graph, but it is evaluated in
# session s which is tied to graph g => ERROR
输出-
1.0
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-15-6b8b687c5178> in <module>()
10 # which is tied to graph g, so everything is ok.
11 y = tf.constant(2.0) # y is created in TensorFlow's default graph!!!
---> 12 print(y.eval()) # y was created in TF's default graph, but it is evaluated in
13 # session s which is tied to graph g => ERROR
1 frames
/tensorflow-1.15.2/python3.6/tensorflow_core/python/framework/ops.py in _eval_using_default_session(tensors, feed_dict, graph, session)
5396 "`eval(session=sess)`")
5397 if session.graph is not graph:
-> 5398 raise ValueError("Cannot use the default session to evaluate tensor: "
5399 "the tensor's graph is different from the session's "
5400 "graph. Pass an explicit session to "
ValueError: Cannot use the default session to evaluate tensor: the tensor's graph is different from the session's graph. Pass an explicit session to `eval(session=sess)`.
错误代码 3 - 按照 错误代码 2 - 输出中的建议,将显式 session 传递给 eval(session=sess)
。让我们试试这个。
%tensorflow_version 1.x
import tensorflow as tf
g = tf.Graph()
with g.as_default():
x = tf.constant(1.0) # x is created in graph g
with tf.Session(graph=g).as_default() as sess:
print(x.eval(session=sess)) # x was created in graph g and it is evaluated in session s
# which is tied to graph g, so everything is ok.
y = tf.constant(2.0) # y is created in TensorFlow's default graph!!!
print(y.eval(session=sess)) # y was created in TF's default graph, but it is evaluated in
# session s which is tied to graph g => ERROR
输出-
1.0
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-16-83809aa4e485> in <module>()
10 # which is tied to graph g, so everything is ok.
11 y = tf.constant(2.0) # y is created in TensorFlow's default graph!!!
---> 12 print(y.eval(session=sess)) # y was created in TF's default graph, but it is evaluated in
13 # session s which is tied to graph g => ERROR
1 frames
/tensorflow-1.15.2/python3.6/tensorflow_core/python/framework/ops.py in _eval_using_default_session(tensors, feed_dict, graph, session)
5402 else:
5403 if session.graph is not graph:
-> 5404 raise ValueError("Cannot use the given session to evaluate tensor: "
5405 "the tensor's graph is different from the session's "
5406 "graph.")
ValueError: Cannot use the given session to evaluate tensor: the tensor's graph is different from the session's graph.
修复 1 - 修复默认 session 和未分配给任何图形的变量
%tensorflow_version 1.x
import tensorflow as tf
x = tf.constant(1.0) # x is in not assigned to any graph
with tf.Session().as_default() as sess:
y = tf.constant(2.0) # y is created in TensorFlow's default graph!!!
print(y.eval(session=sess)) # y was created in TF's default graph, and is evaluated in
# default session, so everything is ok.
print(x.eval(session=sess)) # x not assigned to any graph, and is evaluated in
# default session, so everything is ok.
输出-
2.0
1.0
修复 2 - 最佳修复 是将构造阶段和执行阶段完全分开。
import tensorflow as tf
g = tf.Graph()
with g.as_default():
x = tf.constant(1.0) # x is created in graph g
y = tf.constant(2.0) # y is created in graph g
with tf.Session(graph=g).as_default() as sess:
print(x.eval()) # x was created in graph g and it is evaluated in session s
# which is tied to graph g, so everything is ok.
print(y.eval()) # y was created in graph g and it is evaluated in session s
# which is tied to graph g, so everything is ok.
输出-
1.0
2.0
关于python - 无法使用给定 session 评估张量 : the tensor's graph is different from the session's graph,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61006702/
我的一个 friend 在一次求职面试中被要求编写一个程序来测量可用 RAM 的数量。预期的答案是以二进制搜索方式使用 malloc():分配越来越大的内存部分,直到收到失败消息,减少部分大小,然后对
我正在通过任务管理器检查 Chrome 中特定选项卡的内存消耗情况。它显示了我使用的 RAM 量相当大: 但是,当我在开发人员工具中拍摄堆快照时,其显示的大小要小几倍: 怎么会这样呢? 最佳答案 并非
是否有一种可移植的方式,可以在各种支持的操作系统上同时在 .Net 和 Mono 上运行,让程序知道它运行的机器上有多少 RAM(即物理内存而不是虚拟内存)可用? 上下文是一个程序,其内存要求是“请尽
有谁知道是否有办法查看 android studio 项目中的所有 View 、LinearLayout、TextView 等? 我正在使用 android 设备监视器中的层次结构查看器使用 xml
很简单,我想从 Python 脚本中运行外部命令/程序,完成后我还想知道它消耗了多少 CPU 时间。 困难模式:并行运行多个命令不会导致 CPU 消耗结果不准确。 最佳答案 在 UNIX 上: (a)
我需要在给定数组索引和范围的情况下,在返回新索引的数组中向前循环 X 量并向后循环 X 量。 如果循环向前到达数组的末尾,它将在数组的开头继续。如果循环在向后时到达开头,它会在数组末尾继续。 例如,数
Android 应用程序中是否有类似最大 Activity 的内容?我想知道,因为我正在考虑创建具有铃声功能的声音应用程序。它将有大约 40 个 Activity 。但只有 1 个会持续运行。那太多了
有什么方法可以限制这种演示文稿的 curl 量吗?我知道系统会根据我们以 taht 方式模态呈现的 viewcontroller View 内的内容自动 curl 。 但 thta 在我的 iPad
我正在编写一个 Java 应用程序,它需要检查系统中可用的最大 RAM 量(不是 VM 可用的 RAM)。有没有可移植的方式来做到这一点? 非常感谢:-) 最佳答案 JMX 您可以访问 java.la
我发现它使用了 600 MB 的 RAM,甚至超过了 Visual Studio(当它达到 400 MB 的 RAM 时我将其关闭)。 最佳答案 dart 编辑器基于 Eclipse,而 Eclips
这个问题已经有答案了: Java get available memory (10 个回答) 已关闭 7 年前。 假设我有一个专门运行一个程序的 JVM,我如何获得分配给 JVM 的 RAM 量? 假
我刚刚使用 Eclipse 编写了一个程序,该程序需要很长时间才能执行。它花费的时间甚至更长,因为它只将我的 CPU 加载到 25%(我假设这是因为我使用的是四核,而程序只使用一个核心)。有没有办法让
我编写了一个 2x2x2 魔方求解器,它使用广度优先搜索算法求解用户输入的立方体位置。该程序确实解决了立方体。然而,当我进入一个很难解决的问题时,我会在搜索的深处发现这个问题,我用完了堆空间。我的电脑
我正在尝试同步运行多个 fio 线程,但随着线程数量的增加,我的计算机内存不足。似乎每个 fio 线程占用大约 200MB 的 RAM。话虽这么说,有没有办法让每个线程都有一个固定的最大内存使用量?设
我使用“fitctree”函数(链接:https://de.mathworks.com/help/stats/classificationtree-class.html)在 Matlab 中开发了一个
我有一个 .NET 进程,由于我不会深入探讨的原因,它消耗了大量 RAM。我想要做的是对该进程可以使用的 RAM 量实现上限。有办法做到这一点吗? 我找到的最接近的是 Process.GetCurre
您可能已经看到许多“系统信息”应用程序,它们显示诸如剩余电池生命周期之类的信息,甚至显示内存等系统信息。 以类似的方式,是否有任何方法可以从我的应用中检索当前可用 RAM 量,以便我可以更好地决定何时
我从来都不是 MFC 的忠实粉丝,但这并不是重点。我读到微软将在 2010 年发布新版本的 MFC,这让我感到很奇怪 - 我以为 MFC 已经死了(不是恶意,我真的这样做了)。 MFC 是否用于新开发
我在一台安装了 8 GB 内存的机器上工作,我试图以编程方式确定机器中安装了多少内存。我已经尝试使用 sysctlbyname() 来获取安装的内存量,但它似乎仅限于返回带符号的 32 位整数。 ui
基本上,我想要一个由大小相同的 div(例如 100x100)和类似 200x100 的变体构建的页面。它们都 float :向左调整以相应地调整窗口大小。问题是,我不知道如何让它们在那种情况下居中,
我是一名优秀的程序员,十分优秀!