In an image classification project, I have tried various CNN architectures with fastai v1. I’d like to share my note here, as it may take some time to figure out what cut and split parameters to use and where to get the pretained models.
This notebook shows the structures of some archs and how to use them with fastai v1. It includes ResNet, ResNeXt, SENet, Densenet, Inception V4, WRN, Xception, VGG, etc. Some pretrained models are from torchvision, some are from Cadene. The notebook also shows what the model is like after cutting and splitting into layer groups.
I hope it helps!
Although the fastai v1’s flexible API allows people to customize their own models, it may be more convenient to use if the library has default cut and split parameters for various models. Actually v0.7 has more models included and I saw people asking about it in some other posts.
I’d be happy to submit a PR if we want to include some of the models into the library.
Hi @sgugger ,
I’m glad you like it! I have sent a PR to include all models in torchvision, except for inception_v3. The torchvision inception_v3 code has used functions like F.max_pool2d in between the model’s modules in forward, but the cut model code in fastai only take its children, these functions won’t be included, so it doesn’t work for now. It’s not hard to fix if we write our own code for Inception, but Cadene already has working ones for Inception.
Some other useful models in the notebook, such as ResNeXt, SENet, etc, are from Cadene pretrained models, I’m not sure we want to add a dependency just for this so I didn’t include them. Let me know whether we’d like to add these models or skip them for now. In v0.7, we had our own implementations for some of them (e.g. SENet).
@PPPW I don’t think that pretrainedmodels has to be a dependency. You could add the code to fastai and throw an error message when a model from pretrainedmodels is used, but the dependency ist not installed.
Hi @sotte, model_meta uses the model function as key, do you mean inside the model function we add a check to see whether the user has pretrainedmodel installed or not? Good idea, thanks!
@others, I’m glad the notebook helps, someone asked me to add more examples, I have added a few such as NASNet, PNASNet, etc.
Look good, it should work. We can create a file cadene_pretrainedmodels.py in the models folder and put all those models there, to prevent the learner.py file getting too long.
There’s another repo (pytorchcv) which provides a much more comprehensive list of models. Moreover, the models’ implementation is much easier to be used with fastai, comparing with Cadene. I have provided some simple examples here.
Hi @rdass, in the second last line of your first block, you have from utils import *. The utils.py is in this folder, it’s just a simple py file with some functions, it’s not part of any library. Do you have that file in the directory of your notebook?
Hi @PPPW sorry for the really late reply. I just revisited this problem and it’s been resolved now. How would you go about permanently adding the utils.py file to my path? Would you recommend following this link?