前言:
{
这次也遇到了不少问题,最头疼的就是OOM(内存不够)。虽然要训练的东西很少,但在初始化时还是会出错,目前就先用CPU(禁用显存)做初步调试。
}
正文:
{
按照我原本的打算,损失是mean_squared_error;当某类的输出与标签的差不小于0.5时,则此类的预测正确,准确率为平均正确率。
此准确率的计算用到了二值张量。代码1是张量二值化的函数和评估步骤,其中输出张量input_tensor的类型需要与阈值threshold的一致。
#代码1
#the following function is to return a binary tensor by the argument input_tensor
#of which values less than the threshold will be converted into zeros or Falses.
def tensor_binaryzation(input_tensor, threshold):
y = tf.subtract(tf.cast(threshold, tf.float32), 1.0)
x = tf.cast(input_tensor, tf.float32)
output_tensor = tf.cast(tf.subtract(x, y), dtype=tf.uint64)
return tf.cast(output_tensor, dtype=tf.bool)
如果想改变trainable variables&#