【问题标题】:Tensorflow 2.x: How to assign convolution weights manually using numpyTensorflow 2.x:如何使用 numpy 手动分配卷积权重
【发布时间】:2020-06-15 16:34:04
【问题描述】:

在 tensorflow 1.x 中,这可以使用 graph and a session 来完成,这非常乏味。

在 tensorflow 2.x 中是否有更简单的方法可以手动将预训练的权重分配给特定的卷积?

【问题讨论】:

    标签: tensorflow tensorflow2.0 onnx


    【解决方案1】:

    如果您在 Tensorflow 2.x 中使用 Keras,每个层都有一个名为 set_weights 的方法,您可以使用该方法替换权重或从 Numpy 数组分配新权重。

    例如,假设您正在学习蒸馏知识。然后您可以通过以下方式将老师的权重分配给学生:

    conv.set_weights(teacher.convx.get_weights())

    其中conv 是学生的特定层,convx 是老师的同源层。

    您可以查看文档以获取更多详细信息:

    Documentation - set_weights()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-13
      • 2021-06-12
      • 2021-09-10
      • 1970-01-01
      • 2016-05-27
      • 1970-01-01
      • 1970-01-01
      • 2021-04-09
      相关资源
      最近更新 更多