如何在 TensorFlow 对象检测 API 中保留 class 特定权重的同时重置 classes

How to reset classes while retaining class specific weights in TensorFlow Object Detection API

我目前正在使用 TensorFlow Object Detection API and am attempting to fine tune a pre-trained Faster-RCNN from the model zoo. Currently, if I choose a different number of classes to the number used in the original network, it will simply not initialise the weights and biases from the SecondStageBoxPredictor/ClassPredictor as this now has different dimensions from the original ClassPredictor. However, as all of the classes I would like to train the network on are classes the original network has been trained to identify, I would like to retain the weights and biases associated with the classes I want to use in SecondStageBoxPredictor/ClassPredictor and prune all the others, rather than simply initialising these values from scratch (similar to the behaviour of this function)。

这可能吗?如果可以,我将如何在 Estimator 中修改该层的结构?

n.b。 This question 问了类似的事情,他们的回答是忽略网络输出中不相关的 类 - 然而,在这种情况下,我正在尝试微调网络,我假设存在这些冗余 类 会使训练/评估过程复杂化吗?

如果你想要训练网络的所有 类 都是网络已经训练识别的那些,你可以简单地使用网络来检测,不是吗?

但是,如果你有额外的 类 并且你想进行迁移学习,你可以通过设置从检查点恢复尽可能多的变量:

fine_tune_checkpoint_type: 'detection'
load_all_detection_checkpoint_vars: True

在管道配置文件的字段 train_config 中。

最后,通过看计算图可以看出,SecondStageBoxPredictor/ClassPredictor/weights的形状依赖于输出的个数类。

注意在tensorflow中你只能在变量级别恢复,如果两个变量的形状不同,一个不能用一个来初始化另一个。因此,在您的情况下,保留 weights 变量的某些值的想法是不可行的。