Python Forum

Full Version: Sequential Decision Making
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am generating a sequential decision making model. I am using tensorflow.keras.sequantial.
But any time I train my model, I have the following error

Error:
assert_input_compatibility str(tuple(shape))) ValueError: Input 0 of layer sequential is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: (None, 30)
Here is the part of the code creating the problem,

import gym
import numpy as np
import gym_anytrading
from gym_anytrading.datasets import FOREX_EURUSD_1H_ASK, STOCKS_GOOGL
import tensorflow as tf
from tensorflow.keras import layers
import pandas as pd
import matplotlib.pyplot as plt


class QuantitativeTrading():
    def __init__(self, market):
        self.market = str(market)


    def Environment(self):
    # Set up the environment
        env = gym.make(self.market)
        return env

if __name__ == '__main__':

    # Call market
    market = 'stocks-v0'

    # Call the trader
    trader = QuantitativeTrading(market)

    # Define the model
    env = trader.Environment()
    units = env.action_space.n
    model = tf.keras.Sequential()
    model.add(tf.keras.layers.LSTM(128, input_shape=(2, env.observation_space.shape[0])))
    model.add(tf.keras.layers.Dense(units, activation='softmax'))
    model.compile(optimizer='adam', loss="mean_squared_error")

    # [layers.Dense(2, activation="relu", name="layer1"),
    #     layers.Dense(3, activation="relu", name="layer2")]

    # Train the model
    def ModelTraining(num_epochs, env, model):

        for epoch in range(num_epochs):
            state = env.reset()
            action = model.predict(state.transpose())
            next_state, reward, done, _ = env.step(action)
            model.fit(state, reward, epochs=num_epochs, verbose=0)
            state = next_state

        return action, state


    num_epochs = 100
    action, state = ModelTraining(num_epochs, env, model)
Is that all that was included in the error traceback?
Yes, this part creates the error. If you compile it on your interpreter, you must see the same error.