【发布时间】:2021-07-08 20:55:42
【问题描述】:
我需要在预处理中给图像添加一层归一化。
它需要是模型的附加层(而不是 python 中的单独代码),因为我后来将 keras 模型转换为 mlmodel。
我的意思是标准化:
在 python 中(来自here):
parser.add_argument('--std', type=list, default=[0.229, 0.224, 0.225],
help='the std used to normalize your images')
parser.add_argument('--mean', type=list, default=[0.485, 0.456, 0.406],
help='the mean used to normalize your images')
normalize = transforms.Normalize(std=args.std, mean=args.mean)
transformation = transforms.Compose([transforms.ToTensor()])
man_normalize = transformation(man_resize)
在安卓中:
@Override
| protected void addPixelValue(int pixelValue) {
| imgData.putFloat((((pixelValue >> 16) & 0xFF)/255f - IMAGE_MEAN[0]) / IMAGE_STD[0]);
| imgData.putFloat((((pixelValue >> 8) & 0xFF)/255f - IMAGE_MEAN[1]) / IMAGE_STD[1]);
| imgData.putFloat(((pixelValue & 0xFF)/255f - IMAGE_MEAN[2]) / IMAGE_STD[2]);
| }
我考虑过 Lambda 层,但我不确定如何有效地按通道进行。
谢谢
【问题讨论】:
标签: keras normalization image-preprocessing coremltools