From a2507af5f75186ca922af356685cf310ba40bd50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zheng=20Mingzhi=20=28AI=E7=A0=81=E5=A3=AB=29?= Date: Tue, 24 Jun 2025 19:28:43 +0800 Subject: [PATCH 1/2] Adding requirements.txt to resolve code incompatibility with the latest version of libraries --- requirements.txt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..843987a --- /dev/null +++ b/requirements.txt @@ -0,0 +1,7 @@ +numpy==1.22.0 +scipy==1.8.0 +matplotlib==3.5.0 +torch==1.8.0 +gym==0.23.0 +dezero==0.0.13 +pygame==2.1.2 \ No newline at end of file From 2baa71312b369ebeb85d0390bfb2756f23311de3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zheng=20Mingzhi=20=28AI=E7=A0=81=E5=A3=AB=29?= Date: Tue, 24 Jun 2025 19:30:02 +0800 Subject: [PATCH 2/2] Resolved the issue of "IndexError: tensors used as indices must be long, byte or bool tensors" --- pytorch/dqn.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pytorch/dqn.py b/pytorch/dqn.py index a9116c7..3833dc0 100644 --- a/pytorch/dqn.py +++ b/pytorch/dqn.py @@ -75,7 +75,8 @@ def update(self, state, action, reward, next_state, done): state, action, reward, next_state, done = self.replay_buffer.get_batch() qs = self.qnet(state) - q = qs[np.arange(len(action)), action] + # q = qs[np.arange(len(action)), action] + q = qs[torch.arange(len(action)), action.long()] next_qs = self.qnet_target(next_state) next_q = next_qs.max(1)[0]