PPPW / deep-learning-random-explore

194 stars 34 forks source link

EfficientNet implementation in pretrainedmodels #7

Closed saurabh502 closed 5 years ago

saurabh502 commented 5 years ago

Hi, Can we implement new EfficientNet in this package? Details: [https://ai.googleblog.com/2019/05/efficientnet-improving-accuracy-and.html]

I tried implementing it with Fastai, but getting error. Below is the code: `!pip install efficientnet_pytorch from efficientnet_pytorch import EfficientNet

def efficientnet(model_name='efficientnet-b0',**kwargs): return EfficientNet.from_pretrained(model_name).to(device)

getting error here

learn = cnn_learner(data_large, efficientnet, metrics=accuracy, model_dir=MODEL_PATH)`

Error: `--------------------------------------------------------------------------- AttributeError Traceback (most recent call last)

in () ----> 1 learn = cnn_learner(data_large, efficientnet, metrics=accuracy, model_dir=MODEL_PATH) /opt/conda/lib/python3.6/site-packages/fastai/vision/learner.py in cnn_learner(data, base_arch, cut, pretrained, lin_ftrs, ps, custom_head, split_on, bn_final, init, concat_pool, **kwargs) 95 meta = cnn_config(base_arch) 96 model = create_cnn_model(base_arch, data.c, cut, pretrained, lin_ftrs, ps=ps, custom_head=custom_head, ---> 97 split_on=split_on, bn_final=bn_final, concat_pool=concat_pool) 98 learn = Learner(data, model, **kwargs) 99 learn.split(split_on or meta['split']) /opt/conda/lib/python3.6/site-packages/fastai/vision/learner.py in create_cnn_model(base_arch, nc, cut, pretrained, lin_ftrs, ps, custom_head, split_on, bn_final, concat_pool) 81 split_on:Optional[SplitFuncOrIdxList]=None, bn_final:bool=False, concat_pool:bool=True): 82 "Create custom convnet architecture" ---> 83 body = create_body(base_arch, pretrained, cut) 84 if custom_head is None: 85 nf = num_features_model(nn.Sequential(*body.children())) * (2 if concat_pool else 1) /opt/conda/lib/python3.6/site-packages/fastai/vision/learner.py in create_body(arch, pretrained, cut) 53 def create_body(arch:Callable, pretrained:bool=True, cut:Optional[Union[int, Callable]]=None): 54 "Cut off the body of a typically pretrained `model` at `cut` (int) or cut the model as specified by `cut(model)` (function)." ---> 55 model = arch(pretrained) 56 cut = ifnone(cut, cnn_config(arch)['cut']) 57 if cut is None: in efficientnet(model_name, **kwargs) 1 def efficientnet(model_name='efficientnet-b0',**kwargs): ----> 2 return EfficientNet.from_pretrained(model_name).to(device) /opt/conda/lib/python3.6/site-packages/efficientnet_pytorch/model.py in from_pretrained(cls, model_name) 185 @classmethod 186 def from_pretrained(cls, model_name): --> 187 model = EfficientNet.from_name(model_name) 188 load_pretrained_weights(model, model_name) 189 return model /opt/conda/lib/python3.6/site-packages/efficientnet_pytorch/model.py in from_name(cls, model_name, override_params) 179 @classmethod 180 def from_name(cls, model_name, override_params=None): --> 181 cls._check_model_name_is_valid(model_name) 182 blocks_args, global_params = get_model_params(model_name, override_params) 183 return EfficientNet(blocks_args, global_params) /opt/conda/lib/python3.6/site-packages/efficientnet_pytorch/model.py in _check_model_name_is_valid(cls, model_name, also_need_pretrained_weights) 201 num_models = 4 if also_need_pretrained_weights else 8 202 valid_models = ['efficientnet_b'+str(i) for i in range(num_models)] --> 203 if model_name.replace('-','_') not in valid_models: 204 raise ValueError('model_name should be one of: ' + ', '.join(valid_models)) AttributeError: 'bool' object has no attribute 'replace'`
PPPW commented 5 years ago

Hi @saurabh502, I have added a sections for EfficientNet, maybe you can test it out?

saurabh502 commented 5 years ago

Hi @PPPW , I checked it , it is working for me, thank you for your help!

PPPW commented 5 years ago

Hi @saurabh502, Sounds good! Thanks for testing, I'm glad it helps!