If we import the ResNet model conv5_x will be layer4. We could do the following:
model = torchvision.models.resnet18(pretrained=True)
model.layer4 = nn.Identity()
model.fc = nn.Linear(256, num_classes)

And you could use on the model.fc = nn.Sequential(nn.Linear(), ...) if you wish to write several linear layers.