tucan9389 / PoseEstimation-CoreML

The example project of inferencing Pose Estimation using Core ML
https://github.com/motlabs/awesome-ml-demos-with-ios
MIT License
680 stars 136 forks source link

How to add normalization to the image in preprocess? #39

Closed yonatanbitton closed 3 years ago

yonatanbitton commented 3 years ago

Hello

I need to add normalization to the image in the preprocess

This is how it's being done in python (From 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)

This is how it's being done in Android:

@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]);
  | }

How can I do similar thing in your Swift application?

Thanks

tucan9389 commented 3 years ago

@yonatanbitton

Here is my sample conversion script for normalization. Please check it out. https://github.com/tucan9389/SemanticSegmentation-CoreML/issues/12#issue-829545201

yonatanbitton commented 3 years ago

Great, this is what I searched for. Closing the issue. Thanks.