- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在我的 TF 代码中,我在模型中定义了以下内容:
with tf.name_scope("loss"):
self.loss = self.contrastive_loss(self.input_y,self.distance, batch_size)
with tf.name_scope("accuracy"):
correct_predictions = tf.equal(self.distance, self.input_y)
self.accuracy=tf.reduce_mean(tf.cast(correct_predictions, "float"), name="accuracy")
但我意识到在我的任务中使用 PIL 逊相关性更合适。所以,我把它改成这样:
with tf.name_scope("loss"):
self.loss = self.contrastive_loss(self.input_y,self.distance, batch_size)
with tf.name_scope("pearson"):
self.pearson = tf.contrib.metrics.streaming_pearson_correlation(self.distance, self.input_y, name="pearson")
我在计算图中调用我的模型,在训练循环中我有这个评估代码:
acc = dev_step(dev_x1_batch, dev_x2_batch, dev_y_batch, X)
调用此方法:
def dev_step(x1_batch, x2_batch, y_batch, X):
"""
A single training step
"""
if random()>0.5:
feed_dict = {
siameseModel.input_x1: x1_batch,
siameseModel.input_x2: x2_batch,
siameseModel.input_y: y_batch,
siameseModel.dropout_keep_prob: FLAGS.dropout_keep_prob,
siameseModel.embedding_placeholder: X
}
else:
feed_dict = {
siameseModel.input_x1: x2_batch,
siameseModel.input_x2: x1_batch,
siameseModel.input_y: y_batch,
siameseModel.dropout_keep_prob: FLAGS.dropout_keep_prob,
siameseModel.embedding_placeholder: X
}
step, _, loss, pearson, dist, out1, out2 = sess.run([global_step, siameseModel.embedding_init, siameseModel.loss, siameseModel.pearson, siameseModel.distance, siameseModel.out1, siameseModel.out2], feed_dict)
print("DEV {}: step {}, loss {:g}, acc {:g}".format(time_str, step, loss, pearson))
return pearson
我在 TF session 中完成所有这些操作:
sess = tf.Session(config=session_conf)
....code to create instance of model, definition of training procedure
sess.run(tf.initialize_all_variables())
...training loop
但我收到此错误:
tensorflow/core/framework/op_kernel.cc:968] Failed precondition: Attempting to use uninitialized value pearson/pearson/covariance/count
[[Node: pearson/pearson/covariance/count/read = Identity[T=DT_FLOAT, _class=["loc:@pearson/pearson/covariance/count"], _device="/job:localhost/replica:0/task:0/cpu:0"](pearson/pearson/covariance/count)]]
tensorflow/core/framework/op_kernel.cc:968] Failed precondition: Attempting to use uninitialized value pearson/pearson/covariance/count
[[Node: pearson/pearson/covariance/count/read = Identity[T=DT_FLOAT, _class=["loc:@pearson/pearson/covariance/count"], _device="/job:localhost/replica:0/task:0/cpu:0"](pearson/pearson/covariance/count)]]
tensorflow/core/framework/op_kernel.cc:968] Failed precondition: Attempting to use uninitialized value pearson/pearson/covariance/count
[[Node: pearson/pearson/covariance/count/read = Identity[T=DT_FLOAT, _class=["loc:@pearson/pearson/covariance/count"], _device="/job:localhost/replica:0/task:0/cpu:0"](pearson/pearson/covariance/count)]]
tensorflow/core/framework/op_kernel.cc:968] Failed precondition: Attempting to use uninitialized value pearson/pearson/covariance/count
[[Node: pearson/pearson/covariance/count/read = Identity[T=DT_FLOAT, _class=["loc:@pearson/pearson/covariance/count"], _device="/job:localhost/replica:0/task:0/cpu:0"](pearson/pearson/covariance/count)]]
tensorflow/core/framework/op_kernel.cc:968] Failed precondition: Attempting to use uninitialized value pearson/pearson/covariance/count
[[Node: pearson/pearson/covariance/count/read = Identity[T=DT_FLOAT, _class=["loc:@pearson/pearson/covariance/count"], _device="/job:localhost/replica:0/task:0/cpu:0"](pearson/pearson/covariance/count)]]
tensorflow/core/framework/op_kernel.cc:968] Failed precondition: Attempting to use uninitialized value pearson/pearson/covariance/count
[[Node: pearson/pearson/covariance/count/read = Identity[T=DT_FLOAT, _class=["loc:@pearson/pearson/covariance/count"], _device="/job:localhost/replica:0/task:0/cpu:0"](pearson/pearson/covariance/count)]]
Traceback (most recent call last):
File "train.py", line 260, in <module>
acc = dev_step(dev_x1_batch, dev_x2_batch, dev_y_batch, X)
File "train.py", line 207, in dev_step
step, _, loss, pearson, dist, out1, out2 = sess.run([global_step, siameseModel.embedding_init, siameseModel.loss, siameseModel.pearson, siameseModel.distance, siameseModel.out1, siameseModel.out2], feed_dict)
File "/Users/kurt/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 717, in run
run_metadata_ptr)
File "/Users/kurt/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 915, in _run
feed_dict_string, options, run_metadata)
File "/Users/kurt/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 965, in _do_run
target_list, options, run_metadata)
File "/Users/kurt/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 985, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors.FailedPreconditionError: Attempting to use uninitialized value pearson/pearson/covariance/count
[[Node: pearson/pearson/covariance/count/read = Identity[T=DT_FLOAT, _class=["loc:@pearson/pearson/covariance/count"], _device="/job:localhost/replica:0/task:0/cpu:0"](pearson/pearson/covariance/count)]]
Caused by op u'pearson/pearson/covariance/count/read', defined at:
File "train.py", line 97, in <module>
batch_size=FLAGS.batch_size)
File "filepath/", line 89, in __init__
self.pearson = tf.contrib.metrics.streaming_pearson_correlation(self.distance, self.input_y, name="pearson")
File "/Users/kurt/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/contrib/metrics/python/ops/metric_ops.py", line 2490, in streaming_pearson_correlation
predictions, labels, weights=weights, name='covariance')
File "/Users/kurt/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/contrib/metrics/python/ops/metric_ops.py", line 2367, in streaming_covariance
count = _create_local('count', [])
File "/Users/kurt/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/contrib/metrics/python/ops/metric_ops.py", line 135, in _create_local
collections=collections)
File "/Users/kurt/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/ops/variables.py", line 215, in __init__
dtype=dtype)
File "/Users/kurt/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/ops/variables.py", line 327, in _init_from_args
self._snapshot = array_ops.identity(self._variable, name="read")
File "/Users/kurt/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 1128, in identity
result = _op_def_lib.apply_op("Identity", input=input, name=name)
File "/Users/kurt/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 749, in apply_op
op_def=op_def)
File "/Users/kurt/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2380, in create_op
original_op=self._default_original_op, op_def=op_def)
File "/Users/kurt/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1298, in __init__
self._traceback = _extract_stack()
FailedPreconditionError (see above for traceback): Attempting to use uninitialized value pearson/pearson/covariance/count
[[Node: pearson/pearson/covariance/count/read = Identity[T=DT_FLOAT, _class=["loc:@pearson/pearson/covariance/count"], _device="/job:localhost/replica:0/task:0/cpu:0"](pearson/pearson/covariance/count)]]
抱歉,如果这个问题非常基本,我在 TF 方面还是个新手。您能否指出这里出了什么问题以及如何修复它?
最佳答案
streaming_pearson_correlation
函数委托(delegate)给 streaming_covariance
,根据文档,它创建了四个局部变量。
tf.initialize_all_variables()
不会初始化局部变量。
对于 Tensorflow r0.12+,请使用
tf.group(tf.global_variables_initializer(), tf.local_variables_initializer())
对于 Tensorflow <= r0.11,使用
tf.group(tf.initialize_all_variables(), tf.initialize_variables(tf.local_variables()))
关于python - 使用 Pearson 相关性而不是 tensorflow 中的准确性来报告性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41568721/
我使用以下代码来查看用户在特定页面上的停留时间。我为此脚本使用了带有 src 属性的隐藏图像: $timer_seconds = 1; while(!connection_aborted()) {
我在 Keras 中使用自定义损失函数: def get_top_one_probability(vector): return (K.exp(vector) / K.sum(K.exp(vect
当我使用 long 来节省一个月毫秒时,我发现一个问题。但我打印负数。所以我做了一个测试 代码如下: LogUtils.d(TAG, "long max time:"+Long.MAX_VALUE);
关于使用 Lenet5 网络解释某些优化器在 MNIST 上的性能,我有几个问题,以及验证损失/准确性与训练损失/准确性图表究竟告诉我们什么。所以一切都是在 Keras 中使用标准的 LeNet5 网
我有 1000 个 pdf(每个 200 页)。 我需要将每个 pdf 添加到 Azure 搜索索引中的索引(作为小文本 block 和相关元数据,例如每个 pdf 200 个 block ) 已达到
我必须在 mssql 数据库中存储一些间隔。我知道日期时间的准确性约为。 3.3ms(只能结束0、3、7)。但是当我计算日期时间之间的间隔时,我发现结果只能以 0、3 和 6 结尾。所以我总结的间隔越
我想制作一个需要将位置精确到大约 1m 或更小的 Android 应用程序。“Fused Location Manager API”是否足够好,或者 GPS 永远不会如此准确,无论是否与其他传感器融合
我想使用 pySerial 的 serial.tools.list_ports.comports() 列出可用的 COM 端口。 阅读documentation : The function retu
使用 pyomo 和 glpk 求解器,我定义了以下目标规则: def cost_rule(m): return (sum(m.rd[i]*m.pRdImp*m.dt - m.vr[i]*m.
我正在遵循“Lucene in Action”中的示例,第 308-315 页,它描述了 Lucene Spatial。我正在使用 lucene 2.9.4。我用过 http://geocoder.u
我一直在试验各种计时方法的代码。创建延迟的一种方法是使用thread.sleep(millis)运行线程,但可以很好地说明,线程“唤醒”的时间并不完全准确,可能在这个时间之前或之后。然后我遇到一个定义
我在使用 boost::sleep() 函数时遇到奇怪的问题。我有这个基本代码: #include #include #include void thread_func() { time
数字示例 我正在使用标准的 pytesseract img 来发送文本。我尝试过仅使用数字选项,90% 的情况下它是完美的,但上面是一个非常错误的例子!这个例子根本没有产生任何字符 如您所见,现在有字
我想从 python 中的图像中提取文本.为了做到这一点,我选择了 pytesseract .当我尝试从图像中提取文本时,结果并不令人满意。我也经历过this并实现了列出的所有技术。然而,它的表现似乎
在每个时代结束时,我得到例如以下输出: Epoch 1/25 2018-08-06 14:54:12.555511: 2/2 [==============================] - 86
我想为我的移动项目需求之一实现条形码。要存储的数据量非常少(<25 个字母数字)。我想知道对于这个项目实现一维条形码或二维条形码(特别是二维码)是否更明智。如果有人能从 1d 与 2d 的角度对我进行
想象一个二元分类问题。假设我在 pred_test 中存储了 800,000 个预测概率。我将 cutoff 定义为 pred_test 中的任何值,以便大于或等于 cutoff 的值被分配值 1 和
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我正在使用 iBeacon 和 Altbeacon 测试定位系统。我发现我的三角测量结果实际上非常准确,但有时需要 5 秒以上才能看到正确的结果。 例如,假设我目前正站在A点。 Altbeacon +
因此,我有 2 个独立的数据表,它们看起来非常相同,但它们行中的值可能不同。 编辑: 我可以通过创建一个可以用作主键的临时标识列来获得唯一 ID,如果这样做更容易的话。所以将 ID 列视为主键。 表A
我是一名优秀的程序员,十分优秀!