程序问答   发布时间:2022-05-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了输入 0 与层 conv1d_3 不兼容:预期 ndim=3,发现 ndim=4大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决输入 0 与层 conv1d_3 不兼容:预期 ndim=3,发现 ndim=4?

开发过程中遇到输入 0 与层 conv1d_3 不兼容:预期 ndim=3,发现 ndim=4的问题如何解决?下面主要结合日常开发的经验,给出你关于输入 0 与层 conv1d_3 不兼容:预期 ndim=3,发现 ndim=4的解决方法建议,希望对你解决输入 0 与层 conv1d_3 不兼容:预期 ndim=3,发现 ndim=4有所启发或帮助;

我能解决这个问题吗?

Train_points.shape=(4096,3) Train_labels.shape=(4096,2)

你好。我手上有 3D 屋顶模型,我将这些模型转换为点云数据。每个模型有 2048 个点(用于 x、y 和 z 坐标)。即(2048.3)。我还创建了一个标签矩阵。 (2048.1)。当我使用 conv1d 时,它给了我这个错误。我不明白问题出在哪里?

import numpy as np
import pandas as pd
import keras
import seaborn as sns
import matplotlib.pyplot as plt
import trimesh
import warnings
warnings.filterwarnings('ignore') #filter warnings

mesh=trimesh.load("m1.stl")
mesh.show()
point1 = mesh.sample(2048) #modelin üstündeki nokta sayısı

mesh=trimesh.load("m2.stl")
mesh.show()
point2 = mesh.sample(2048) #modelin üstündeki nokta sayısı



Train_points=np.concatenate((point1,point2),axis=0)


fig = plt.figure(figsize=(15,15))
ax = fig.add_subplot(222,projection="3d")
ax.scatter(point1[:,0],point1[:,1],2])
ax.set_axis_off()
plt.show()


fig = plt.figure(figsize=(15,projection="3d")
ax.scatter(point2[:,point2[:,2])
ax.set_axis_off()
plt.show()


labels=np.zeros((4096),dtype='int') #4096=örnek sayısı
labels[0:2048]=0
labels[2048:4096]=1

from keraS.Utils.np_utils import to_categorical # convert to one-hot-enCoding
Train_labels= to_categorical(labels,2) #2=örnek sınıf sayısı
np.save('etiket_matrisi.npy',Train_labels)


from keras.models import Sequential
from keras.layers import input,Dense,Activation,Dropout,Flatten
from keras.layers import Conv1D,MaxPool1D

#input_shape = keras.input(shape=(4096,3))
input_shape=(2,2048,3)

model = Sequential()

model.add(Conv1D(filters=8,kernel_size=3,input_shape=input_shape,padding="same"))
model.add(Activation("relu"))

model.add(Conv1D(filters=8,padding="same"))
model.add(Activation("relu"))

model.add(MaxPool1D(pool_size=2))

model.add(Dense(16))
model.add(Activation("relu"))
model.add(Dropout(0.25))

model.add(Dense(8))
model.add(Activation("relu"))
model.add(Dropout(0.25))


#fully connected
model.add(Flatten())
model.add(Dense(4,activation="relu"))
model.add(Dropout(0.5))
model.add(Dense(2,activation="softmax")) #çıktı katmanı(2 modelim var)

#Compile Model
model.compile(optimizer="adam",loss="categorical_crossentropy",metrics=["accuracy"])
model.sumMary


#fit the model

history=model.fit(Train_points,Train_labels,epochs=500,batch_size=250,verbose=1)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的输入 0 与层 conv1d_3 不兼容:预期 ndim=3,发现 ndim=4全部内容,希望文章能够帮你解决输入 0 与层 conv1d_3 不兼容:预期 ndim=3,发现 ndim=4所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。