Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Cannot interpret 'torch.uint8' as a data type

Tags:

python

pytorch

Today I have started to learn Pytorch and I stuck here. The code piece in the comment raises this error: TypeError: Cannot interpret 'torch.uint8' as a data type

For changing the data type of the tensor I used: quzu_torch = quzu_torch.type(torch.float) But this time I got this error: TypeError: Cannot interpret 'torch.float32' as a data type

import numpy as np
import torch
from matplotlib import pyplot as plt

quzu = np.array(Image.open('wool.jpg').resize((224,224)))

quzu_torch = torch.from_numpy(quzu)

plt.imsave('quzucuq.jpg', quzu)

# quzu_torch = quzu_torch.type(torch.bool)
plt.imsave('quzucuq_tensor.jpg', quzu_torch)```
like image 667
Gulnar Avatar asked Aug 06 '26 19:08

Gulnar


1 Answers

Just use the numpy array for the image don't convert it into a torch tensor.

like image 153
Rakesh Raj Avatar answered Aug 09 '26 16:08

Rakesh Raj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!