Esempio n. 1
0
def validate(model):
    
    anchor = generate_anchor(8, [8, ], [0.33, 0.5, 1, 2, 3], 17)
    
    prec1 = 0
    model = model.eval()
    transform=transforms.Compose([
                       transforms.ToTensor(),transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                     std=[0.229, 0.224, 0.225]),
                   ])
    lines = []
    for k in xrange(20):
        all_sample = [ args.vot2018[i] for i in sorted(random.sample(xrange(len(args.vot2018)), 30)) ]

        nSamples = len(all_sample)
        for i in xrange(nSamples):

            sequence = all_sample[i]
            ran_id = random.randint(0,len(sequence)-1)

            while len(sequence[ran_id])<2:

                        sequence = all_sample[random.randint(0,nSamples-1)]

                        ran_id = random.randint(0,len(sequence)-1)

            track_obj = sequence[ran_id]

            ran_f1 = random.randint(0,len(track_obj)-1)

            ran_f2 = random.randint(0,len(track_obj)-1)
            lines.append([track_obj[ran_f1],track_obj[ran_f2]])
        random.shuffle(lines)
        
    for line in lines:
        
        z,x,gt_box,regression_target,conf_target= load_data(line,0)
        
        inpz = transform(z)
        inpx = transform(x)
        score, delta = model(inpz.unsqueeze(0).cuda(),inpx.unsqueeze(0).cuda())
        
        delta = delta.permute(1, 2, 3, 0).contiguous().view(4, -1).data.cpu().numpy()
        score = F.softmax(score.permute(1, 2, 3, 0).contiguous().view(2, -1), dim=0).data[1, :].cpu().numpy()
        delta[0, :] = delta[0, :] * anchor[:, 2] + anchor[:, 0]
        delta[1, :] = delta[1, :] * anchor[:, 3] + anchor[:, 1]
        delta[2, :] = np.exp(delta[2, :]) * anchor[:, 2]
        delta[3, :] = np.exp(delta[3, :]) * anchor[:, 3]
        best_pscore_id = np.argmax(score)
        target = delta[:, best_pscore_id]
        prec1 += bbox_iou(target, gt_box, False)
    prec1 = prec1/600
        
        
        

        
    
        
    return prec1
Esempio n. 2
0
    def __getitem__(self, index):
        assert index <= len(self), 'index range error'

        img_path = self.lines[index]
        img, target = load_data(img_path, self.train)

        if self.transform is not None:
            img = self.transform(img)
        return img, target
    def __getitem__(self, index):
        assert index <= len(self), 'index range error'

        img_path = self.lines[index]

        img, target, smap = load_data(img_path)
        img = self.transform(img)

        return img, target, smap
Esempio n. 4
0
def pre_data(train_list, args, train):
    print("Pre_load dataset ......")
    data_keys = {}
    count = 0
    for j in range(len(train_list)):
        Img_path = train_list[j]
        fname = os.path.basename(Img_path)
        img, gt_count = load_data(Img_path, args, train)

        blob = {}
        blob['img'] = img
        blob['gt_count'] = gt_count
        blob['fname'] = fname
        data_keys[count] = blob
        count += 1
        '''for debug'''
        # if j> 10:
        #     break
    return data_keys