我想将github项目https://github.com/liupei101/TFDeepSurvvon TF1迁移到TF2,因为存在其他依赖项。 使用tf_upgrade_v2 skcript转换的问题文件是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"])
哪一条是这两条线的正确替代品
在Tensorflow 2.x中,keras训练循环帮助我们应用正则化,自动激活丢失,无需调用显式
apply_regularization
方法。有关更多信息,请参阅Tensorflow doc 在tfv2.x中使用tf.keras.regularizers.L1L2
相关问题 更多 >
编程相关推荐