tf.boolean_mask got必须指定蒙版尺寸数

时间:2018-08-28 16:20:07

标签: python tensorflow

> = 80之后,张量形状变为(?,)。这导致boolean_mask出错。以下代码用于过滤掉80%以上的精度。

outputs, final_state = tf.contrib.rnn.static_rnn(cell, lstm_in, dtype=tf.float32,
                                                 initial_state = initial_state)
logits = tf.layers.dense(outputs[-1], n_classes, name='logits')
np_logits_b = tf.reduce_max(outputs[-1], axis=1) >= 80
labels_filtered = tf.boolean_mask(labels_, np_logits_b)

    <ipython-input-13-2615e31971df> in <module>()
     23     # Accuracy on >80%
     24     np_logits_b = tf.reduce_max(logits, axis=1) >= 80
---> 25     labels_filtered = tf.boolean_mask(labels_, np_logits_b)
     26     correct_pred_filtered = tf.equal(tf.argmax(logits_filtered, 1), tf.argmax(labels_filtered, 1))
     27     accuracy_filtered = tf.reduce_mean(tf.cast(correct_pred_filtered, tf.float32), name='accuracy_filtered')

~\Anaconda3\lib\site-packages\tensorflow\python\ops\array_ops.py in boolean_mask(tensor, mask, name)
   1119     if ndims_mask is None:
   1120       raise ValueError(
-> 1121           "Number of mask dimensions must be specified, even if some dimensions"
   1122           " are None.  E.g. shape=[None] is ok, but shape=None is not.")
   1123     shape_tensor[:ndims_mask].assert_is_compatible_with(shape_mask)

ValueError: Number of mask dimensions must be specified, even if some dimensions are None.  E.g. shape=[None] is ok, but shape=None is not.


print(tf.shape(np_logits_b))
Tensor("Shape_4:0", shape=(?,), dtype=int32)

0 个答案:

没有答案