EfficientNet-PyTorch icon indicating copy to clipboard operation
EfficientNet-PyTorch copied to clipboard

It doesn't work when I set the in_channels=1 using from_name to define an efficientnet-b5.

Open shijun18 opened this issue 3 years ago • 0 comments

Code:

net = EfficientNet.from_name(model_name='efficientnet-b5',in_channels=1)

Error: TypeError: from_name() got an unexpected keyword argument 'in_channels'

By reading the source code, I found that from_name() contains the in_channels argument, as follows:

@classmethod
def from_name(cls, model_name, in_channels=3, **override_params):
    """Create an efficientnet model according to name.
    Args:
        model_name (str): Name for efficientnet.
        in_channels (int): Input data's channel number.
        override_params (other key word params):
            Params to override model's global_params.
            Optional key:
                'width_coefficient', 'depth_coefficient',
                'image_size', 'dropout_rate',
                'num_classes', 'batch_norm_momentum',
                'batch_norm_epsilon', 'drop_connect_rate',
                'depth_divisor', 'min_depth'
    Returns:
        An efficientnet model.
    """
    cls._check_model_name_is_valid(model_name)
    blocks_args, global_params = get_model_params(model_name, override_params)
    model = cls(blocks_args, global_params)
    model._change_in_channels(in_channels)
    return model

But it still raises the above error, I don't know the reason. I look forward to any useful reply.

shijun18 avatar Mar 16 '22 10:03 shijun18