python - 奇怪的张量流问题:排名下降
问题描述
我不确定这里发生了什么。我一直在阅读有关此错误的信息,并将其解释为与图像重塑有关的错误。由于某种原因,最后 3 个等级丢失了。数据集的每个图像的宽度和高度都未标准化。处理后的图像应该是一个正方形,这是 scikit 的调整大小功能无法填充空间的地方。相反,它将基于最大维度的按比例缩放的集合放入 train_X 中。这是流程的一个想法。
def read_img(file):
img = skimage.io.imread(img_folder + file)
img = skimage.transform.resize(img, (img_height, img_width), mode='reflect')
return img[:,:,:img_channels] #the last 3 ranks meant to fill in the traceback
read_img 函数输入到 train_X。
train_X = np.stack(train_['file'].apply(read_img))
这是追溯。
Traceback (most recent call last):
File "A:\anoth\...\newmodel.py", line 196, in <module>
generator, train_X, val_X, test_X, train_y, val_y, test_y =
prepare2train(train_, val_, test_, 'Category')
File "A:\anoth\...\newmodel.py", line 192, in prepare2train
generator.fit(train_X,augment=True, rounds=50, seed=43)
File "A:\anoth\Anaconda\lib\site-packages\keras_preprocessing\image.py", line 1347, in fit
'Got array with shape: ' + str(x.shape))
ValueError: Input to `.fit()` should have rank 4. Got array with shape: (6848,)
我是否正确理解了这个问题?如果是这样,为什么 train_X 会下降最后 3 个等级?我该如何解决这个问题?
解决方案
img = skimage.transform.resize(img, (img_height, img_width), mode='reflect') 由于某种原因没有适当地调整图像大小。在 python 之外调整图像大小并且不使用这行代码解决了排名下降的问题。
推荐阅读
- docker - 用于网站的单个 Nginx Docker 与多个 Nginx Docker
- azure-managed-app - 如何使用新的包版本更新现有的 Azure 托管应用程序?
- javascript - 如何使用 vanilla JavaScript 在列表中获取 span 的值?
- java - 将文件保存在谷歌驱动器上
- android - 从 expo 客户端构建应用程序 apk 时获取“keystore.keyAlias”不允许为空错误
- python - 确定一个列表中的元素是否小于另一个列表中的元素
- javascript - Is there a way to copy validation from one input to another with JavaScript?
- .htaccess - 如何对主域强制执行 https 连接,同时对子域强制执行 http?
- javascript - 我该如何处理这个错误:调用未定义的方法 App\Models\client::findOrFails() 并使用 Js formData 对象发送表单数据?
- css - 如何始终在有焦点的 Material-UI Button 组件上应用 focusVisible 样式?