了解张量流二进制图像分类结果 [英] understanding tensorflow binary image classification results

查看:51
本文介绍了了解张量流二进制图像分类结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我第一次使用Tensor流的尝试,我遵循了二进制图像分类教程

For one of my first attempts at using Tensor flow I've followed the Binary Image Classification tutorial https://www.tensorflow.org/tutorials/keras/text_classification_with_hub#evaluate_the_model.

我能够很好地按照教程进行操作,但是随后我想尝试更仔细地检查结果,即我想查看模型对测试数据集中的每个项目做出了哪些预测.

I was able to follow the tutorial fine, but then I wanted to try to inspect the results more closely, namely I wanted to see what predictions the model made for each item in the test data set.

简而言之,我想看看它将对给定的电影评论预测什么标签"(1或0).

In short, I wanted to see what "label" (1 or 0) it would predict applies to a given movie review.

所以我尝试了:

结果= model.predict(test_data.batch(512))

然后

i在结果中:打印(i)

这使我接近了我的期望.25,000个条目的列表(每个电影评论一个).

This gives me close to what I would expect. A list of 25,000 entries (one for each movie review).

但是数组中每个项目的值都不是我所期望的.我期望看到一个预测的标签,所以0(表示负数)或1(表示正数).

But the value of each item in the array is not what I would expect. I was expecting to see a predicted label, so either a 0 (for negative) or 1 (for positive).

但是我得到了:

[0.22731477]
[2.1199656]
[-2.2581818]
[-2.7382329]
[3.8788114]
[4.6112833]
[6.125982]
[5.100685]
[1.1270659]
[1.3210837]
[-5.2568426]
[-2.9904163]
[0.17620209]
[-1.1293088]
[2.8757455]
...and so on for 25,000 entries.

有人可以帮助我理解这些数字的含义吗?

Can someone help me understand what these numbers mean.

我是否误解了预测"方法的作用,或者(由于这些数字看起来与模型第一层中引入的词嵌入向量相似),也许我误解了预测与词嵌入层和词嵌入层之间的关系.最终分类标签.

Am I misunderstanding what the "predict" method does, or (since these number look similar to the word embedding vectors introduced in the first layer of the model) perhaps I am misunderstanding how the prediction relates to the word embedding layer and the ultimate classification label.

我知道这是一个主要的新手问题.但是感谢您的帮助和耐心:)

I know this a major newbie question. But appreciate your help and patience :)

推荐答案

根据您提供的链接,问题出在您的输出激活功能上.该代码使用具有1个神经元且没有激活功能的密集向量.因此,它只是将前一层的输出乘以权重和偏差并将它们相加.您获得的输出将在-infinity(负类)和+ infinity(正类)之间变化,因此,如果您确实希望输出在零和一之间,则需要一个激活函数,例如sigmoid model.add(tf.keras.layers.Dense(1),激活="Sigmoid").现在,我们将所有事物都映射到0到1的范围内,因此如果输出小于0.5(中点),我们就可以归类为负类,反之亦然.

According to the link that you provided, the problem come from your output activation function. That code use dense vector with 1 neuron without activation function. So it just multiplying output from previous layer with weight and bias and sum them together. The output that you get will have a range between -infinity(negative class) and +infinity(positive class), Therefore if you really want your output between zero and one you need an activation function such as sigmoid model.add(tf.keras.layers.Dense(1), activation='sigmoid'). Now we just map every thing to range 0 to 1, so we can classify as negative class if output is less than 0.5(mid point) and vice versa.

实际上,您对预测功能的理解是正确的.您只是没有添加符合您的假设的激活,这就是为什么要选择该输出而不是0到1之间的值的原因.

Actually your understanding of prediction function is correct. You simply did not add an activation to fit with your assumption, that's why you gat that output instead of value between 0 and 1.

这篇关于了解张量流二进制图像分类结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆