Closed oke-aditya closed 4 years ago
Following the excellent lightning architecture, something to keep in mind is to avoid hiding pytorch details from the user, this is the single most loved feature from lightning
That being said, I do think we can do something similar from what you're suggesting, and it would be great if it worked both for FasterRCNN
and MaskRCNN
Currently the creating of the backbone model happens inside the constructor:
def __init__(self, ...):
self.m = fasterrcnn_resnet50_fpn(pretrained=self.pretrained, **kwargs)
What do you think about injecting this via an argument? Something like:
def __init__(self, backbone=None):
self.m = backbone or fasterrcnn_resnet50_fpn(pretrained=self.pretrained)
I like this way because we avoid the problem of unsunsupported Backbone
and we don't hide pytorch from the user
We also need to be careful with model_splits
, this is used for differential learning rates, independent of the method we decide to go with this, we somehow have to make sure model_splits
is behaving as expected
Slight issue in the backbone definition. To create the backbone we need to pass it to faster RCNN class of Pytorch then it gets created similar to ResNet 50 rpn.
Also when we add the backbone the major problem is ResNet 50 rpn by default given is trained on COCO while backbones when we add are trained on ImageNet
To create the backbone we need to pass it to faster RCNN class
Yeah, that's okay, we can easily refactor the code to work like that
About the pre-trained weights, we might in some cases even want to start from scratch, so it's fine to start from ImageNet, as long as is clear to the user what is happening.
What is important here, is that I think that if the user wants to change the backbone we want to make sure he has to write pytorch code, no magic should happen inside our classes
What we should do is write helper function/classes so that he has to write less boilerplate, that's all
That sounds good. It would make it easier.
Feel free to open a PR implementing these changes, I'll give you freedom to design the API as you like, just follow the principles discussed here 🎉
Ow, we don't have a contributing guide yet, but we take inspiration from lightning contribution guide you can find here
For code formatting, use black, all defaults, simple
That's it, happy coding 😉
Can you provide a high level example (with code just like I did before) on how that would look like?
I'm thinking a bit on backbones. To create a seperate folder for backbones and keep inheriting those models. Few reasons why.
On a high level view we would have structure of folders like this
mantishrimp
-> backbones (containing backbones like mobilenet etc)
-> layers (layers that aren't in torch e.g. dilated convolution, this is used by by both backbones and models)
-> models (which contain folder for each e.g. ssd, fasterrcnn, detr)
This will allow the user to specify the backbone and subsequent flexible model is built.
def __init__(self, backbone=None):
self.m = backbone or fasterrcnn_resnet50_fpn(pretrained=self.pretrained)
will change a bit to
def __init__(self, user_backbone=None):
ft_backbone = user_backbone.features
ft_bakbone.out_channels = (as in model)
self.m = FasterRCNN(backbone = ft_backbone)
This FasterRCNN or so models should come from folder of models.
So, it will simplify as follows, backbones, layers, and models are in Pytorch (no other alternative) and then our trainer, engines, and user access will be with Pytorch Ligthning
It will allow us to create a seperate file like I did, model.py for initializing model with user defined backbones and hyperparameters, which would be passed to engine.py which is controlled by pytorch ligthning.
End user would need lesser pain in manually defining.
here instead of taking self.feature extractor from torchvision it would come from our custom backbones in model folder, they would be written with Pytorch lightining
Extend this to object detection.
Closing this for now, as it would be more clear in #61
🚀 Feature
It would be hard for end-user to understand where to implement custom architectures and backbones. They require same training code as there is a change in backbone which is feature extractor.
Provide different backbone configurations that can be extended easily, something like a model file https://github.com/oke-aditya/pytorch_fasterrcnn/blob/dev/src/model.py
Then use pytorch lightning trainer which is same for all these models. Something that simplifies https://github.com/oke-aditya/pytorch_fasterrcnn/blob/dev/src/engine.py
using torch lightning.