如何获取检测到的对象的类别 - tensorflow

Dav*_*ime 2 python machine-learning object-detection tensorflow

我是张力流的新手,我想知道如何获得检测到的物体的"类别"及其得分?

这是一个我用于样本图像的分数数组,因为你可以看到有4个''框',信心超过50%:

    scores
Out[104]: 
array([[ 0.86274904,  0.68427145,  0.53348649,  0.51449829,  0.4737072 ,
         0.20210901,  0.18676876,  0.15660423,  0.15557742,  0.15542269,
         0.15463693,  0.14486608,  0.13966955,  0.1298867 ,  0.12409254,
         0.12288965,  0.10780571,  0.10559474,  0.10537479,  0.10148374,
         0.10037792,  0.09754734,  0.09640686,  0.09590817,  0.09435588,
         0.09198856,  0.0918662 ,  0.09173656,  0.0879355 ,  0.08762371,
         0.08711197,  0.08627746,  0.08621041,  0.08481266,  0.08390592,
         0.08365501,  0.08259587,  0.08251529,  0.08152138,  0.08019584,
         0.07996205,  0.07962734,  0.07907323,  0.07718709,  0.07715672,
         0.07693762,  0.07692765,  0.07642546,  0.07611038,  0.07582222,
         0.0754476 ,  0.07542069,  0.07490928,  0.07476845,  0.0747645 ,
         0.07418264,  0.07383376,  0.07275221,  0.07237192,  0.0722541 ,
         0.07183521,  0.07175662,  0.07174246,  0.07155806,  0.071283  ,
         0.0710848 ,  0.07026858,  0.06924678,  0.06890308,  0.06833564,
         0.06827622,  0.06769758,  0.06753176,  0.06721075,  0.0663776 ,
         0.06553975,  0.06466822,  0.06375053,  0.06349288,  0.0633459 ,
         0.06320453,  0.06309631,  0.06307632,  0.06258182,  0.06233004,
         0.06231011,  0.06228941,  0.06161467,  0.06125913,  0.06117567,
         0.06101252,  0.06089024,  0.0608751 ,  0.06063354,  0.06047466,
         0.06046106,  0.0603817 ,  0.06035899,  0.06034132,  0.06016544]], dtype=float32)
Run Code Online (Sandbox Code Playgroud)

我想知道的是你如何获得每个分数对对象进行分类的输出,我似乎无法在任何变量中看到它.这是返回的列表:

    print(locals().keys())
dict_keys(['__name__', '__builtin__', '__builtins__', '_ih', '_oh', '_dh', 'In', 'Out', 'get_ipython', 'exit', 'quit', '_i', '_ii', '_iii', '_i52', 'np', 'os', 'urllib', 'sys', 'tarfile', 'tf', 'zipfile', 'defaultdict', 'StringIO', 'plt', 'Image', 'total_count', 'label_map_util', 'vis_util', 'MODEL_NAME', 'MODEL_FILE', 'DOWNLOAD_BASE', 'PATH_TO_CKPT', 'PATH_TO_LABELS', 'NUM_CLASSES', 'opener', 'tar_file', 'file', 'file_name', 'detection_graph', 'od_graph_def', 'fid', 'serialized_graph', 'label_map', 'categories', 'category_index', 'load_image_into_numpy_array', 'PATH_TO_TEST_IMAGES_DIR', 'TEST_IMAGE_PATHS', 'IMAGE_SIZE', 'sess', 'image_tensor', 'detection_boxes', 'detection_scores', 'detection_classes', 'num_detections', 'image_path', 'image', 'image_np', 'image_np_expanded', 'boxes', 'scores', 'classes', 'num',
Run Code Online (Sandbox Code Playgroud)

这是使用github上的object_detection教程中的主要教程脚本:https://github.com/tensorflow/models/tree/master/research/object_detection

任何帮助,将不胜感激.干杯,

Mih*_*uja 5

我假设你在谈论这款笔记本.

我查看了代码,得分数组表示每个检测到的框的置信度.每个框的类都在classes变量(detection_classes:0张量)中.

此行通过网络运行输入:

(boxes, scores, classes, num) = sess.run(
          [detection_boxes, detection_scores, detection_classes, num_detections],
          feed_dict={image_tensor: image_np_expanded})
Run Code Online (Sandbox Code Playgroud)

要打印课程以及分数,您可以:

for class, score in zip(classes, scores):
    print(class, ':', score)
Run Code Online (Sandbox Code Playgroud)

在笔记本中使用类别的描述是在这里(mscoco标签).