【问题标题】:Migrate tf.contrib.layers.apply_regularization to Tensorflow 2.0将 tf.contrib.layers.apply_regularization 迁移到 TensorFlow 2.0
【发布时间】:2021-06-24 11:09:12
【问题描述】:

我想将 github 项目 https://github.com/liupei101/TFDeepSurv von TF1 迁移到 TF2,因为其他依赖项。 使用 tf_upgrade_v2 脚本转换的问题文件是https://github.com/liupei101/TFDeepSurv/blob/master/tfdeepsurv/dsl.py。 此行无法转换

reg_item =tf.contrib.layers.l1_l2_regularize(self.config["L1_reg"], self.config["L2_reg"])
loss_reg = tf.contrib.layers.apply_regularization(reg_item, tf.compat.v1.get_collection("var_weight"))

对于第一个,我认为正确的迁移是:

reg_item = tf.keras.regularizers.L1L2(l1=self.config["L1_reg"], l2=self.config["L2_reg"])

哪一个是这两条线的正确替代品?

【问题讨论】:

    标签: python tensorflow tf.keras


    【解决方案1】:

    在 Tensorflow 2.x 中,keras 训练循环帮助我们自动应用正则化、激活损失,无需调用显式 apply_regularization 方法。欲了解更多信息,请查看Tensorflow doc 在 TF v2.x 中使用tf.keras.regularizers.L1L2

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-08
      • 2015-02-16
      • 2010-09-23
      • 2017-01-09
      • 1970-01-01
      相关资源
      最近更新 更多