process_image
(sample, mode, color_jitter, rotate,
crop_size=224, mean=None, std=None)
| 96 | return img |
| 97 | |
| 98 | def process_image(sample, mode, color_jitter, rotate, |
| 99 | crop_size=224, mean=None, std=None): |
| 100 | """ process_image """ |
| 101 | |
| 102 | mean = [0.485, 0.456, 0.406] if mean is None else mean |
| 103 | std = [0.229, 0.224, 0.225] if std is None else std |
| 104 | |
| 105 | |
| 106 | img_path = sample[0] |
| 107 | img = cv2.imread(img_path) |
| 108 | img = cv2.resize(img, (crop_size, crop_size)) |
| 109 | |
| 110 | img = img[:, :, ::-1].astype('float32').transpose((2, 0, 1)) / 255 |
| 111 | img_mean = np.array(mean).reshape((3, 1, 1)) |
| 112 | img_std = np.array(std).reshape((3, 1, 1)) |
| 113 | img -= img_mean |
| 114 | img /= img_std |
| 115 | |
| 116 | return (img, ) |
| 117 | |
| 118 | def image_mapper(**kwargs): |
| 119 | """ image_mapper """ |