当我运行此代码时,出现此错误:
AttributeError:“str”对象没有属性“reshape”
进程已完成,退出代码为 1
def shift_image(image, dx, dy):
image = image.reshape((28, 28))
请您在使用它的地方添加一个代码块。
另外,我相信您在调用此函数时传递了错误的参数,我认为您错误地传递了一个字符串作为参数
尝试:
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)
我迟到了。对于任何正在寻找更大背景的人:上面的代码片段是以下 Medium 文章的一部分:https://medium.com/towards-data-science/improving-accuracy-on-mnist-using-data-augmentation -b5c38eb5a903