To extract the gradient of a trained network with respect to the input in MATLAB, you can use the dlgradient function. Here's an example:
main.m576 chars26 lines
In this example, we load the pretrained AlexNet network and an example image, preprocess the image, and then perform a forward pass through the network to get the output. We then use the dlgradient function to calculate the gradient of the output with respect to the input, which is the image. We convert the gradient back to an array using the extractdata function, and then display it using the imshow function.
Note that the dlgradient function requires the deep learning toolbox in MATLAB.
gistlibby LogSnag