【问题标题】:How to access index of a class label in from mxnet nd array? The output must be index of the label name entered with function如何从 mxnet nd 数组中访问类标签的索引?输出必须是使用函数输入的标签名称的索引
【发布时间】:2023-04-08 01:13:02
【问题描述】:
#pred_probas is probabilities of each class type
def find_class_idx(label):
    """
    Should return the class index of a particular label.

    :param label: label of class
    :type label: str

    :return: class index
    :rtype: int
    """
    #ind = mx.nd.argmax(label, axis=1).astype('int')
    topk_indices=mx.nd.topk(pred_probas,k=100)
    return max(topk_indices)*100

【问题讨论】:

    标签: python arrays function indexing mxnet


    【解决方案1】:

    由于 GluonCV 的网络输出类是列表类型的。我们可以使用这个函数 list.index(label) 访问列表的索引

    def find_class_idx(label):
    """
    Should return the class index of a particular label.
    
    :param label: label of class
    :type label: str
    
    :return: class index
    :rtype: int
    """
    
    return network.classes.index(label)
    

    【讨论】:

      猜你喜欢
      • 2021-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多