迁移tf.contrib.layers.apply_正则化到Tensorflow 2.0

2024-09-30 01:19:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我想将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"])

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


Tags: httpsselfgithubcomconfigl1layerstf

热门问题