比较经过迁移学习训练的多个不同 Yolov8s 模型的权重和偏差。

huangapple go评论56阅读模式
英文:

Comparing the Weights and Biases of several different Yolov8s models trained through transfer learning

问题

I have 3 different yolov8s models which I would like to assess:

  1. 使用普通的model.train()命令训练的Yolov8s模型。

  2. 使用冻结骨干部分训练的Yolo8vs模型。

  3. 所有层都被冻结后训练的Yolov8s模型。

我正在使用回调函数来冻结权重,如下所示:

def freeze_layer(trainer):
    model = trainer.model
    num_freeze = 10
    print(f"冻结{num_freeze}层")
    freeze = [f'model.{x}.' for x in range(num_freeze)]  # 要冻结的层
    for k, v in model.named_parameters():
        v.requires_grad = True  # 训练所有层
        if any(x in k for x in freeze):
            print(f'冻结{k}')
            v.requires_grad = False
    print(f"{num_freeze}层已冻结")

if __name__ == "__main__":
    model = YOLO(yolov8s.pt)
    model.add_callback("on_train_start", freeze_layer)
    model.train(
        data="coco128.yaml",
        epochs=300,
        imgsz=640
        )

我想要能够评估这3个神经网络之间的权重和偏差的差异。我想要查看迁移学习后哪些神经元已经"死亡",并评估所有三个神经网络之间的主要差异。有没有标准解决方案可以用来获得这种对神经网络的洞察?

我已经比较了yolo提供的标准训练指标,如MAP和损失,一切都符合预期。冻结的层数越多,性能就越差。当我冻结整个网络时,性能比其他两个实例要差得多。

当涉及到比较相同的网络架构但训练方式不同时,我几乎不知道从哪里开始。

非常感谢任何帮助。

英文:

I have 3 different yolov8s models which I would like to assess:

  1. Yolov8s trained with the normal model.train() command

  2. Yolo8vs model trained with a frozen backbone

  3. Yolov8s model trained with all layers frozen

I am using a callback function to freeze the weights, see below:

def freeze_layer(trainer):
    model = trainer.model
    num_freeze = 10
    print(f"Freezing {num_freeze} layers")
    freeze = [f'model.{x}.' for x in range(num_freeze)]  # layers to freeze
    for k, v in model.named_parameters():
        v.requires_grad = True  # train all layers
        if any(x in k for x in freeze):
            print(f'freezing {k}')
            v.requires_grad = False
    print(f"{num_freeze} layers are freezed.")

if __name__ == "__main__":
    model = YOLO(yolov8s.pt)
    model.add_callback("on_train_start", freeze_layer)
    model.train(
        data="coco128.yaml",
        epochs=300,
        imgsz=640
        )

I want to be able to assess the differences in the weights and biases between these 3 neural networks. I want to see which neurons are dead after transfer learning and assess the major differences between all three neural networks. Are there any standard solutions to use to gain this kind of insight into a neural network?

I have compared the standard training metrics that yolo provides like MAP and Loss and everything is as expected. The more layers you freeze the worse performce gets. And when I freeze the whole network the performance is much worse than the other 2 instances.

I barely know where to begin when it comes to comparing the same network architetchure but just trained differently.

Any help is much appreciated.

答案1

得分: 1

YOLO架构相当复杂(取决于您使用的大小),比较/匹配特定层中间表示的权重可能相当不直观。一种方法是在每个层上可视化中间激活。您还可以绘制每个层的权重分布。或计算每个模型权重之间的范数。

英文:

YOLO architecture is quite complicated (depending on which size you're using), and it can be quite counter-intuitive to compare / match the weights of intermediate representations in a specific layer. One approach would be to Visualize the intermediate activations at each layer. You can also plot the distribution of the weights for each layer. Or calculating the norm between the weights of each model.

huangapple
  • 本文由 发表于 2023年5月10日 23:13:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76220101.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定