Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

可以修改board的大小吗,12*12太小了,能否改成36*36或者铺满整个屏幕的 #8

Open
aijunzhao opened this issue May 23, 2023 · 2 comments

Comments

@aijunzhao
Copy link

我一改动,就报错,怎么修改才可以呢?

@aijunzhao
Copy link
Author

这是改成24*24的报错。

(SnakeAI) E:\snake-ai-master\main>python test_cnn.py
Using seed = 591160627 for testing.
=================== Episode 1 ==================
Traceback (most recent call last):
File "test_cnn.py", line 45, in
action, _ = model.predict(obs, action_masks=env.get_action_mask())
File "C:\Users\KEN2020.conda\envs\SnakeAI\lib\site-packages\sb3_contrib\ppo_mask\ppo_mask.py", line 379, in predict
return self.policy.predict(observation, state, episode_start, deterministic, action_masks=action_masks)
File "C:\Users\KEN2020.conda\envs\SnakeAI\lib\site-packages\sb3_contrib\common\maskable\policies.py", line 276, in predict
observation, vectorized_env = self.obs_to_tensor(observation)
File "C:\Users\KEN2020.conda\envs\SnakeAI\lib\site-packages\stable_baselines3\common\policies.py", line 263, in obs_to_tensor
vectorized_env = is_vectorized_observation(observation, self.observation_space)
File "C:\Users\KEN2020.conda\envs\SnakeAI\lib\site-packages\stable_baselines3\common\utils.py", line 398, in is_vectorized_observation
return is_vec_obs_func(observation, observation_space)
File "C:\Users\KEN2020.conda\envs\SnakeAI\lib\site-packages\stable_baselines3\common\utils.py", line 265, in is_vectorized_box_observation
raise ValueError(
ValueError: Error: Unexpected observation shape (168, 168, 3) for Box environment, please use (3, 84, 84) or (n_env, 3, 84, 84) for the observation shape.

(SnakeAI) E:\snake-ai-master\main>

@lang07123
Copy link

这个东西可能比你想象中的要复杂, 如果你需要修改棋盘大小, 那么你需要重新训练模型, (我措辞好几次, 发现我的知识不足以解释清楚为什么需要重新训练, 放弃了..) 但是它的难度提升之大, 远不是 16 - 12 能比拟的...你的训练时间会成倍增长, 套用作者的计算方式.

(SnakeAI) PS E:\ai-demo\snake-ai-master\main> python ..\utils\path_counter.py
The total number of path with length 60 in a 12x12 grid is  6353172170978043900310938172858813152.
(SnakeAI) PS E:\ai-demo\snake-ai-master\main> python ..\utils\path_counter.py
The total number of path with length 60 in a 16x16 grid is 22725213785431853779603119329747403536.

如果你实在需要更大的棋盘的模型, 你需要修改两个地方, 以16为例子, 简单来说gym.spaces.Box的shape,为 16 * 7 (别问为什么解释不了.)
snake_game_custom_wrapper_cnn.py
图片

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants