classification_head
最后更新
luxonis_train.nodes.heads.classification_head一个带有池化、dropout 和线性层的分类头。类
ClassificationHead
输入::inputs(Tensor): [B, C, h, w]
输出::classification(Tensor): [B, nclasses] logits
参考
- 来源:本项目。
- 许可证:Apache-2.0(本项目)
注意事项
头部应用全局平均池化、dropout 和一个线性层。特征图可以有任意高度 h 和宽度 w。
forward 不检查模式,因此导出模式也提供 logits。dropout 仅在训练模式下起作用。变体:: 无。通过params配置节点。
示例
配置中
model.nodes 部分的节点条目:Yaml
1- name: ClassificationHead
2 inputs: [ResNet]兼容::- 附加索引:
-1,输入节点的最后一个输出 - 所需标签:
classification - 使用者:ClassificationModel
- 损失:
- 指标:
- 可视化工具:ClassificationVisualizer
- 导出解析器:
ClassificationParser
- 附加索引:
方法
init
Python
1def __init__(dropout_rate: float = 0.2, **kwargs):dropout_rate(float): 在训练模式下,dropout 层将池化特征设置为零的概率,范围为[0, 1]。**kwargs: BaseNode 的关键字参数。它们必须包含input_shapes或in_sizes,以及通过n_classes或dataset_metadata指定的类别计数。
forward
Python
1def forward(inputs: Tensor) -> Tensor:示例
Pycon
1>>> import torch
2>>> from torch import Size
3>>> from luxonis_train.nodes import ClassificationHead
4>>> head = ClassificationHead(
5... n_classes=4,
6... input_shapes=[{"features": [Size([2, 16, 7, 7])]}],
7... )
8>>> head(torch.zeros(2, 16, 7, 7)).shape
9torch.Size([2, 4])inputs(Tensor): 形状为[B, C, h, w]的特征图。
Tensor: 形状为[B, n_classes]的 logits。BaseNode.run 将它们放在"classification"键下。
get_custom_head_config
Python
1def get_custom_head_config(self) -> Params:"metadata" 字典中。基本实现返回一个空字典。返回Params: 附加的元数据键及其值。
属性
head
in_channels
RuntimeError: 当 in_sizes 找不到输入大小时。ValueError: 当 attach_index 不适合大小时。