简体   繁体   中英

No dimension mismatch for Keras sequential model?

I created a sequential neural network with Keras that has an input of 4 and an output of 8. I realize what I did was incorrect but I'm not sure as to why the code does not throw an error.

print(X.shape)    # Prints (64, 4)
print(y.shape)    # Prints (64, 64, 8)

self.model.fit(X, y, batch_size=MINIBATCH_SIZE, verbose=0, shuffle=False)

So why does Keras accept an array of array of arrays? Shouldn't it only accept an array of arrays?

EDIT: This is how my model was created

model = Sequential()
model.add(tf.keras.layers.InputLayer(input_shape=(4,)))
model.add(Dense(64))
model.add(Dense(Env.ACTION_SPACE, activation='linear'))             # Env.ACTION_SPACE = 8
model.compile(loss="mse", optimizer='adam', metrics=['accuracy'])

They are mostly mariz computation then the dimension is expand or reduce by the function but the last layer, you can falttern, softmax or conclude into shape you want. You can see from traing batch or prediction that it return set of output where you seelct batch number more than 1 or prediction print to see the output result where they are multipl of answers stacks you search from np.max or softwax or attached networks.

I saw your remarks that from this example

next_act = mainQ_outputs.evaluate(x=input_image, batch_size=16, max_queue_size=10, workers=16 )

Or you also can do

predictions = model.predict(obs, batch_size=32)

Sample output:

### ( 1 ): Q-Networks
model = models.Sequential()         
    for layer in mainQ_outputs: 
     model.add(layer)
     model.add(tf.keras.layers.Flatten() )
     model.add(tf.keras.layers.Dense(6, activation=tf.nn.softmax))

### ( 2 ): predictions[0] - predictions[31]
action = np.argmax(predictions[0])  
action = actions_name[action]

...

目标运动预测(一)

目标运动预测(二)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM