Can I unpack variable after backward()?

input is a Variable

>>> output = model(input)
>>> loss = loss_cal(input, ouput)
>>> loss.backward()

Save output as image after backward

>>> save_image(

Can I unpack the variable output to save as image to disk after backward() ?
If no, what is the work around for this?

Yes, you can save output as an image to your HDD.
Do you have trouble in doing so or encounter any errors?

NO I don’t have problem in saving the output once I unpack the Variable to numpy.

I was wondering if unpacking Variable after backward() after each epoch/iteration will hurt gradient propagation in the network.

There shouldn’t be a problem, if you properly .detach the Tensor or get the underlying .data.
Your example looks fine to me.

1 Like