如何从张量流中得到识别区域?

2024-04-16 21:55:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我在TF中创建了一个简单的模型来识别汽车。 它将下面的图像识别为一辆汽车:

enter image description here

我想要的是实际识别车辆的面积(或面积的收成),如下所示: enter image description here

如果有可能的话,有什么想法吗?我当前的python代码如下所示:

file_name = 'mustangTest.png'
input_height = 299
input_width = 299
input_mean = 0
input_std = 255
input_layer = "Mul"
output_layer = "final_result"
t = read_tensor_from_image_file(src,input_height=input_height,input_width=input_width,input_mean=input_mean,input_std=input_std)
        input_name = "import/" + input_layer
        output_name = "import/" + output_layer
        input_operation = graph.get_operation_by_name(input_name);
        output_operation = graph.get_operation_by_name(output_name);

        with tf.Session(graph=graph) as sess:
            results = sess.run(output_operation.outputs[0],{input_operation.outputs[0]: t})
            results = np.squeeze(results)
        top_k = results.argsort()[-5:][::-1]
        print("car is " + top_k[0]")

Tags: nameimportlayerinputoutputmeanwidthoperation
1条回答
网友
1楼 · 发布于 2024-04-16 21:55:32

初始注释:既然您谈到“创建了一个简单的模型”并说模型“将此图像识别为汽车”,我就假设您实际上并没有使用一个模型进行目标检测,而是使用一个进行简单分类的模型。你知道吗

你试图解决的问题与你训练你的人际网络去解决的问题是不同的。你知道吗

你有一个经过训练的网络,它可以告诉你你提供给它的图像是否包含一辆汽车。这是一个分类问题。你知道吗

现在需要的是图像中汽车实际所在的区域。这是一个更难解决的问题,因为现在您的网络不再需要输出“我看到一辆车”与“我没有看到一辆车”,而是在最简单的公式中,“我在矩形(x,y,w,h)中看到一辆车”。在另一个公式中,更类似于您期望的输出,您将拥有个像素一个分类,如“它是一辆车”或“不是一辆车”。这些问题就是目标检测和分割。你知道吗

有一些研究解决了这些问题(one exampleanother),但我的建议是看一下Tensorflow的object detection API,它有预先训练好的模型,您可以利用这些模型来开发您的用例。你知道吗

相关问题 更多 >