keras 2颜色通道的图像?

wmomyfyw  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(185)

我有一个超过12,000张图像的数据集,在对其中一些图像进行视觉评估时,它们的图像形状看起来正常,正如我所期望的那样,具有3个颜色通道RGB

['10371.jpg']
 image shape: (375, 500, 3)
 array([[[128, 129, 134],
        [129, 130, 134],
        [130, 131, 135],
        ...,
        [209, 214, 218],
        [209, 214, 218],
        [209, 214, 218]],

       [[125, 126, 130],
        [126, 127, 131],
        [127, 128, 132],
        ...,
        [209, 214, 218],
        [209, 214, 218],
        [209, 214, 218]],

       [[123, 124, 128],
        [123, 124, 128],
        [124, 125, 129],
        ...,
        [206, 213, 219],
        [206, 213, 219],
        [206, 213, 219]],

       ...,

       [[196, 196, 196],
        [196, 196, 196],
        [196, 196, 196],
        ...,
        [ 81,  76,  70],
        [ 87,  82,  76],
        [ 88,  83,  77]],

       [[196, 196, 196],
        [196, 196, 196],
        [196, 196, 196],
        ...,
        [ 95,  90,  84],
        [106, 101,  95],
        [106, 101,  95]],

       [[196, 196, 196],
        [196, 196, 196],
        [196, 196, 196],
        ...,
        [ 99,  94,  88],
        [111, 106, 100],
        [109, 104,  98]]], dtype=uint8)

字符串
但是当我试图运行一个模型时,我得到了错误:

import tensorflow as tf
from tensorflow.keras.layers import Conv2D, MaxPool2D, Dense, Flatten, Rescaling, Activation
from tensorflow.keras import Sequential
from tensorflow.keras.optimizers import Adam

def baseline_model():
  model = Sequential([
  Rescaling(1.0/255.0),                    
  Conv2D(filters=10,
         kernel_size=3,
         strides=1,
         input_shape=(224, 224, 3)),
  Activation(activation='relu'),
  MaxPool2D(),
  Conv2D(filters=10,
         kernel_size=3,
         strides=1),
  Activation(activation='relu'),
  MaxPool2D(),
  Conv2D(filters=10,
         kernel_size=3,
         strides=1),
  Activation(activation='relu'),
  MaxPool2D(),
  Flatten(),
  Dense(1, activation='sigmoid')                                         
  ])
  return model

baseline_model_0 = baseline_model()

baseline_model_0.compile(loss='binary_crossentropy',
                         optimizer=Adam(learning_rate=0.001),
                         metrics=['accuracy'])

history_0_baseline = baseline_model_0.fit(train_data,
                                          epochs=5,
                                          validation_data=test_data,
                                          steps_per_epoch=len(train_data),
                                          validation_steps=int(0.15 * len(test_data)),  # Evaluate on 15% of the testing data
                                          callbacks=create_tensorboard_callback(dir_name=tensorboard_dir_name,
                                                                                experiment_name='baseline_model_0'))

InvalidArgumentError: Graph execution error:

Number of channels inherent in the image must be 1, 3 or 4, was 2
     [[{{node decode_image/DecodeImage}}]]
     [[IteratorGetNext]] [Op:__inference_train_function_1885]


我如何才能找到呈现问题的图像/图像?

xriantvc

xriantvc1#

我知道我回答这个问题已经晚了,但我想你的数据集可能有不是jpeg的文件。我运行了一个脚本,以确保我的数据集只有jpeg/jpg格式的文件,因为其他格式可能会导致我的模型出现错误。我遇到了这个问题,昨天解决了这个问题。

相关问题