reinforcement-learning icon indicating copy to clipboard operation
reinforcement-learning copied to clipboard

TypeError: img should be PIL Image. Got <class 'torch.Tensor'>

Open wwwpkol opened this issue 2 years ago • 1 comments

Hey friend. I downloaded the code as you asked, but I get this error when I run it. My coding skills are poor and I don't know how to modify it. Can you give me a hand?

Traceback (most recent call last): File "D:/code/Pytorch_yyh/Macri_2022_1_19/reinforcement-learning-main/mario_enviroment/mario_ppo.py", line 214, in solver = PPOSolver() File "D:/code/Pytorch_yyh/Macri_2022_1_19/reinforcement-learning-main/mario_enviroment/mario_ppo.py", line 108, in init self.obs = env.reset().array() File "C:\Users\yyh.conda\envs\Pytorch_envs\lib\site-packages\gym\wrappers\frame_stack.py", line 110, in reset observation = self.env.reset(**kwargs) File "C:\Users\yyh.conda\envs\Pytorch_envs\lib\site-packages\gym\core.py", line 264, in reset observation = self.env.reset(**kwargs) File "C:\Users\yyh.conda\envs\Pytorch_envs\lib\site-packages\gym\core.py", line 265, in reset return self.observation(observation) File "D:/code/Pytorch_yyh/Macri_2022_1_19/reinforcement-learning-main/mario_enviroment/mario_ppo.py", line 40, in observation return transform(torch.tensor(np.transpose(observation, (2, 0, 1)).copy(), dtype=torch.float)) File "C:\Users\yyh.conda\envs\Pytorch_envs\lib\site-packages\torchvision\transforms\transforms.py", line 1249, in call return F.to_grayscale(img, num_output_channels=self.num_output_channels) File "C:\Users\yyh.conda\envs\Pytorch_envs\lib\site-packages\torchvision\transforms\functional.py", line 949, in to_grayscale raise TypeError('img should be PIL Image. Got {}'.format(type(img))) TypeError: img should be PIL Image. Got <class 'torch.Tensor'>

Process finished with exit code 1

wwwpkol avatar Jan 19 '22 10:01 wwwpkol

Hi, don't use conda Create python venv and then use pip install -r requirements.txt from this repo

kekw333 avatar Jan 19 '22 12:01 kekw333