如何从模型函数返回tf.confusion_matrix()的值

时间:2019-02-21 00:51:01

标签: tensorflow tensorflow-serving tensorflow-datasets

我的代码段

要求。 我希望输出混淆矩阵2个纪元。

def model_fn():
    tf.get_variable(name="conMat",initilializer=tf.confusion_matrix(y,ypred)) 
    //ERROR

    model=tf.estimator.Estimator(model_fn=model_fn,
                            params={"learningrate":1e-4},
                            model_dir="./model_dir/")
    while (count <2 ):
      model.train(input_fn=input_fn)
      conMat=model.get_variable_value("conMat")
      conMatValue=sess.run(conMat)
      print(conMatValues)

我希望conMatValues显示混乱矩阵。但是,它无法将变量放入conMat中。

我收到以下错误:

  

“初始值必须具有指定的形状:   张量(“ confusion_matrix / SparseTensorAdd:0”,shape =(?,?),dtype = int32)   “

如果我将shape=()作为tf.get_variable的参数,则会收到错误消息

  

“形状对于常量输入无效”

我现在被锁定了,不知道该怎么办。
我需要一些帮助才能在训练循环中获得混淆矩阵的输出。

感谢您的帮助

0 个答案:

没有答案