PyTorch計算dataset的mean和std

一般在進行CNN模型訓練的時候,通常都會對dataset的圖片進行normalize,而經常會看到一組數字:

mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]

這組數字是針對ImageNet所設計的,一般來說照常使用此組數字即可

這篇討論串的留言提到
Just note that you need to use your own mean and std if your dataset is not similar to ImageNet. In the 3-channel case you have mentioned, you are using mean and std from ImageNet which works for most of the datasets that are similar but if you are using datasets such as medical image processing, then you need to obtain proper mean and std regarding your own dataset.
如果我們自己的資料集與ImageNet差異很大,或許就可以考慮針對自己的Dataset來計算mean和std,作為normalize的參數。

另一個討論串當中,有人比較

(a)ImageNet的mean和std
(b)自己資料集中的mean和std

最終準確度的差別,發現使用自己dataset中所計算的mean和std來作為Normalize參數,準確度比較高,細節可參考此篇

Machine Learning | Deep Learning | https://linktr.ee/yanwei