pytorch-neural-style-transfer icon indicating copy to clipboard operation
pytorch-neural-style-transfer copied to clipboard

generated image could be better

Open lonewolfnsp opened this issue 3 years ago • 1 comments

I've run through the codes and was able to generate images by running the model. I realize that the images generated were sort of over exposed. I modified the codes to use pytorch's own save_image function, instead of opencv as was used in the codes, and found that I could achieve better results.

using a mean and std of: mean = np.asarray([ 0.485, 0.456, 0.406 ]) std = np.asarray([ 0.229, 0.224, 0.225 ]) I used this transforms for loading: transforms.ToTensor(), transforms.Normalize(mean, std, inplace=True), # normalize image based on mean and std of ImageNet dataset transforms.Lambda(lambda x: x.mul(255.))

and these transforms for saving: transforms.Lambda(lambda x: x.div(255.) ), transforms.Normalize((-1 * mean / std), (1.0 / std),inplace=True)

saving to file uses torch.utils.save_image function which accepts tensor.

couple of thing that puzzles me:

  1. running the training is very fast. 3000 epochs completed within 6+ mins. I could not figure out how you made it so fast. could you please advice me?
    1. loss backward doesn't require retain_graph=True. I independently wrote one myself and it gave error during training, about the graph being freed and calling basckward a second time. I only managed to train it by setting retain_graph to True. Could you please enlighten me why you could reuse the content and style outputs for the respective images, and only generates the outputs for the optimizing_umg and yet don't need to set retain_graph to True?

lonewolfnsp avatar Nov 21 '21 18:11 lonewolfnsp

Thank you for this information. I was able to add your comments to this piece of code. (Thanks for your Notebook).

sbetzin avatar Jul 01 '22 12:07 sbetzin