A have two models with the same architecture but trained with a different losses.
These models give different results. I want to «balance» between these models combining their weights lineary:
combined_weights = k * weights_a + (1 - k) * weights_b
The problem I working on allows for this approach. It's argued that this approach is more efficient than interpolating the outputs.
I also have a PyTorch implementation of this approach:
k = 0.3
model_a = torch.load(...)
model_b = torch.load(...)
combined_model = OrderedDict()
for i, v_a in model_a.items():
v_b = model_b[i]
combined_model[i] = k * v_a + (1 - k) * v_b
torch.save(combined_model, ...)
How can I do the same in TensorFlow? I've tried to do it combining weights of my models:
k = 0.3
weights_a = model_a.get_weights()
weights_b = model_b.get_weights()
combined_weights = k * weights_a + (1 - k) * weights_b
combined_model.set_weights(combined_weights)
But got an error at k * weights_a:
can't multiply sequence by non-int of type 'float'
So, how can I do it?