Ejemplo n.º 1
0
 def forward(self,  im_data, gt_data=None):        
     im_data = network.np_to_variable(im_data, is_cuda=True, is_training=self.training)                
     density_map = self.DME(im_data)
     
     if self.training:                        
         gt_data = network.np_to_variable(gt_data, is_cuda=True, is_training=self.training)            
         self.loss_mse = self.build_loss(density_map, gt_data)
         
     return density_map
Ejemplo n.º 2
0
 def forward(self,  im_data, gt_data=None, gt_cls_label=None, ce_weights=None):        
     im_data = network.np_to_variable(im_data, is_cuda=False, is_training=self.training)                        
     density_map, density_cls_score = self.CCN(im_data)
     
     if self.training:                        
         density_cls_prob = F.softmax(density_cls_score, dim=1)
         gt_data = network.np_to_variable(gt_data, is_cuda=False, is_training=self.training)            
         gt_cls_label = network.np_to_variable(gt_cls_label, is_cuda=False, is_training=self.training,dtype=torch.FloatTensor)                        
         self.loss_mse, self.cross_entropy = self.build_loss(density_map, density_cls_prob, gt_data, gt_cls_label, ce_weights)
         
         
     return density_map
Ejemplo n.º 3
0
    def __index__(self, i):
        bid, pid = self.patch_list[i]

        ncl = self.ncls[bid + 1]
        choice = self.choices[bid + 1]
        idx, image, label = self.sample_dict[bid + 1][ncl][choice]
        img, den, gt_count = self.loaded[idx]

        transform_img = []
        transform_den = []
        transform_raw = []

        transform_raw.append(
            transforms.Lambda(lambda img: i_crop(img, self.patches[bid][pid],
                                                 self.crop_size)))
        transform_raw.append(
            transforms.Lambda(lambda img: i_flip(img, self.filps[i])))
        transform_raw.append(transforms.Lambda(lambda img: np.array(img)))
        transform_raw = transforms.Compose(transform_raw)

        transform_img.append(
            transforms.Lambda(lambda img: i_crop(img, self.patches[bid][pid],
                                                 self.crop_size)))
        transform_img.append(
            transforms.Lambda(lambda img: i_flip(img, self.filps[i])))
        transform_img += [
            transforms.ToTensor(),
            transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
        ]
        transform_img = transforms.Compose(transform_img)

        transform_den.append(
            transforms.Lambda(lambda img: d_crop(img, self.patches[bid][pid],
                                                 self.crop_size)))
        transform_den.append(
            transforms.Lambda(lambda img: d_flip(img, self.filps[i])))
        transform_den += [
            transforms.Lambda(lambda den: network.np_to_variable(
                den, is_cuda=False, is_training=self.training))
        ]
        transform_den = transforms.Compose(transform_den)

        return transform_img(img.copy()), transform_den(den), transform_raw(
            img.copy()), gt_count, i
Ejemplo n.º 4
0
    def __index__(self, i):
        '''bid: image index; pid: patch index, to find slice'''
        bid, pid = self.patch_list[i]
        transform_img = []
        transform_den = []
        transform_raw = []

        transform_raw.append(
            transforms.Lambda(lambda img: i_crop(img, self.patches[bid][pid],
                                                 self.crop_size)))
        transform_raw.append(
            transforms.Lambda(lambda img: i_flip(img, self.filps[i])))
        transform_raw.append(transforms.Lambda(lambda img: np.array(img)))
        transform_raw = transforms.Compose(transform_raw)

        transform_img.append(
            transforms.Lambda(lambda img: i_crop(img, self.patches[bid][pid],
                                                 self.crop_size)))
        transform_img.append(
            transforms.Lambda(lambda img: i_flip(img, self.filps[i])))
        transform_img += [
            transforms.ToTensor(),
            transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
        ]
        transform_img = transforms.Compose(transform_img)
        transform_den.append(
            transforms.Lambda(lambda img: d_crop(img, self.patches[bid][pid],
                                                 self.crop_size)))
        transform_den.append(
            transforms.Lambda(lambda img: d_flip(img, self.filps[i])))
        transform_den += [
            transforms.Lambda(lambda den: network.np_to_variable(
                den, is_cuda=False, is_training=self.training))
        ]
        transform_den = transforms.Compose(transform_den)

        img, den, gt_count = self.dataloader[bid]

        return transform_img(img.copy()), transform_den(den), transform_raw(
            img.copy()), gt_count, i