Error making prediction with pruned neural network

Figured it out. I saw on this post (RuntimeError: mat2 must be a matrix, got 1-D tensor) that someone had a similar error, and the solution suggested they needed to change the shape of their output tensor. I modified my code where I was copying the weights/biases from the first network, as follows:

model3 = NMR_Model2()
model3.lin1.weight.data = model2.lin1.weight.data
model3.lin1.bias.data = model2.lin1.bias.data
model3.lin2.weight.data = model2.lin2.weight.data[:1]
model3.lin2.bias.data = model2.lin2.bias.data[:1]

1 Like