使用torch.from_numpy时如何解决PyTorch UnicodeEncodeError错误?

时间:2017-10-31 08:57:34

标签: python-3.x numpy pytorch

我正在使用PyTorch和python3。 我在ipdb模式下尝试了以下内容:

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

打印张量。 但是在尝试时:

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

我收到以下错误:

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

我正在使用:

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

和python3.5.3

2 个答案:

答案 0 :(得分:0)

我能够在jupyter笔记本中运行两个版本的代码。我要说这种Unicode编解码器错误不是由.from_numpy()

引起的

我正在运行Python 3.5.2 | Anaconda custom(x86_64)

numpy==1.13.0
torch==0.1.12.post2
torchvision==0.1.8

答案 1 :(得分:0)

来自网站http://pytorch.org/,他们说:

  

请确保您使用最新的pip和numpy包。

我无法使用最新版本的numpy和pytorch重现您的错误。我认为pip install -U numpy可能会解决问题。

相关问题