-2

I am using PyTorch with python3. I tried the following while in ipdb mode:

regions = np.zeros([107,4], dtype='uint8')
torch.from_numpy(regions)

This prints the tensor. However when trying:

regions = np.zeros([107,107,4], dtype='uint8')
torch.from_numpy(regions)

I get the following error:

*** UnicodeEncodeError: 'ascii' codec can't encode character '\u22ee' in position 72: ordinal not in range(128)

I'm am using:

numpy==1.11.3
torch==0.2.0.post4
torchvision==0.1.9

and python3.5.3

avitheavi
  • 103
  • 1
  • 9
  • Why is this question getting downvotes? – titusfx Mar 12 '18 at 21:35
  • I find several solutions and all says the same, try to find what file are you importing on your script that use *with open(filename) as* and change it for *with open(filename, encoding='utf8') as* . That worked for me. Check these solutions: https://stackoverflow.com/questions/30750843/python-3-unicodedecodeerror-charmap-codec-cant-decode-byte-0x9d , https://stackoverflow.com/questions/42919076/python-charmap-codec-cant-decode-byte-x-in-position-y-character-maps-to-undefi, https://stackoverflow.com/questions/18648154/read-lines-of-a-textfile-and-getting-charmap-decode-error – titusfx Mar 12 '18 at 21:48

2 Answers2

0

I'm able to run both versions of your code with no issues in a jupyter notebook. I'm gonna say that this kind of Unicode codec error is not due to .from_numpy()

I'm running Python 3.5.2 |Anaconda custom (x86_64)

numpy==1.13.0
torch==0.1.12.post2
torchvision==0.1.8
ruoho ruotsi
  • 1,283
  • 14
  • 13
0

From the website http://pytorch.org/ they say:

Please ensure that you are on the latest pip and numpy packages.

I was not able to reproduce your errors with recent versions of numpy and pytorch. I think pip install -U numpy might solve the problem.

Manuel Lagunas
  • 2,611
  • 19
  • 31
  • I have a similar problem trying https://github.com/jojonki/BiDAF I did what you suggest and I'm still having the same problem. – titusfx Mar 12 '18 at 21:36