当前位置: 首页>>代码示例>>Python>>正文


Python nd.topk方法代码示例

本文整理汇总了Python中mxnet.nd.topk方法的典型用法代码示例。如果您正苦于以下问题:Python nd.topk方法的具体用法?Python nd.topk怎么用?Python nd.topk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mxnet.nd的用法示例。


在下文中一共展示了nd.topk方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _topk

# 需要导入模块: from mxnet import nd [as 别名]
# 或者: from mxnet.nd import topk [as 别名]
def _topk(scores, K=40):
    batch, cat, height, width = scores.shape

    [topk_scores, topk_inds] = nd.topk(nd.reshape(scores, (batch, cat, -1)), ret_typ='both', k=K)  # return both value and indices

    topk_inds = topk_inds % (height * width)
    topk_ys   = (topk_inds / width).astype('int32').astype('float32')
    topk_xs   = (topk_inds % width).astype('int32').astype('float32')

    [topk_score, topk_ind] = nd.topk(nd.reshape(topk_scores, (batch, -1)), ret_typ='both', k=K)
    topk_clses = (topk_ind / K).astype('int32')

    topk_inds = _gather_feat(nd.reshape(topk_inds, (batch, -1, 1)), topk_ind)
    topk_inds = nd.reshape(topk_inds, (batch, K))

    topk_ys = _gather_feat(nd.reshape(topk_ys, (batch, -1, 1)), topk_ind)
    topk_ys = nd.reshape(topk_ys, (batch, K))

    topk_xs = _gather_feat(nd.reshape(topk_xs, (batch, -1, 1)), topk_ind)
    topk_xs = nd.reshape(topk_xs, (batch, K))

    return topk_score, topk_inds, topk_clses, topk_ys, topk_xs 
开发者ID:Guanghan,项目名称:mxnet-centernet,代码行数:24,代码来源:decoder.py

示例2: symbolic_topk

# 需要导入模块: from mxnet import nd [as 别名]
# 或者: from mxnet.nd import topk [as 别名]
def symbolic_topk(F, scores, K=40):
    batch, cat, height, width = 1, 1, 128.0, 128.0

    [topk_scores, topk_inds] = F.topk(scores.reshape((batch, cat, -1)), ret_typ='both', k=K)  # return both value and indices

    topk_inds = topk_inds % (height * width)
    topk_ys   = (topk_inds / width).astype('int32').astype('float32')
    topk_xs   = (topk_inds % width).astype('int32').astype('float32')

    [topk_score, topk_ind] = F.topk(topk_scores.reshape((batch, -1)), ret_typ='both', k=K)
    topk_clses = (topk_ind / K).astype('int32')

    topk_inds = symbolic_gather_feat(F, topk_inds.reshape((batch, -1, 1)), topk_ind, K, attri=1)
    topk_inds = topk_inds.reshape((batch, K))

    topk_ys = symbolic_gather_feat(F, topk_ys.reshape((batch, -1, 1)), topk_ind, K, attri=1)
    topk_ys = topk_ys.reshape((batch, K))

    topk_xs = symbolic_gather_feat(F, topk_xs.reshape((batch, -1, 1)), topk_ind, K, attri=1)
    topk_xs = topk_xs.reshape((batch, K))

    return topk_score, topk_inds, topk_clses, topk_ys, topk_xs 
开发者ID:Guanghan,项目名称:mxnet-centernet,代码行数:24,代码来源:decoder.py

示例3: get_attribute

# 需要导入模块: from mxnet import nd [as 别名]
# 或者: from mxnet.nd import topk [as 别名]
def get_attribute(self, image): 
        """Face attribute predictor.
        Parameters
        ----------
        image: NDArray.
            The NDArray data format for MXNet to process, such as (H, W, C).
        Returns
        -------
        type: tuple
            Results of Face Attribute Predict:
            (str(gender), int(age), str(expression)).
        """     
        img = transform_eval(image, resize_short=self._image_size, crop_size=self._image_size)
        img = img.as_in_context(self.ctx[0])   
        tic = time.time()
        pred = self.net(img)
        toc = time.time() - tic
        print('Attribute inference time: %fms' % (toc*1000))

        topK = 1
        topK_age = 6
        topK_exp = 2
        age = 0
        ind_1 = nd.topk(pred[0], k=topK)[0].astype('int')
        ind_2 = nd.topk(pred[1], k=topK_age)[0].astype('int')
        ind_3 = nd.topk(pred[2], k=topK_exp)[0].astype('int')
        for i in range(topK_age):
            age += int(nd.softmax(pred[1])[0][ind_2[i]].asscalar() * self.attribute_map2[1][ind_2[i].asscalar()])
        gender = self.attribute_map2[0][ind_1[0].asscalar()]
        if  nd.softmax(pred[2])[0][ind_3[0]].asscalar() < 0.45:
            expression = self.attribute_map2[2][7]
        else:
            expression_1 = self.attribute_map2[2][ind_3[0].asscalar()]
            expression_2 = self.attribute_map2[2][ind_3[1].asscalar()]  

        return (gender, age, (expression_1, expression_2)) 
开发者ID:becauseofAI,项目名称:MobileFace,代码行数:38,代码来源:mobileface_attribute_predictor.py

示例4: _topk_channel

# 需要导入模块: from mxnet import nd [as 别名]
# 或者: from mxnet.nd import topk [as 别名]
def _topk_channel(scores, K=40):
    batch, cat, height, width = scores.shape

    [topk_scores, topk_inds] = nd.topk(scores.reshape((batch, cat, -1)), ret_typ = "both", k= K)

    #[topk_score, topk_ind] = nd.topk(nd.reshape(topk_scores, (batch, -1)), ret_typ='both', k=K)

    topk_inds = topk_inds % (height * width)
    #topk_ys   = (topk_inds / width).astype('int32').astype('float32')
    #topk_xs   = (topk_inds % width).astype('int32').astype('float32')
    topk_ys   = (topk_inds / width).astype('int64').astype('float32')
    topk_xs   = (topk_inds % width).astype('int64').astype('float32')

    return topk_scores, topk_inds, topk_ys, topk_xs 
开发者ID:Guanghan,项目名称:mxnet-centernet,代码行数:16,代码来源:decoder.py

示例5: symbolic_topk_channel

# 需要导入模块: from mxnet import nd [as 别名]
# 或者: from mxnet.nd import topk [as 别名]
def symbolic_topk_channel(F, scores, K=40):
    scores_shape = F.shape_array(scores)
    batch, cat, height, width = 1, 1, 128.0, 128.0

    [topk_scores, topk_inds] = F.topk(scores.reshape((batch, cat, -1)), ret_typ = "both", k= K)

    topk_inds = topk_inds % (height * width)
    topk_ys   = (topk_inds / width).astype('int32').astype('float32')
    topk_xs   = (topk_inds % width).astype('int32').astype('float32')

    return topk_scores, topk_inds, topk_ys, topk_xs 
开发者ID:Guanghan,项目名称:mxnet-centernet,代码行数:13,代码来源:decoder.py


注:本文中的mxnet.nd.topk方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。