Hi, I am using following function to flatten the network:
#############################################################################
# Flattening the NET
#############################################################################
def flattenNetwork(net):
flatNet = []
shapes = []
for param in net.parameters():
#if its WEIGHTS
curr_shape = param.cpu().data.numpy().shape
shapes.append(curr_shape)
if len(curr_shape) == 2:
param = param.cpu().data.numpy().reshape(curr_shape[0]*curr_shape[1])
flatNet.append(param)
elif len(curr_shape) == 4:
param = param.cpu().data.numpy().reshape(curr_shape[0]*curr_shape[1]*curr_shape[2]*curr_shape[3])
flatNet.append(param)
else:
param = param.cpu().data.numpy().reshape(curr_shape[0])
flatNet.append(param)
finalNet = []
for obj in flatNet:
for x in obj:
finalNet.append(x)
finalNet = np.array(finalNet)
return finalNet,shapes
I manipulate the weights given by finalNet and I don’t change the shape of the network. How can I get back the original network with manipulated weights? Later I want to see the effect of weight manipulations on the accuracy. Please help. Thank you.