zhanghang1989 / PyTorch-Multi-Style-Transfer

Neural Style and MSG-Net
http://hangzh.com/PyTorch-Style-Transfer/
MIT License
976 stars 207 forks source link

What is the default value of args.ngf #3

Closed akashdexati closed 6 years ago

akashdexati commented 6 years ago

@zhanghang1989 Thanks for sharing this nice project.

I changed the content of main.py to only have evaluate() method. def evaluate(content_image_name, style_image_name, output_image_name): `

content_image = utils.tensor_load_rgbimage(content_image_name, size=1024, keep_asp=True)
content_image = content_image.unsqueeze(0)
style = utils.tensor_load_rgbimage(style_image_name) # size=args.style_size
style = style.unsqueeze(0)
style = utils.preprocess_batch(style)

style_model = Net() # (ngf=args.ngf)
#style_model.load_state_dict(torch.load(args.model))
model_path = 'models/21styles.model'
style_model.load_state_dict(torch.load(model_path))

#if args.cuda: - start
style_model.cuda()
content_image = content_image.cuda()
style = style.cuda()
#if args.cuda - end

style_v = Variable(style, volatile=True)

content_image = Variable(utils.preprocess_batch(content_image), volatile=True)
style_model.setTarget(style_v)

output = style_model(content_image)
utils.tensor_save_bgrimage(output.data[0], output_image_name, 1) #args.cuda=1

`

Now I am getting below error While copying the parameter named model1.4.residual_layer.weight, whose dimensions in the model are torch.Size([256, 128, 1, 1]) and whose dimensions in the checkpoint are torch.Size([512, 128, 1, 1]), ... Traceback (most recent call last): File "newMain.py", line 297, in main() File "newMain.py", line 57, in main evaluate(content_image_name, style_image_name) File "newMain.py", line 251, in evaluate style_model.load_state_dict(torch.load(model_path)) File "/usr/local/lib/python2.7/dist-packages/torch/nn/modules/module.py", line 360, in load_state_dict ownstate[name].copy(param) RuntimeError: inconsistent tensor size, expected tensor [256 x 128 x 1 x 1] and src [512 x 128 x 1 x 1] to have the same number of elements, but got 32768 and 65536 elements respectively at /pytorch/torch/lib/TH/generic/THTensorCopy.c:86

Can you please suggest what I could be missing. Because I have done a very minor change and getting this error when everything is of your orginal code.

akashdexati commented 6 years ago

I fixed it by passing ngf=128 to Net()