D3F4LT4ST / RL-trading

Forex trading strategy learning with reinforcement learning
7 stars 7 forks source link

AssertionError: spaces must have the same shape #3

Closed Chaosqing closed 6 months ago

Chaosqing commented 6 months ago

I have a problem, and I need your help.


forex_full_eurusd_rl_experiments.ipynb


Evaluation set results in[37] eurusd_env_eval = VecNormalize.load( f'{log_path}/ForexFullEURUSD-v1/vecnormalize.pkl', make_vec_env( ForexEnvBasic, env_kwargs=dict( target_prices_df=target_prices_eval, features_df=basic_features_eval, **deepcopy(BASE_ENV_KWARGS) ) ) )


AssertionError Traceback (most recent call last) Cell In[38], line 3 1 #print("Loaded VecNormalize observation space:", vec_normalize.observation_space) 2 #print("New environment observation space:", venv.observation_space) ----> 3 eurusd_env_eval = VecNormalize.load( 4 f'{log_path}/ForexFullEURUSD-v1/vecnormalize.pkl', 5 make_vec_env( 6 ForexEnvBasic, 7 env_kwargs=dict( 8 target_prices_df=target_prices_eval, 9 features_df=basic_features_eval, 10 **deepcopy(BASE_ENV_KWARGS) 11 ) 12 ) 13 )

File D:\anaconda3\Lib\site-packages\stable_baselines3\common\vec_env\vec_normalize.py:309, in VecNormalize.load(load_path, venv) 307 with open(load_path, "rb") as file_handler: 308 vec_normalize = pickle.load(file_handler) --> 309 vec_normalize.set_venv(venv) 310 return vec_normalize

File D:\anaconda3\Lib\site-packages\stable_baselines3\common\vec_env\vec_normalize.py:168, in VecNormalize.set_venv(self, venv) 165 self.class_attributes = dict(inspect.getmembers(self.class)) 167 # Check that the observation_space shape match --> 168 utils.check_shape_equal(self.observation_space, venv.observation_space) 169 self.returns = np.zeros(self.num_envs)

File D:\anaconda3\Lib\site-packages\stable_baselines3\common\utils.py:248, in check_shape_equal(space1, space2) 246 check_shape_equal(space1.spaces[key], space2.spaces[key]) 247 elif isinstance(space1, spaces.Box): --> 248 assert space1.shape == space2.shape, "spaces must have the same shape"

AssertionError: spaces must have the same shape


print("Loaded VecNormalize observation space:", vec_normalize.observation_space)-->self.observation_space:([],(132,),float32) print("New environment observation space:", venv.observation_space)-->venv.observation_space:([],(133,),float32)

Did I do something wrong?

D3F4LT4ST commented 6 months ago

I did some of these experiments a while ago, there were changes to the code since. https://github.com/D3F4LT4ST/RL-trading/commit/652fe725ca6ec63715f7a7f7e2da3e71b9bf3295