框回归器模块
最后一个任务是创建一个回归器模块,用于预测边界框坐标。您决定使用包含 2 个全连接层的模块,中间接一个 ReLU 激活,这与您之前定义的分类器类似。
vgg_model 和 input_dim 仍然可用,且已导入 torch 和 torchvision.models。
本练习是课程的一部分
使用 PyTorch 进行图像深度学习
练习说明
- 创建变量
num_coordinates,其值为需要预测的边界框坐标数量。 - 为第一层线性层定义合适的输入维度,并将输出维度设为
32。 - 在回归器的最后一层中定义合适的输出维度。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Define the number of coordinates
____
bb = nn.Sequential(
# Add input and output dimensions
nn.Linear(____, ____),
nn.ReLU(),
# Add the output for the last regression layer
nn.Linear(32, ____),
)