# .cuda() call transfers the densor from the CPU to the GPU if that is the case.
# Non-blocking argument lets the caller bypas synchronization when necessary
withtorch.no_grad():# Causes operations to have no gradients
output=self.forward(X)
_,idx=torch.max(output,1)
# We retrieve the tensor held by idx (.data), and map it to a cpu as an ndarray
idx=idx.data.cpu().numpy()
prediction=np.squeeze(idx)
delX,output,idx
returnprediction
defreset_parameters(self):
"""Parameter Initialization
This function (re)initializes the parameters of the defined network.
This function is a wrapper for the reset_parameters() function defined for each module.
More information can be found here: https://discuss.pytorch.org/t/what-is-the-default-initialization-of-a-conv2d-layer-and-linear-layer/16055 + https://discuss.pytorch.org/t/how-to-reset-model-weights-to-effectively-implement-crossvalidation/53859
An alternative (re)initialization method is described here: https://discuss.pytorch.org/t/how-to-reset-variables-values-in-nn-modules/32639
# .cuda() call transfers the densor from the CPU to the GPU if that is the case.
# Non-blocking argument lets the caller bypas synchronization when necessary
withtorch.no_grad():# Causes operations to have no gradients
output=self.forward(X)
_,idx=torch.max(output,1)
# We retrieve the tensor held by idx (.data), and map it to a cpu as an ndarray
idx=idx.data.cpu().numpy()
prediction=np.squeeze(idx)
delX,output,idx
returnprediction
defreset_parameters(self):
"""Parameter Initialization
This function (re)initializes the parameters of the defined network.
This function is a wrapper for the reset_parameters() function defined for each module.
More information can be found here: https://discuss.pytorch.org/t/what-is-the-default-initialization-of-a-conv2d-layer-and-linear-layer/16055 + https://discuss.pytorch.org/t/how-to-reset-model-weights-to-effectively-implement-crossvalidation/53859
An alternative (re)initialization method is described here: https://discuss.pytorch.org/t/how-to-reset-variables-values-in-nn-modules/32639