Methods for synthesizing images in Pytorch

Main Q: I want to know are there any methods to synthesize images to illicit the maximum value of CNN last layer (if we dense the last layer to 1, it only gives a number) in Pytorch?

What did I try? I wrote a TensorFlow version, I used the random images to input to a pre-trained CNN, and then gave one value. I did the SGD to change the random image to an image that will elicit the largest CNN final layer value (maybe not the largest, maybe to a certain value I defined say 10). And the results will give me a certain image that looks good, but when I wrote the same Pytorch implement version, it generated an image that will have lots of noise around. I wonder are there any methods or codes to generate images that will elicit the largest response (or certain response) of pre-trained CNN. Thank you all!