最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jupyter notebook - Input 0 of layer "conv2d" is incompatible with the layer: expected min_ndim=4, found ndim=2

programmeradmin1浏览0评论

I'm making a CNN and I don't know the full ins and outs of coding. When i try to add the layers, it constantly gives me a "NotImplmentedError" and a "ValueError" that says ValueError: Input 0 of layer "conv2d" is incompatible with the layer: expected min_ndim=4, found ndim=2. Full shape received: (None, 4)

single_feature_normalizer = tf.keras.layers.Normalization(axis=None)
feature = tf.random.normal((314, 1))
single_feature_normalizer.adapt(feature)

single_feature_model = tf.keras.models.Sequential([
    tf.keras.layers.Input(shape=(1,)),
    single_feature_normalizer,
    tf.keras.layers.Conv2D(1)
])

model.add(Conv2D(16, (3,3), 1, activation='relu', input_shape=(None,256,256,3))) 
model.add(MaxPooling2D())
model.add(Conv2D(32, (3,3), 1, activation='relu', input_shape=(None,256,256,3)))
model.add(MaxPooling2D())
model.add(Conv2D(16, (3,3), 1, activation='relu'))
model.add(MaxPooling2D())
model.add(Flatten())
model.add(Dense(256, activation='relu'))
model.add(Dense(1, activation='sigmoid'))

My min_ndim is 4, I checked so I'm unsure what's wrong.

I tried adding these lines:

single_feature_normalizer = tf.keras.layers.Normalization(axis=None)
feature = tf.random.normal((314, 1))
single_feature_normalizer.adapt(feature)

single_feature_model = tf.keras.models.Sequential([
    tf.keras.layers.Input(shape=(1,)),
    single_feature_normalizer,
    tf.keras.layers.Conv2D(1)
])

`` but it didn't work, I also tried explicitly stating that the min_ndim was 4

I'm making a CNN and I don't know the full ins and outs of coding. When i try to add the layers, it constantly gives me a "NotImplmentedError" and a "ValueError" that says ValueError: Input 0 of layer "conv2d" is incompatible with the layer: expected min_ndim=4, found ndim=2. Full shape received: (None, 4)

single_feature_normalizer = tf.keras.layers.Normalization(axis=None)
feature = tf.random.normal((314, 1))
single_feature_normalizer.adapt(feature)

single_feature_model = tf.keras.models.Sequential([
    tf.keras.layers.Input(shape=(1,)),
    single_feature_normalizer,
    tf.keras.layers.Conv2D(1)
])

model.add(Conv2D(16, (3,3), 1, activation='relu', input_shape=(None,256,256,3))) 
model.add(MaxPooling2D())
model.add(Conv2D(32, (3,3), 1, activation='relu', input_shape=(None,256,256,3)))
model.add(MaxPooling2D())
model.add(Conv2D(16, (3,3), 1, activation='relu'))
model.add(MaxPooling2D())
model.add(Flatten())
model.add(Dense(256, activation='relu'))
model.add(Dense(1, activation='sigmoid'))

My min_ndim is 4, I checked so I'm unsure what's wrong.

I tried adding these lines:

single_feature_normalizer = tf.keras.layers.Normalization(axis=None)
feature = tf.random.normal((314, 1))
single_feature_normalizer.adapt(feature)

single_feature_model = tf.keras.models.Sequential([
    tf.keras.layers.Input(shape=(1,)),
    single_feature_normalizer,
    tf.keras.layers.Conv2D(1)
])

`` but it didn't work, I also tried explicitly stating that the min_ndim was 4

Share Improve this question asked Feb 7 at 0:02 EveEve 113 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I actually figured it out, I had inputed the images as RGB when they were actually greyscale. I fixed this and the code is working now.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论