Feb-09-2023, 09:20 PM
I am generating a sequential decision making model. I am using
But any time I train my model, I have the following error
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,1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
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) |