object - 如何在没有 nms 的情况下从 Tensorflow 对象检测 ssd-mobilenet 解码 raw_outputs/box_encodings

标签 object tensorflow detection

为了在android上部署自己的ssd-mobile模型并使用NNAPI加速,我根据tensorflow objection detection API重新训练了没有NMS后处理的模型。 没有NMS,输出的raw_outputs/box_encodings是encoded box location,我解码如下,但是不行:

for(int j =0; j < 5; j++)
               {
                   float sk = (float)(0.2 + (0.949 - 0.200) *j * 1.0 / 5*1.0);
                   float width_a = (float)(sk * Math.sqrt(aspectra[j]));
                   float height_a = (float)(sk * 1.0 / Math.sqrt(aspectra[j]));
                   for(int k = 0; k < featuresize[j] ; k++)
                   {
                       float center_x_a = (float)((k + 0.5) * 1.0/ featuresize[j]);
                       float center_y_a = (float)((k + 0.5) * 1.0/ featuresize[j]);

                       float ty = (float)(outputBox[0][i][0] / 10.);
                       float tx = (float)(outputBox[0][i][1] /  10.);
                       float th = (float)(outputBox[0][i][2] / 5.);
                       float tw = (float)(outputBox[0][i][3] / 5.);

                       float w =(float)(Math.exp(tw) * width_a);
                       float h = (float)(Math.exp(th) * height_a);
                       float y_center = ty * height_a + center_y_a;
                       float x_ceneter = tx * width_a + center_x_a;


                       float ymin = (float)((y_center - h ) / 2.);
                       float xmin = (float)((x_ceneter - w ) / 2.);
                       float ymax = (float)((y_center + h ) / 2.);
                       float xmax = (float)((x_ceneter + w ) / 2.);

最佳答案

为了解码 raw_outputs/box_encodings,您还需要 anchors,因为 box_encodings 是根据 anchor 编码的。

下面是我解码raw_outputs/box_encodings的实现:

private float[][][] decodeBoxEncodings(final float[][][] boxEncoding, final float[][] anchor, final int numBoxes) {
    final float[][][] decodedBoxes = new float[1][numBoxes][4];
    for (int i = 0; i < numBoxes; ++i) {

        final double ycenter = boxEncoding[0][i][0] / y_scale * anchor[i][2] + anchor[i][0];
        final double xcenter = boxEncoding[0][i][1] / x_scale * anchor[i][3] + anchor[i][1];
        final double half_h = 0.5 * Math.exp((boxEncoding[0][i][2] / h_scale)) * anchor[i][2];
        final double half_w = 0.5 * Math.exp((boxEncoding[0][i][3] / w_scale)) * anchor[i][3];

        decodedBoxes[0][i][0] = (float)(ycenter - half_h);   //ymin
        decodedBoxes[0][i][1] = (float)(xcenter - half_w);   //xmin
        decodedBoxes[0][i][2] = (float)(ycenter + half_h);   //ymax
        decodedBoxes[0][i][3] = (float)(xcenter + half_w);   //xmax
    }
    return decodedBoxes;
}

此解码技术来自 TFLite detection_postprocess操作。

编辑:比例值是:

float y_scale = 10.0f;
float x_scale = 10.0f;
float h_scale = 5.0f;
float w_scale = 5.0f;

关于object - 如何在没有 nms 的情况下从 Tensorflow 对象检测 ssd-mobilenet 解码 raw_outputs/box_encodings,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54436186/

相关文章:

SpriteKit 如何添加激光束并在碰撞点调整其大小

javascript - 检测 WebSocket 的无效证书

c++ - 重新启动游戏并重新实例化对象

python - 禁用 Tensorflow/Numpy 弃用警告消息

Java颜色检测

tensorflow - keras中的fit_generator : where is the batch_size specified?

machine-learning - tensorflow 的逻辑回归不起作用

Python: 'int' 对象不可订阅

JavaScript 图像对象

javascript - Javascript 数组中的未定义值是否使用任何内存或在 for-in 循环中迭代?