about preprocessing
See original GitHub issueHi, I am wondering that what “sm.get_preprocessing” actually do.
For example, assume we are using
BACKBONE = 'resnet34'
preprocess_input = sm.get_preprocessing(BACKBONE)
I trace the code back to line 385 (somewhere near it) in
“/my_virtual_environment/lib/python3.6/site-packages/classification_models/models/resnet.py”.
And it occurs to me that the preprocess function appears as :
def preprocess_input(x, **kwargs):
return x
.
It means that the preprocess_input = sm.get_preprocessing(BACKBONE)
did actually nothing.
I am not so sure if it is the truth. But here is my question. If it actually works like I say aboved, it is really necessary to give detailed introduction of the preprocessing functions which were used when pretraing the networks on imagenet. And it is important that we know the scaling of the inputs ([0-255] or [-1,1] or others).
Hope you can help me. Your work is excellent.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:5 (1 by maintainers)
It’s because Resnet (the original backbone that was trained on ImageNet) didn’t have any pre-processing/scaling. So in this case,
preprocess_input(backbone = 'resnet34')
, really doesn’t do anything. But for other backbones the pre-processing/scaling might be between [0, 255], [-1, 1], [0, 1], or some subtraction of the mean pixel value.It is important to pre-process the images if you’re using imagenet weights with the backbone of your choice. For example, If you use VGG w/ imagenet weights, it is expecting some range of values of the images it is given. If you all the sudden provide it with a different range of values, it’s not going to do well at all. I believe that if you’re training some backbone from scratch, then you can use whatever pre-processing methods you want. But again, if using imagenet weights you should do what the original author of the code/architecture did to get the best results.
Use
get_preprocessing
andpreprosessing_fn
for your data is your responsibility (see examples)