我希望能够访问我在TensorFlow中训练的二元分类器的概率,以允许我调整概率阈值而无需重新训练整个模型。以下两行对我来说已经好几个月了:
self.scores = tf.nn.xw_plus_b(self.h_drop, W, b, name="scores")
self.predictions = tf.argmax(self.scores, 1, name="predictions")
我添加了以下行来评估得分的softmax:
self.probabilities = tf.nn.softmax(self.scores, 1, name="probabilities")
引发了以下错误:
Traceback (most recent call last):
File "/home/produser/code/python/deeplearning/text_cnn_main.py", line 111, in <module>
vocabulary=vocab_processor.vocabulary_)
File "/var/store/code/python/deeplearning/text_cnn.py", line 84, in __init__
self.probabilities = tf.nn.softmax(self.scores, 1, name="probs")
TypeError: softmax() got multiple values for keyword argument 'name'
我尝试删除可选的name参数,并按如下方式运行调用:
self.probabilities = tf.nn.softmax(self.scores, 1)
在这种情况下,抛出以下错误:
Traceback (most recent call last):
File "/home/produser/code/python/deeplearning/text_cnn_main.py", line 111, in <module>
vocabulary=vocab_processor.vocabulary_)
File "/var/store/code/python/deeplearning/text_cnn.py", line 84, in __init__
self.probabilities = tf.nn.softmax(self.scores, 1)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_nn_ops.py", line 1396, in softmax
result = _op_def_lib.apply_op("Softmax", logits=logits, name=name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 357, in apply_op
with g.as_default(), ops.name_scope(name) as scope:
File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2799, in name_scope
if not _VALID_SCOPE_NAME_REGEX.match(name):
TypeError: expected string or buffer
似乎softmax函数继承了输入张量的名称。在命名空间中解决这种混淆的最佳方法是什么?非常感谢你的时间和想法。