def unpackLabel(self, label):
     label_ohc = np.reshape(label[:, :, :, GridParams().numBBox:],
                            (GridParams().numGridX, GridParams().numGridY,
                             GridParams().numBBox * GridParams().numClass))
     label_box = np.reshape(
         label[:, :, :, 0:GridParams().numBBox],
         (GridParams().numGridX, GridParams().numGridY,
          GridParams().numBBox * GridParams().numBBoxElements))
     objIds = self.unpackOHCLabel(label_ohc)
     offset, bb = self.unpackBBoxLabel(label_box)
     return objIds, offset, bb
 def unpackOHCLabel(self, label_ohc):
     objIds = []
     for i in range(0, GridParams().numGridX):
         for j in range(0, GridParams().numGridY):
             for k in range(0, GridParams().limNumBBoxPerGrid):
                 line = label_ohc[i, j, k * GridParams().numClass:(k + 1) *
                                  GridParams().numClass]
                 c = np.where(line == 1)[0]
                 if (c.shape[0]) == 1:
                     objIds.append(c[0])
                 else:
                     break
     return objIds
    def unpackBBoxLabel(self, label_box):
        bbList = []
        oxyList = []
        for i in range(0, GridParams().numGridX):
            for j in range(0, GridParams().numGridY):
                for k in range(0, GridParams().limNumBBoxPerGrid):
                    flag = label_box[i, j, k * GridParams().numBBoxElements]
                    if flag >= 0.5:
                        start = k * GridParams().numBBoxElements + 1
                        bb = label_box[i, j, start:start + 4]
                        oxy = np.array([i, j])
                        bbList.append(bb)
                        oxyList.append(oxy)
        bb_centers_wh = np.array(bbList)
        offset = None
        bboxes = None
        try:
            bb_centers_wh[:, 0:2] *= GridParams().gridW
            bb_centers_wh[:, 2:4] *= GridParams().imgW

            offset = GridParams().gridW * np.array(oxyList)
            bboxes = bb_centers_wh
            bboxes[:, 0] += offset[:, 0] - bboxes[:, 2] / 2
            bboxes[:, 1] += offset[:, 1] - bboxes[:, 3] / 2
        except:
            print(bb_centers_wh.shape)
        return offset, bboxes.astype(int) if bboxes is not None else None
Example #4
0
    def getBBoxes_Relative(self, offset, relX, relY, bboxes):
        label = np.zeros((bboxes.shape[0], GridParams().numBBoxElements))
        ox, oy = np.zeros(((bboxes.shape[0])), dtype=int), np.zeros(
            ((bboxes.shape[0])), dtype=int)
        for i in range(0, bboxes.shape[0]):
            x = int(offset[i, 0] / self.gridW)
            y = int(offset[i, 1] / self.gridH)

            w = bboxes[i, 2] / self.imgW
            h = bboxes[i, 3] / self.imgH

            ox[i] = x
            oy[i] = y
            label[i, :] = np.array([
                1, relX[i] / GridParams().gridW, relY[i] / GridParams().gridW,
                w, h
            ])

        return ox, oy, label
    def packBBoxAndObj(self, res_bb, objIds):
        label = np.zeros((GridParams().numGridX, GridParams().numGridY,
                          GridParams().numBBox, 5 + GridParams().numClass))
        offset, relX, relY = self.convG2L.getBBoxCenter_Absolute(res_bb)

        ox, oy, label_box = self.convG2L.getBBoxes_Relative(
            offset, relX, relY, res_bb)
        #print(label_box.shape)
        counter = np.zeros((GridParams().numGridX, GridParams().numGridY),
                           dtype=int)
        for i in range(0, res_bb.shape[0]):
            c = counter[ox[i], oy[i]]
            if c < GridParams().limNumBBoxPerGrid:
                table = np.concatenate(
                    [label_box[i, :],
                     self.getOneHotCode(objIds[i])], axis=0)
                label[ox[i], oy[i], c, :] = table
                counter[ox[i], oy[i]] += 1
        return counter, label
 def isMoreThanOneObjPerGrid(self, counter):
     for i in range(0, GridParams().numGridX):
         for j in range(0, GridParams().numGridY):
             if counter[i, j] > 1:
                 return True
     return False
Example #7
0
 def __init__(self):
     self.numGridX, self.numGridY = GridParams().numGridX, GridParams(
     ).numGridY
     self.imgW, self.imgH = GridParams().imgW, GridParams().imgH
     self.gridW = GridParams().gridW
     self.gridH = GridParams().gridH