dearleiii / PIRM-2018-SISR-Challenge

Super Resolution
https://www.pirm2018.org/PIRM-SR.html
2 stars 0 forks source link

Can't call numpy() on Variable #6

Closed dearleiii closed 6 years ago

dearleiii commented 6 years ago

File "scatter_plots.py", line 135, in trainNet plt.scatter(scores.numpy(), outputs.numpy(), c='g') RuntimeError: Can't call numpy() on Variable that requires grad. Use var.detach().numpy() instead. leichen@gpu-compute7>

dearleiii commented 6 years ago

Variable, numpy bridge

Variable's can’t be transformed to numpy, because they’re wrappers around tensors that save the operation history, and numpy doesn’t have such objects. You can retrieve a tensor held by the Variable, using the .data attribute. Then, this should work: var.data.numpy().

random_tensor_ex = random_variable_ex.data