logits和标签必须具有相同的形状((None,4,1,2)vs(None,2))

时间:2020-10-10 23:40:09

标签: tensorflow keras

def train(data,model=False):

    X= np.array([i[0] for i in data]).reshape(-1,len(data[0][0]),1)
    y=np.array([i[1] for i in data])

    if model==False:
        network = models.Sequential()

        network.add(layers.Dense(32,input_shape=[None, len(X[0]), 1], activation='relu'))
#        network.add(layers.Flatten())
        network.add(layers.Dropout(0.8))

        network.add(layers.Dense(64,activation='relu'))
        network.add(layers.Dropout(0.8))

        network.add(layers.Dense(128,activation='relu'))
        network.add(layers.Dropout(0.8))

        network.add(layers.Dense(64,activation='relu'))
        network.add(layers.Dropout(0.8))

        network.add(layers.Dense(32,activation='relu'))
        network.add(layers.Dropout(0.8))

        network.add(layers.Dense(2,activation='sigmoid'))
        network.compile(optimizer='adam',
                    loss='sparse_categorical_crossentropy',
                    metrics=['accuracy'])

    network.fit(X, y, epochs=5, batch_size=128)

    return network

以上是我在开放AI体育馆环境中使用的keras神经网络。我得到了数据并像这样存储

[ [obs , reward , done , info ] , [ 0 , 1 ] ] 

[ 0 , 1 ] for 0 and [ 1 , 0 ] for 1. 

y 变量是 [0,1] ,而 x 变量是** [obs,奖励,完成,信息] **

将这些数据拟合到我的神经网络的正确方法是什么?

0 个答案:

没有答案