gpt4 book ai didi

python - InvalidArgumentError : input depth must be evenly divisible by filter depth: 4 vs 3

转载 作者:行者123 更新时间:2023-12-03 07:37:58 27 4
gpt4 key购买 nike

我是初学者。我尝试使用Tensorflow进行图像分类,并收到以下错误。我在网上发现了类似的问题,但我听不懂。错误是什么意思?我应该怎么做?请给我一些建议。我使用100个文件(png/15pix,15pix)作为示例图片。 Tensorflow Ver.2.0.0/Python Ver.3.8.1/Jupyter笔记本。

sample image

    num_epochs = 30
steps_per_epoch = round(num_train)//BATCH_SIZE
val_steps = 20
history = model.fit(train_data.repeat(),
epochs=num_epochs,
steps_per_epoch = steps_per_epoch,
validation_data=val_data.repeat(),
validation_steps=val_steps)

InvalidArgumentError: input depth must be evenly divisible by filter depth: 4 vs 3 [[node sequential_2/mobilenetv2_1.00_96/Conv1/Conv2D (defined at C:\Users\XXXXX\Anaconda3\lib\site-packages\tensorflow_core\python\framework\ops.py:1751) ]] [Op:__inference_distributed_function_42611] Function call stack: distributed_function

最佳答案

如果您的模型如下所示:

model = tf.keras.Sequential([
tf.keras.layers.Conv2D(16, (3, 3), activation = 'relu', input_shape = (150, 150, 3)),
tf.keras.layers.MaxPooling2D(2, 2),
tf.keras.layers.Conv2D(32, (3, 3), activation = 'relu'),
tf.keras.layers.MaxPooling2D(2, 2),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(512, activation = 'relu'),
tf.keras.layers.Dense(10, activation = 'softmax')
])
input_shape的值(在第一卷积层)从 (150, 150, 3)更改为 (150, 150, 4)
仅将元组中的最后一项(此处为3)替换为4。
那应该使它工作。

关于python - InvalidArgumentError : input depth must be evenly divisible by filter depth: 4 vs 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60174964/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com