I make such changes for 4 channels but it doesn’t work, most likely I’m wrong somewhere but I can’t understand where
import torch
import torch.nn as nn
import torchvision
from torchvision.models import resnet50
from torchvision.models.detection import FasterRCNN
from torchvision.models.detection.rpn import AnchorGenerator


def get_resnet50(n_classes, n_channels=4):
    model = resnet50(pretrained=False)
    for p in model.parameters():
        p.requires_grad = False
    inft = model.fc.in_features
    model.fc = nn.Linear(in_features=inft, out_features=n_classes)
    model.avgpool = nn.AdaptiveAvgPool2d(1)
    model.conv1 = nn.Conv2d(n_channels, 64, kernel_size=7, stride=2, padding=3, bias=False)

    return model


def get_faster_rcnn(n_classes, n_channels=4):
    resnet = get_resnet50(n_classes, n_channels)
    resnet_features = list(resnet.children())[:-1]
    backbone = nn.Sequential(*resnet_features)

    # ResNet50 output channels is 2048
    backbone.out_channels = 2048

    anchor_generator = AnchorGenerator(sizes=((32, 64, 128, 256, 512),), aspect_ratios=((0.5, 1.0, 2.0),))

    roi_pooler = torchvision.ops.MultiScaleRoIAlign(featmap_names=[0], output_size=7, sampling_ratio=2)

    model = FasterRCNN(backbone=backbone, num_classes=n_classes, rpn_anchor_generator=anchor_generator,
                       box_roi_pool=roi_pooler)

    return model