简体   繁体   English

ValueError:pytorch 中的尺寸“str”太多 python

[英]ValueError: too many dimensions 'str' python in pytorch

I keep getting the error:我不断收到错误:

ValueError: too many dimensions 'str' ValueError:太多维度“str”

I attach my colab notebook to have a look at it.我附上我的 colab 笔记本来查看它。 Have not found anything online yet that helps me solve the problem.还没有在网上找到任何可以帮助我解决问题的东西。

link: https://colab.research.google.com/drive/1ikol2D8mmiIPKhNHbcFlTfVpuU_Gf9BZ?usp=sharing链接: https://colab.research.google.com/drive/1ikol2D8mmiIPKhNHbcFlTfVpuU_Gf9BZ?usp=sharing

I've seen this error as well in my Jupyter notebook.我在我的 Jupyter 笔记本中也看到了这个错误。 I can reproduce it with the following simple code:我可以使用以下简单代码重现它:

Input:
tensor(['a'])

Output: 
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-55-3bdb0dbfafc2> in <module>
----> 1 tensor(['a'])
...(stacktrace)...

ValueError: too many dimensions 'str'

Apparently PyTorch tensors are different from Numpy arrays in that they don't work with strings , only integers, floats, and booleans.显然 PyTorch 张量与 Numpy arrays 不同,因为它们不适用于字符串,仅适用于整数、浮点数和布尔值。

The above error indicates that there are too many strings passed to the tensor (ie even one string is too many).上述错误表明传递给张量的字符串太多(即即使一个字符串也太多)。 When I change the code to the following, it works fine:当我将代码更改为以下内容时,它可以正常工作:

Input:
tensor([1])

Output: 
tensor([1])

I haven't check your notebook yet but I just solved mine with same error.我还没有检查你的笔记本,但我刚刚解决了同样的错误。 Just double check if all training datasets and labels are converted to numeric values or tensors.只需仔细检查所有训练数据集和标签是否都转换为数值或张量。 If you have multiple columns in your dataframe remove the one that does not need to feed into training loop.如果 dataframe 中有多个列,请删除不需要输入训练循环的列。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Pytorch: ValueError: 太多维度: 3 &gt; 2. 9/opt/anaconda3/envs/pytorch/lib/python3.7/site-packages/PIL/Image.py in fromarray(obj, mode) - Pytorch: ValueError: Too many dimensions: 3 > 2. 9/opt/anaconda3/envs/pytorch/lib/python3.7/site-packages/PIL/Image.py in fromarray(obj, mode) 无法在torchtext迭代器中加载单热标签(ValueError:太多维&#39;str&#39;) - Unable to load one-hot labels in a torchtext iterator ( ValueError: too many dimensions 'str') OpenAIGPTModel PyTorch 错误 - ValueError: too many values to unpack (expected 2) - OpenAIGPTModel PyTorch Error- ValueError: too many values to unpack (expected 2) Tensorboard - ValueError:解包的值太多(预期 2) - Tensorboard - ValueError: too many values to unpack (expected 2) Pytorch数据加载器,线程过多,CPU内存分配过多 - Pytorch dataloader, too many threads, too much cpu memory allocation Pytorch 闪电指标:ValueError:preds 和 target 必须具有相同的维度数,或者 preds 的一个额外维度 - Pytorch lightning metrics: ValueError: preds and target must have same number of dimensions, or one additional dimension for preds PyTorch DataLoader-“ IndexError:维度0的张量的索引太多” - PyTorch DataLoader - “IndexError: too many indices for tensor of dimension 0” Pytorch自定义nn模块转发函数中的参数过多 - too many arguments in a Pytorch custom nn module forward function PyTorch转换可更改尺寸 - PyTorch transformations change dimensions 匹配 PyTorch 张量维度 - matching PyTorch tensor dimensions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM