Besides some minor issues, your code looks fine.
Could you post the complete model definition so that I could take a look at it?
The minor problems are:

Call the model directly for your forward pass, i.e. use model(input) instead of model.forward(input) as the former call will properly register all hooks etc.

Variables are deprecated sind PyTorch 0.4.0. Just remove the Variable wrapping in your code.
Your comparison will always return True, since before holds a reference to weight’s data. Use unet.conv4.weight.data.clone() to deep copy the data.