model = models.resnet18(pretrained=False) model.fc = torch.nn.Linear(512, ???)
时间: 2023-06-24 08:07:35 浏览: 195
关于PyTorch源码解读之torchvision.models
5星 · 资源好评率100%
The number of output units in the `torch.nn.Linear` layer depends on the number of classes in your classification task. For example, if you have 10 classes, you would set the number of output units to 10:
```
model.fc = torch.nn.Linear(512, 10)
```
If you have a binary classification task, you would set the number of output units to 1:
```
model.fc = torch.nn.Linear(512, 1)
```
If you're doing regression instead of classification, you would set the number of output units to 1 (assuming you're predicting a single continuous value):
```
model.fc = torch.nn.Linear(512, 1)
```
阅读全文