如何解决在 CNN 中重塑图像时出错Googel Colab
我有一个数字识别的 CNN 项目。我正在 colab 中尝试它。我有一个 784 像素的一维向量,在将它传递给 CNN 之前,我必须将其重塑为 (28x28x1)。但我无法重塑它。我有一个错误。 这是我的代码-
x_train = x_train.reshape(-1,28,1)
x_test = x_test.reshape(-1,1)
test_df=test_df.reshape(-1,1)
我得到了错误,它是 -
AttributeError Traceback (most recent call last)
<ipython-input-31-fc5920daac40> in <module>()
9 # reshape(examples,height,width,channels)
10 x_train = x_train.reshape(-1,1)
---> 11 x_test = x_test.reshape(-1,1)
12 test_df=test_df.reshape(-1,1)
/usr/local/lib/python3.6/dist-packages/pandas/core/generic.py in __getattr__(self,name)
5139 if self._info_axis._can_hold_identifiers_and_holds_name(name):
5140 return self[name]
-> 5141 return object.__getattribute__(self,name)
5142
5143 def __setattr__(self,name: str,value) -> None:
AttributeError: 'DataFrame' object has no attribute 'reshape'
我阅读了 this question 并且当我使用此代码时-
x_train = x_train.values.reshape(-1,1)
x_test = x_test.values.reshape(-1,1)
test_df=test_df.values.reshape(-1,1)
我也有错误,它是 -
AttributeError Traceback (most recent call last)
<ipython-input-32-93a2a0b4627a> in <module>()
8 ##first param in reshape is number of examples. We can pass -1 here as we want numpy to figure that out by itself ###################
9 # reshape(examples,channels)
---> 10 x_train = x_train.values.reshape(-1,1)
11 x_test = x_test.values.reshape(-1,1)
12 test_df=test_df.values.reshape(-1,1)
AttributeError: 'numpy.ndarray' object has no attribute 'values'
有时它会出错,有时它会运行。我不知道问题出在哪里,我该怎么办?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。