M using the object detection model Faster RCNN Resnet 50 for some project. Now I want to add some additional layers to it.
How can I add additional layers to he existing pre-trained object detection model ?
import torch
import torch.nn as nn
from torchvision.ops.misc import FrozenBatchNorm2d
from torch.nn import Conv2d, Sequential, ReLU
class CustomNet(nn.Module):
def __init__(self):
super(CustomNet, self).__init__()
self.l1 = Sequential(
Conv2d(2048, 512, kernel_size=(1,1), bias = False, stride = (1,1)),
FrozenBatchNorm2d(512),
Conv2d(512, 512, kernel_size=(3,3), bias = False, stride = (1,1), padding=(1, 1)),
FrozenBatchNorm2d(512),
Conv2d(512, 2048, kernel_size=(1,1), bias = False, stride = (1,1)),
FrozenBatchNorm2d(2048),
ReLU(inplace=True) )
def forward(self, x):
x = self.l1(x)
return x
I want to add the above layer generated to the main model.
main_model = torchvision.models.detection.fasterrcnn_resnet50_fpn(pretrained=True)
How can I do that ?