我就废话不多说了。直接 上代码吧!
def var_filter(var_list, last_layers = [0]): filter_keywords = ['fine_tune', 'layer_11', 'layer_10', 'layer_9', 'layer_8'] for var in var_list: for layer in last_layers: kw = filter_keywords[layer] if kw in var.name: yield var break else: continue def set_optimizer(self, n): train_vars = list(var_filter(tf.trainable_variables(), last_layers = range(n))) self.train_op = self.optim.minimize(self.loss, global_step=self.global_step, var_list = train_vars)
以上这篇tensorflow 固定部分参数训练,只训练部分参数的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持IIS7站长之家。