【问题标题】:Strange tensorflow issue: dropped ranks奇怪的张量流问题:排名下降
【发布时间】:2019-03-04 17:27:24
【问题描述】:

我不确定这里发生了什么。我一直在阅读有关此错误的信息,并将其解释为与图像重塑有关的错误。由于某种原因,最后 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 个等级?我该如何解决这个问题?

【问题讨论】:

  • 完成。添加了定义。
  • Train .. 拆分和平衡数据集。我之前使用过该代码,它适用于 jpgs。我开始怀疑它与读取文件的 img 数组的结构有关。该代码适用于 jpg,但 png 可能具有与读取文件 img 返回输出冲突的结构。

标签: python tensorflow machine-learning keras computer-vision


【解决方案1】:

img = skimage.transform.resize(img, (img_height, img_width), mode='reflect') 由于某种原因没有适当地调整图像大小。在 python 之外调整图像大小并且不使用这行代码解决了排名下降的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-01
    • 2022-09-28
    • 2015-12-08
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 2012-01-20
    • 2017-03-15
    相关资源
    最近更新 更多