Esempio n. 1
0
def get_hypercolumn_prediction(net, img, boxes, categids):
  boxes = boxes.copy()
  #clip boxes to image
  boxes = clip_boxes(boxes-1, img.shape) 

  im_new, spp_boxes, normalized_boxes, categids = get_blobs(img, boxes, categids)
  #reshape the network
  net.blobs['image'].reshape(*(im_new.shape))
  net.blobs['normalizedboxes'].reshape(*(normalized_boxes.shape))
  net.blobs['sppboxes'].reshape(*(spp_boxes.shape))
  net.blobs['categids'].reshape(*(categids.shape))

  #forward
  output_blobs = net.forward(image=im_new, normalizedboxes=normalized_boxes,sppboxes=spp_boxes, categids=categids)

  output =output_blobs['loss']
  return output
Esempio n. 2
0
    def reshape(self, bottom, top):
        #sample a category
        categid = np.random.choice(self.numclasses)
        #sample an image for this category
        imid = self.data_percateg[categid]['imids'][np.random.choice(
            len(self.data_percateg[categid]['imids']))]

        img = cv2.imread(self._params.imgpath.format(self.names[imid]))

        #get all possibilities for this category
        start = self.data_percateg[categid]['im_end_index'][imid] + 1
        stop = self.data_percateg[categid]['im_end_index'][imid + 1]
        #pick a box
        idx = np.random.choice(np.arange(start, stop + 1),
                               cfg.TRAIN_SAMPLES_PER_IMG)
        boxid = self.data_percateg[categid]['boxids'][idx]
        boxes = self.boxes[imid][boxid, :] - 1

        instid = self.data_percateg[categid]['instids'][idx]
        #load the gt
        [inst, categories] = sbd.load_gt(self.names[imid])
        masks = np.zeros((idx.size, 1, inst.shape[0], inst.shape[1]))
        for k in range(idx.size):
            masks[k, 0, :, :] = (inst == instid[k] + 1).astype(np.float32)
        categids = categid * np.ones(idx.size)

        #get the blobs
        im_new, spp_boxes, normalized_boxes, categids, masksblob, instance_wts = get_blobs(
            img, boxes.astype(np.float32), categids, masks)

        #save blobs in private dict
        self.myblobs['image'] = im_new.astype(np.float32)
        self.myblobs['normalizedboxes'] = normalized_boxes.astype(np.float32)
        self.myblobs['sppboxes'] = spp_boxes.astype(np.float32)
        self.myblobs['categids'] = categids.astype(np.float32)
        self.myblobs['labels'] = masksblob.astype(np.float32)
        self.myblobs['instance_wts'] = instance_wts.astype(np.float32)

        #and reshape
        for i in range(len(top)):
            top[i].reshape(*(self.myblobs[self.blob_names[i]].shape))
Esempio n. 3
0
  def reshape(self, bottom, top):
    #sample a category
    categid = np.random.choice(self.numclasses)
    #sample an image for this category
    imid = self.data_percateg[categid]['imids'][np.random.choice(len(self.data_percateg[categid]['imids']))]
    
    img = cv2.imread(self._params.imgpath.format(self.names[imid]))

    #get all possibilities for this category
    start = self.data_percateg[categid]['im_end_index'][imid]+1
    stop = self.data_percateg[categid]['im_end_index'][imid+1]
    #pick a box
    idx = np.random.choice(np.arange(start,stop+1), cfg.TRAIN_SAMPLES_PER_IMG)
    boxid = self.data_percateg[categid]['boxids'][idx]
    boxes = self.boxes[imid][boxid,:]-1    

    instid = self.data_percateg[categid]['instids'][idx]
    #load the gt
    [inst, categories] = sbd.load_gt(self.names[imid])
    masks = np.zeros((idx.size, 1,inst.shape[0],inst.shape[1]))
    for k in range(idx.size):
      masks[k,0,:,:] = (inst==instid[k]+1).astype(np.float32)
    categids = categid*np.ones(idx.size)

    #get the blobs
    im_new, spp_boxes, normalized_boxes, categids, masksblob, instance_wts = get_blobs(img, boxes.astype(np.float32), categids, masks)

    #save blobs in private dict
    self.myblobs['image']=im_new.astype(np.float32)
    self.myblobs['normalizedboxes']=normalized_boxes.astype(np.float32)
    self.myblobs['sppboxes']=spp_boxes.astype(np.float32)
    self.myblobs['categids']=categids.astype(np.float32)
    self.myblobs['labels']=masksblob.astype(np.float32)
    self.myblobs['instance_wts']=instance_wts.astype(np.float32)

    #and reshape
    for i in range(len(top)):
      top[i].reshape(*(self.myblobs[self.blob_names[i]].shape))