我正在尝试使用this文章中的代码来实现神经样式转换。当我运行main.py时,在标题中提到第12行时出现错误。我很确定这与torch.randn(input.data.size())
有关,但是我不知道该怎么办。我仍然是机器学习的初学者,并且我仍在学习有关Python的知识。任何帮助将不胜感激。
from StyleCNN import *
from utils import *
# CUDA Configurations
dtype = torch.cuda.FloatTensor if torch.cuda.is_available() else torch.FloatTensor
# Content and style
style = image_loader("style.jpg").type(dtype)
content = image_loader("content.jpg").type(dtype)
pastiche = image_loader("content.jpg").type(dtype)
pastiche.data = torch.randn(input.data.size()).type(dtype)
num_epochs = 31
def main():
style_cnn = StyleCNN(style, content, pastiche)
for i in range(num_epochs):
pastiche = style_cnn.train()
if i % 10 == 0:
print("Iteration: %d" % (i))
path = "outputs/%d.png" % (i)
pastiche.data.clamp_(0, 1)
save_image(pastiche, path)
main()