示例#1
0
 def get_template_z(self, pos_x, pos_y, z_sz, image, design):
     if isinstance(image, six.string_types):
         image = Image.open(image).convert('RGB')
     avg_chan = ImageStat.Stat(image).mean
     frame_padded_z, npad_z = pad_frame(image, image.size, pos_x, pos_y,
                                        z_sz, avg_chan)
     z_crops = extract_crops_z(frame_padded_z, npad_z, pos_x, pos_y, z_sz,
                               design.exemplar_sz)
     template_z = self.branch(Variable(z_crops).cuda())
     return image, template_z
示例#2
0
    def get_scores(self, pos_x, pos_y, scaled_search_area, template_z,
                   filename, design, final_score_sz):
        image = Image.open(filename).convert('RGB')
        avg_chan = ImageStat.Stat(image).mean
        frame_padded_x, npad_x = pad_frame(image, image.size, pos_x, pos_y,
                                           scaled_search_area[2], avg_chan)
        x_crops = extract_crops_x(frame_padded_x, npad_x, pos_x, pos_y,
                                  scaled_search_area[0], scaled_search_area[1],
                                  scaled_search_area[2], design.search_sz)

        template_x = self.branch(Variable(x_crops).cuda())

        template_z = template_z.repeat(template_x.size(0), 1, 1, 1)

        scores = self.model.head(template_z, template_x)

        # scores = self.bn_adjust(scores)
        # TODO: any elegant alternator?
        scores = scores.squeeze().permute(1, 2, 0).data.cpu().numpy()
        scores_up = cv2.resize(scores, (final_score_sz, final_score_sz),
                               interpolation=cv2.INTER_CUBIC)
        scores_up = scores_up.transpose((2, 0, 1))
        return image, scores_up