小编Sam*_*mbo的帖子

TensorFlow中的矩阵规范

我需要计算Frobenius规范,以便使用TensorFlow框架实现此公式:

式

其中w是一个包含50行和100列的矩阵.

我试着写点什么,但我不明白如何填写axis论点.

tf.pow(
    tf.norm(x, ord='fro', axis=?), 2
)
Run Code Online (Sandbox Code Playgroud)

根据TensorFlow文档,我必须使用2元组(或2个列表),因为它确定了计算矩阵范数的张量中的轴,但我只需要一个简单的Frobenius范数.在SciPy,例如,我可以不用指定任何轴.

那么,我应该使用什么axis来模拟SciPy函数呢?

python tensorflow

7
推荐指数
1
解决办法
6440
查看次数

评估过程中实验者的张量流混淆矩阵

在使用Tensorflow和Experimenter API进行模型评估期间,我遇到了一些麻烦.

我以前使用2级NN工作,但这次我设法训练4级,我需要弄清楚如何在这种情况下构建混淆矩阵.我尝试使用该tf.confusion_matrix功能,但它根本不起作用.

这是我使用的代码片段:

if mode == ModeKeys.EVAL:

    eval_metric_ops = {
        'accuracy' : metrics.streaming_accuracy(predictions=predicted_classes, labels=labels),

        # Other metrics...

        'confusion_matrix': tf.confusion_matrix(prediction=predicted_classes, label=labels, num_classes=4)
    }

    return tf.estimator.EstimatorSpec(
        mode=mode,
        predictions=predicted_classes,
        loss=loss,
        eval_metric_ops=eval_metric_ops
    )
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误:

TypeError: Values of eval_metric_ops must be (metric_value, update_op) tuples, given: (<tf.Operation 'test/group_deps' type=NoOp>, <tf.Tensor 'test/accuracy/value:0' shape=() dtype=float32>, <tf.Variable 'test/confusion:0' shape=(4, 4) dtype=int32_ref>) for key: confusion_matrix
Run Code Online (Sandbox Code Playgroud)

我读了关于在Tensorflow中创建混淆矩阵的其他答案,我理解了如何做,但我认为我的问题与Estimator/Experimenter API更相关.

python neural-network confusion-matrix tensorflow

3
推荐指数
1
解决办法
984
查看次数