鉴于我在相同的数据上训练了几个不同的模型,并且我训练的所有神经网络都具有相同的体系结构,所以我想知道是否可以恢复这些模型,对其权重求平均并使用平均值初始化权重。
这是图形外观的一个示例。基本上,我需要的是平均要加载的重量。
import tensorflow as tf
import numpy as np
#init model1 weights
weights = {
'w1': tf.Variable(),
'w2': tf.Variable()
}
# init model1 biases
biases = {
'b1': tf.Variable(),
'b2': tf.Variable()
}
#init model2 weights
weights2 = {
'w1': tf.Variable(),
'w2': tf.Variable()
}
# init model2 biases
biases2 = {
'b1': tf.Variable(),
'b2': tf.Variable(),
}
# this the average I want to create
w = {
'w1': tf.Variable(
tf.add(weights["w1"], weights2["w1"])/2
),
'w2': tf.Variable(
tf.add(weights["w2"], weights2["w2"])/2
),
'w3': tf.Variable(
tf.add(weights["w3"], …Run Code Online (Sandbox Code Playgroud)