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

我是tensorflow的新手,我想知道如何在检测对象时同时获取其“类别”和分数?

这是一个样本图像的分数数组,你可以看到有4个“框”的置信度超过50%:

    scoresOut[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)

我想知道如何获取这些分数所代表的对象类别,我在任何变量中似乎都找不到。这里是返回的列表:

    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',

这是使用了github上object_detection教程中的主要教程脚本,可以在这里找到: https://github.com/tensorflow/models/tree/master/research/object_detection

任何帮助都将不胜感激。谢谢,


回答:

我猜你指的是这个笔记本。

我查看了代码,分数数组表示每个检测框的置信度。每个框的类别在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})

为了打印类别和分数,你可以:

for class, score in zip(classes, scores):    print(class, ':', score)

笔记本中使用的类别描述在这里(mscoco标签):https://github.com/tensorflow/models/blob/master/research/object_detection/data/mscoco_label_map.pbtxt

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注