| 79 | |
| 80 | |
| 81 | class ValPre(object): |
| 82 | def __init__(self, norm_mean, norm_std, sign=False, config=None): |
| 83 | self.config = config |
| 84 | self.norm_mean = norm_mean |
| 85 | self.norm_std = norm_std |
| 86 | self.sign = sign |
| 87 | |
| 88 | def __call__(self, rgb, gt, modal_x): |
| 89 | # pad to 730*531 |
| 90 | if self.config.pad: |
| 91 | rgb = cv2.copyMakeBorder( |
| 92 | rgb, |
| 93 | 0, |
| 94 | 531 - rgb.shape[0], |
| 95 | 0, |
| 96 | 730 - rgb.shape[1], |
| 97 | cv2.BORDER_CONSTANT, |
| 98 | value=(0.0, 0.0, 0.0), |
| 99 | ) |
| 100 | gt = cv2.copyMakeBorder( |
| 101 | gt, |
| 102 | 0, |
| 103 | 531 - gt.shape[0], |
| 104 | 0, |
| 105 | 730 - gt.shape[1], |
| 106 | cv2.BORDER_CONSTANT, |
| 107 | value=(255,), |
| 108 | ) |
| 109 | modal_x = cv2.copyMakeBorder( |
| 110 | modal_x, |
| 111 | 0, |
| 112 | 531 - modal_x.shape[0], |
| 113 | 0, |
| 114 | 730 - modal_x.shape[1], |
| 115 | cv2.BORDER_CONSTANT, |
| 116 | value=(0.0, 0.0, 0.0), |
| 117 | ) |
| 118 | |
| 119 | # rgb = cv2.resize( |
| 120 | # rgb, |
| 121 | # (self.config.image_width, self.config.image_height), |
| 122 | # interpolation=cv2.INTER_LINEAR, |
| 123 | # ) |
| 124 | # gt = cv2.resize( |
| 125 | # gt, |
| 126 | # (self.config.image_width, self.config.image_height), |
| 127 | # interpolation=cv2.INTER_NEAREST, |
| 128 | # ) |
| 129 | # modal_x = cv2.resize( |
| 130 | # modal_x, |
| 131 | # (self.config.image_width, self.config.image_height), |
| 132 | # interpolation=cv2.INTER_LINEAR, |
| 133 | # ) |
| 134 | |
| 135 | rgb = normalize(rgb, self.norm_mean, self.norm_std) |
| 136 | modal_x = normalize(modal_x, [0.48, 0.48, 0.48], [0.28, 0.28, 0.28]) |
| 137 | return rgb.transpose(2, 0, 1), gt, modal_x.transpose(2, 0, 1) |
| 138 | # return rgb, gt, modal_x |