def _transform_fn(*data): """ This function is used as the parameter of dataset.transform(). The coords in mx_label is absolute coords. The processing procedure of image contains resize, augmentation, color_normalize, and to_tensor. The processing procedure of label just contains resize. :param data: (img, label), img: np.array, int, (h, w, c), label: absolute, np.array, int, (N, 5) :return: (mx_img, mx_label), mx_img: mx.nd.array, float, (c, h, w), mx_label: absolute, mx.nd.array, (N, 5) """ img, label = data img = img.astype('float32') / 255 # deepcopy label = label.astype('float32') aug_img, aug_label = myutils.data_augment(img, label, size=self.model_img_size, rb=0.0, rc=0.0, rh=0.0, rs=0.0, rflr=False, re=True, rcp=False) aug_img = mx.img.color_normalize(mx.nd.array(aug_img), mean=mx.nd.array(myutils.mean), std=mx.nd.array(myutils.std)) mx_img = myutils.to_tensor(aug_img) aug_label[:, 1:] = myutils.bbox_abs_to_rel(aug_label[:, 1:], mx_img.shape[-2:]) mx_label = mx.nd.array(aug_label) return mx_img, mx_label
def transform_fn(*data): """ This function is used as the parameter of dataset.transform(). The coords in mx_label is absolute coords. The processing procedure of image contains resize, augmentation, color_normalize, and to_tensor. The processing procedure of label just contains resize. :param data: (img, label), img: np.array, int, (h, w, c), label: absolute, np.array, int, (N, 5) :return: (mx_img, mx_label), mx_img: mx.nd.array, float, (c, h, w), mx_label: absolute, mx.nd.array, (N, 5) """ img, label = data img = img.astype('float32') # deepcopy label = label.astype('float32') aug_img, aug_label = myutils.data_augment(img, label, size=(300, 300)) norm_img = mx.img.color_normalize(mx.nd.array(aug_img), mean=mx.nd.array(myutils.mean), std=mx.nd.array(myutils.std)) mx_img = myutils.to_tensor(norm_img) mx_label = mx.nd.array(aug_label) return mx_img, mx_label