StacyYang / MXNet-Gluon-Style-Transfer

Neural Style and MSG-Net
http://computervisionrutgers.github.io/MSG-Net/
MIT License
145 stars 31 forks source link

RGB and BGR Mistake with optim in main.py? #6

Open Paul0M opened 6 years ago

Paul0M commented 6 years ago

Line 145-148 in main.py I think content_image is obtained in RBG fomat. However, utils.subtract_imagenet_mean_preprocess_batch take img in BGR fomat. Is that right?

#main.py
    content_image = utils.tensor_load_rgbimage(args.content_image,ctx, size=args.content_size, keep_asp=True)
    content_image = utils.subtract_imagenet_mean_preprocess_batch(content_image)
    style_image = utils.tensor_load_rgbimage(args.style_image, ctx, size=args.style_size)
    style_image = utils.subtract_imagenet_mean_preprocess_batch(style_image)

#utils.py
def subtract_imagenet_mean_preprocess_batch(batch):
    """Subtract ImageNet mean pixel-wise from a BGR image."""
    batch = F.swapaxes(batch,0, 1)
    (r, g, b) = F.split(batch, num_outputs=3, axis=0)

And I think a better understanding way to transform RGB to BGR or vise versa is to use: F.swapaxes(batch,0, 1) is not that obvious.

rgb_img = bgr_img[::-1,,] # C*H*W
bgr_img = rgb_img[::-1,,] # C*H*W