如何解决此错误? AttributeError:“ builtin_function_or_method”对象没有属性“ data”

时间:2019-10-11 22:38:02

标签: python machine-learning pytorch

我正在尝试使用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()

0 个答案:

没有答案