当前位置:网站首页>目标检测学习笔记——paddleDetection使用

目标检测学习笔记——paddleDetection使用

2022-08-11 11:26:00 phily123

一、修改图片缩放尺寸为32的倍数
ppdet\data\transform\operators.py中:

    def apply(self, sample, context=None):
        """ Resize the image numpy. """
        im = sample['image']
        if not isinstance(im, np.ndarray):
            raise TypeError("{}: image type is not numpy.".format(self))
        if len(im.shape) != 3:
            raise ImageError('{}: image is not 3-dimensional.'.format(self))

        # apply image
        im_shape = im.shape
        if self.keep_ratio:

            im_size_min = np.min(im_shape[0:2])
            im_size_max = np.max(im_shape[0:2])

            target_size_min = np.min(self.target_size)
            target_size_max = np.max(self.target_size)

            im_scale = min(target_size_min / im_size_min,
                           target_size_max / im_size_max)

            resize_h = im_scale * float(im_shape[0])
            resize_w = im_scale * float(im_shape[1])
            resize_w = resize_w // 32 * 32
            #im_scale_x = im_scale
            #im_scale_y = im_scale
            im_scale_x = resize_w / im.shape[1]
            im_scale_y = resize_h / im.shape[0]
        else:
            resize_h, resize_w = self.target_size
            im_scale_y = resize_h / im_shape[0]
            im_scale_x = resize_w / im_shape[1]

        im = self.apply_image(sample['image'], [im_scale_x, im_scale_y])
        sample['image'] = im
        sample['im_shape'] = np.asarray([resize_h, resize_w], dtype=np.float32)
原网站

版权声明
本文为[phily123]所创,转载请带上原文链接,感谢
https://blog.csdn.net/phily123/article/details/126149677