【发布时间】:2019-11-01 10:36:35
【问题描述】:
我是神经网络的新手。我有一个 3d 关节位置 (6400*23*3) 和四元数方向 (6400*23*4) 的数据集,我想预测所有 22 个关节和 3 个运动平面 (6400*22*3) 的关节角度。我试图制作一个模型,但它不会运行,因为输入数据与输出形状不匹配,我不知道如何更改它。
我的代码
import scipy
import numpy as np
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv1D, MaxPooling2D, Dense, Flatten
from tensorflow.keras.utils import to_categorical
Jaload = scipy.io.loadmat('JointAnglesXsens11MovementsIforlængelse.mat')
Orload = scipy.io.loadmat('OrientationXsens11MovementsIforlængelse.mat')
Or = np.array((Orload['OR'][:,:]), dtype='float')
Ja = np.array((Jaload['JA'][:,:]), dtype='float')
Jalabel = np.array(Ja)
a = 0.6108652382
Jalabel[Jalabel<a] = 0
Jalabel[Jalabel>a] = 1
Ja3d = np.array(Jalabel.reshape(6814,22,3)) # der er 22 ledvinkler
Or3d = np.array(Or.reshape(6814,23,4)) # der er 23 segmenter
X_train = np.array(Or3d)
Y_train = np.array(Ja3d)
model = Sequential([
Dense(64, activation='relu', input_shape=(23,4)),
Dense(64, activation='relu'),
Dense(3, activation='softmax'),])
model.summary()
model.compile(loss='categorical_crossentropy', optimizer='adam') # works
model.fit(
X_train,
to_categorical(Y_train),
epochs=3,)
运行 model.fit 会返回:
ValueError: 形状为 (6814, 22, 3, 2) 的目标数组被传递为形状 (None, 3) 的输出,同时用作损失 categorical_crossentropy。这种损失期望目标具有与输出相同的形状。
【问题讨论】:
标签: python numpy tensorflow keras neural-network