pytorch ,ncnn,tnn等的减均值,归一化处理等

1 pytorch  

一般通过 transform = transforms.Compose([ 
                transforms.ToTensor(),
                transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.50196078, 0.50196078, 0.50196078])])

toTensor()会进行归一化,Normalize的操作是(x-mean)/std

2 ncnn

const float mean_vals2[3] ={0.4,0.4,0.4};
const float std_vals2[3] = {4,4,4};
int.substract_mean_normalize(mean_vals2,std_vals2);

ncnn不会进行主动归一化,substract_mean_normalize的操作是(x-mean_vals2)*std_vals2

 

3 tnn 

TNN_NS::MatConvertParam input_cvt_param; 
input_cvt_param.bias  = {1,1,1,0};
input_cvt_param.scale = {0,0,0,0};

auto status = instance_->SetInputMat(image_mat, input_cvt_param);

tnn不会进行主动归一化,input_cvt_param的操作是 x*input_cvt_param.scale+input_cvt_param.bias

 

 

你可能感兴趣的:(pytorch ,ncnn,tnn等的减均值,归一化处理等)