AttributeError:“str”对象没有属性“reshape”

问题描述 投票:0回答:3

https://gist.github.com/akashp1712/446ffaa5d87e0110404c75f0b0cff157#filemnist_augmentation_random_forest-py

当我运行此代码时,出现此错误:

AttributeError:“str”对象没有属性“reshape”

进程已完成,退出代码为 1

def shift_image(image, dx, dy):
  image = image.reshape((28, 28))
python mnist
3个回答
0
投票

请您在使用它的地方添加一个代码块。

另外,我相信您在调用此函数时传递了错误的参数,我认为您错误地传递了一个字符串作为参数


0
投票

尝试:

for dx, dy in ((1,0), (-1,0), (0,1), (0,-1)):
         for image, label in zip(X_train.values, y_train):
                 X_train_augmented.append(shift_image(image, dx, dy))
                 y_train_augmented.append(label)

代替:

for dx, dy in ((1,0), (-1,0), (0,1), (0,-1)):
     for image, label in zip(X_train, y_train):
             X_train_augmented.append(shift_image(image, dx, dy))
             y_train_augmented.append(label)

0
投票

我迟到了。对于任何正在寻找更大背景的人:上面的代码片段是以下 Medium 文章的一部分:https://medium.com/towards-data-science/improving-accuracy-on-mnist-using-data-augmentation -b5c38eb5a903

© www.soinside.com 2019 - 2024. All rights reserved.