I am receiving an error whilst looping through the batch The error: expected Tensor as element 0 in argument 0, but got builtin_function_or_method
I followed a tutorial on Udemy, but I am not sure what the issue is.
The Code:
def sample(self, batch_size):
assert self.can_sample(batch_size)
batch = random.sample(self.memory, batch_size)
batch = zip(*batch)
return [torch.cat(items) for items in batch]
def can_sample(self, batch_size):
return len(self.memory) >= batch_size * 10
The error:
TypeError Traceback (most recent call last)
Cell In[52], line 1
----> 1 stats = deep_sarsa(q_network, policy, 2000, epsilon = 0.01)
Cell In[51], line 24, in deep_sarsa(q_network, policy, episodes, alpha, batch_size, gamma, epsilon)
21 memory.insert([state, action, rewards, done, next_state])
23 if (memory.can_sample(batch_size)):
---> 24 state_b, action_b, reward_b, done_b, next__state_b = memory.sample(batch_size)
26 qsa_b = q_network(state_b).gather(1, action_b)
27 next_action_b = policy(next_state_b, epsilon)
Cell In[50], line 46, in ReplayMemory.sample(self, batch_size)
38 batch = zip(*batch)
41 #batch = torch.tensor(batch, dtype=torch.int8)
42 #torch.cat() -> concatinate the elements in a single tensor.
---> 46 return [torch.cat(items) for items in batch]
Cell In[50], line 46, in <listcomp>(.0)
38 batch = zip(*batch)
41 #batch = torch.tensor(batch, dtype=torch.int8)
42 #torch.cat() -> concatinate the elements in a single tensor.
---> 46 return [torch.cat(items) for items in batch]
TypeError: expected Tensor as element 0 in argument 0, but got builtin_function_or_method