python - 如何解决此错误?AttributeError:“builtin_function_or_method”对象没有属性“数据”
问题描述
我正在尝试使用本文中的代码来实现神经风格迁移。当我运行 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()
解决方案
推荐阅读
- javascript - 尝试访问数组内部的数组时感到困惑。
- python - Python中的函数调用错误
- java - 从工具栏隐藏元素,在单个活动上实现,在各种片段上
- mapping - (重新)在 qutebrowser 中定义命令
- javascript - React SSR、NextJS 与 Chrome 无头预渲染
- python-3.x - 如何使用启动/初始化命令注入 pythonWin?(python3改了)
- winforms - 如何使用 Override a Class 阻止 Winforms 面板滚动?
- angular - 使用〜(波浪号)导入的 SCSS 文件在 Angular 6 中不起作用
- r - 如果在 dataframe$text 中找到多个单词,则搜索多个单词,希望保留它们
- swift - 添加手势识别器 uivew 导航栏 swift 不起作用