furkanu / deeplearning.ai-pytorch

PyTorch Implementations of Coursera's Deep Learning(deeplearning.ai) Specialization
MIT License
147 stars 32 forks source link

Bug In "Art Generation with Neural Style Transfer" #2

Open niunuinui opened 4 years ago

niunuinui commented 4 years ago

Hi, I learn a lot from your code! Thanks a lot!

I think there is a bug in the save_image function of Art Generation with Neural Style Transfer code. Since .detach() share the same memory, we should clone the input image first or the change will apply to the original image and mess the training.

Bellow is the fixed code for save_image

def save_image(path, imageO):
    # Un-normalize the image so that it looks good
    image=imageO.clone().detach()
    image = image.cpu().numpy().transpose(0, 2, 3, 1)
    image += CONFIG.MEANS
    image = np.clip(image[0], 0, 255).astype('uint8')
r1ght0us commented 3 years ago

Hi, I learn a lot from your code! Thanks a lot!

I think there is a bug in the save_image function of Art Generation with Neural Style Transfer code. Since .detach() share the same memory, we should clone the input image first or the change will apply to the original image and mess the training.

Bellow is the fixed code for save_image

def save_image(path, imageO):
    # Un-normalize the image so that it looks good
    image=imageO.clone().detach()
    image = image.cpu().numpy().transpose(0, 2, 3, 1)
    image += CONFIG.MEANS
    image = np.clip(image[0], 0, 255).astype('uint8')

牛逼好兄弟,终于找到原因了!!!!