srijarkoroy / artistyle Goto Github PK
View Code? Open in Web Editor NEWAn implementation of the paper "A Neural Algorithm of Artistic Style"
License: MIT License
An implementation of the paper "A Neural Algorithm of Artistic Style"
License: MIT License
when I run
python3 test.py
This error appeared
RuntimeError Traceback (most recent call last)
Cell In[4], line 2
1 content_img, style_img = ('./results/input/content.jpg', './results/input/style.jpg')
----> 2 result = nst_res.run_nst(content_img, style_img)
File ~/autodl-tmp/ArtiStyle/nst/neural_style_transfer.py:219, in NST.run_nst(self, content_path, style_path)
215 content_img, style_img, input_img = self.image_loader(content_path, style_path)
217 ''' building the style transfer model '''
--> 219 model, style_loss, content_loss = self.style_model_and_losses(self.cnn, self.cnn_normalization_mean, self.cnn_normalization_std, content_img, style_img)
221 ''' using LBFGS optimizer to run gradient descent on the input image in order to minimise the content and the style losses '''
223 optimizer = optim.LBFGS([input_img.requires_grad_()])
File ~/autodl-tmp/ArtiStyle/nst/neural_style_transfer.py:191, in NST.style_model_and_losses(self, cnn, cnn_normalization_mean, cnn_normalization_std, content_img, style_img)
189 ''' adding style loss '''
190 if name in style_layers:
--> 191 target_feature = model(style_img).detach()
192 styl_loss = StyleLoss(target_feature)
193 model.add_module('style_loss_{}'.format(i), styl_loss)
File ~/miniconda3/lib/python3.8/site-packages/torch/nn/modules/module.py:889, in Module._call_impl(self, *input, **kwargs)
887 result = self._slow_forward(*input, **kwargs)
888 else:
--> 889 result = self.forward(*input, **kwargs)
890 for hook in itertools.chain(
891 _global_forward_hooks.values(),
892 self._forward_hooks.values()):
893 hook_result = hook(self, input, result)
File ~/miniconda3/lib/python3.8/site-packages/torch/nn/modules/container.py:119, in Sequential.forward(self, input)
117 def forward(self, input):
118 for module in self:
--> 119 input = module(input)
120 return input
File ~/miniconda3/lib/python3.8/site-packages/torch/nn/modules/module.py:889, in Module._call_impl(self, *input, **kwargs)
887 result = self._slow_forward(*input, **kwargs)
888 else:
--> 889 result = self.forward(*input, **kwargs)
890 for hook in itertools.chain(
891 _global_forward_hooks.values(),
892 self._forward_hooks.values()):
893 hook_result = hook(self, input, result)
File ~/miniconda3/lib/python3.8/site-packages/torch/nn/modules/conv.py:399, in Conv2d.forward(self, input)
398 def forward(self, input: Tensor) -> Tensor:
--> 399 return self._conv_forward(input, self.weight, self.bias)
File ~/miniconda3/lib/python3.8/site-packages/torch/nn/modules/conv.py:395, in Conv2d._conv_forward(self, input, weight, bias)
391 if self.padding_mode != 'zeros':
392 return F.conv2d(F.pad(input, self._reversed_padding_repeated_twice, mode=self.padding_mode),
393 weight, bias, self.stride,
394 _pair(0), self.dilation, self.groups)
--> 395 return F.conv2d(input, weight, bias, self.stride,
396 self.padding, self.dilation, self.groups)
RuntimeError: cuDNN error: CUDNN_STATUS_NOT_INITIALIZED
content_img, style_img = ('content.jpg', 'style.jpg')
result = nst_res.run_nst(content_img, style_img)
RuntimeError Traceback (most recent call last)
/tmp/ipykernel_3711029/1610500945.py in
1 content_img, style_img = ('content.jpg', 'style.jpg')
----> 2 result = nst_res.run_nst(content_img, style_img)
~/desktop/ai_safe/ArtiStyle/nst/neural_style_transfer.py in run_nst(self, content_path, style_path)
217 ''' building the style transfer model '''
218
--> 219 model, style_loss, content_loss = self.style_model_and_losses(self.cnn, self.cnn_normalization_mean, self.cnn_normalization_std, content_img, style_img)
220
221 ''' using LBFGS optimizer to run gradient descent on the input image in order to minimise the content and the style losses '''
~/desktop/ai_safe/ArtiStyle/nst/neural_style_transfer.py in style_model_and_losses(self, cnn, cnn_normalization_mean, cnn_normalization_std, content_img, style_img)
189 ''' adding style loss '''
190 for name in style_layers:
--> 191 target_feature = model(style_img).detach()
192 styl_loss = StyleLoss(target_feature)
193 model.add_module('style_loss_{}'.format(i), styl_loss)
~/anaconda3/envs/pt1.8/lib/python3.8/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
887 result = self._slow_forward(*input, **kwargs)
888 else:
--> 889 result = self.forward(*input, **kwargs)
890 for hook in itertools.chain(
891 _global_forward_hooks.values(),
~/anaconda3/envs/pt1.8/lib/python3.8/site-packages/torch/nn/modules/container.py in forward(self, input)
117 def forward(self, input):
118 for module in self:
--> 119 input = module(input)
120 return input
121
~/anaconda3/envs/pt1.8/lib/python3.8/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
887 result = self._slow_forward(*input, **kwargs)
888 else:
--> 889 result = self.forward(*input, **kwargs)
890 for hook in itertools.chain(
891 _global_forward_hooks.values(),
~/desktop/ai_safe/ArtiStyle/nst/loss_norm.py in forward(self, input)
36 '''
37
---> 38 self.loss = F.mse_loss(input, self.target)
39 return input
40
~/anaconda3/envs/pt1.8/lib/python3.8/site-packages/torch/nn/functional.py in mse_loss(input, target, size_average, reduce, reduction)
2926 reduction = _Reduction.legacy_get_string(size_average, reduce)
2927
-> 2928 expanded_input, expanded_target = torch.broadcast_tensors(input, target)
2929 return torch._C._nn.mse_loss(expanded_input, expanded_target, _Reduction.get_enum(reduction))
2930
~/anaconda3/envs/pt1.8/lib/python3.8/site-packages/torch/functional.py in broadcast_tensors(*tensors)
72 if has_torch_function(tensors):
73 return handle_torch_function(broadcast_tensors, tensors, *tensors)
---> 74 return _VF.broadcast_tensors(tensors) # type: ignore
75
76
RuntimeError: The size of tensor a (550) must match the size of tensor b (275) at non-singleton dimension 3
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.