如何从张量流中获取已识别的区域?

时间:2018-01-25 12:53:17

标签: python opencv tensorflow

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

enter image description here

我想要的是实际识别的汽车的面积(或区域的作物)如下: enter image description here

Tensorflow是否可以提出任何想法?我当前的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]")

1 个答案:

答案 0 :(得分:1)

初步说明:因为您谈到了"创建了一个简单的模型"并且说过这个模型"将这个图像识别为汽车",我假设您实际上没有使用模型进行物体检测,而是进行简单分类。

您尝试解决的问题与您培训网络解决的问题不同。

您的网络经过培训可以告诉您您提供给它的图片是否包含汽车。这是一个分类问题。

您现在想要的是汽车实际位于图片中的区域。这是一个难以解决的问题,因为现在你的网络不再需要输出了#34;我看到了一辆汽车"与"我没有看到汽车",而是在最简单的表述中,"我在矩形中看到一辆汽车(x,y, W,H)&#34 ;.在另一个公式中,与您期望的输出更相似,您将每个每个像素分类,例如"它是汽车"或者"不是汽车" 。这些问题是对象检测分割

有些研究解决了这些问题(one exampleanother),但我的建议是看看Tensorflow的object detection API哪些有预先训练的模型你可能会利用你的用例。