Why can't I convert to LongTensor

pak_key: <p>import torch<br>
import matplotlib.pyplot as plt<br>
from sklearn.datasets import make_blobs<br>
from sklearn.model_selection import train_test_split</p>
<h1><a name="h-1" class="anchor" href="#h-1"></a>设置类别的个数</h1>
<p>NUM_CLASSES = 4<br>
NUM_FRATURES = 2<br>
RANDEM_SEED = 42</p>
<h1><a name="h-2" class="anchor" href="#h-2"></a>创建数据集</h1>
<p>X_blob,y_bolb = make_blobs(n_samples=1000,<br>
n_features=NUM_FRATURES,<br>
centers=NUM_CLASSES,<br>
cluster_std=1.5,<br>
random_state=RANDEM_SEED,)</p>
<h1><a name="sklearnnumpytensors-3" class="anchor" href="#sklearnnumpytensors-3"></a>sklearn的数据集使用的是numpy,所以要转为Tensors。</h1>
<p>X_blob = torch.from_numpy(X_blob).type(torch.float)<br>
y_bolb = torch.from_numpy(y_bolb).type(torch.LongTensor)<br>
print(y_bolb.dtype)</p>
<h1><a name="h-4" class="anchor" href="#h-4"></a>切割训练和测试训练集</h1>
<p>X_blob_train,X_blob_test,y_blob_train,y_blob_test  = train_test_split(X_blob,y_bolb,test_size=0.2,random_state=RANDEM_SEED)</p>
<h1><a name="h-5" class="anchor" href="#h-5"></a>可视化数据集</h1>
<p>plt.figure(figsize=(12,10))<br>
plt.scatter(X_blob[:,0],X_blob[:,1],c=y_bolb,cmap=plt.cm.RdYlBu)</p>
<p>--------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) Cell In[143], <a>line 22</a> <a>19</a> y_pred = torch.softmax(y_logits,dim=1).argmax(dim=1) <a>21</a> # 计算损失(交叉熵)(X为训练,y为测试) —&gt; <a>22</a> loss = loss_fn(y_pred,y_blob_test) <a>23</a> # 准确性 <a>24</a> acc = acccracy_fn(y_true=y_blob_train,y_pred=y_pred) File [d:\python_3.11\Lib\site-packages\torch\nn\modules\module.py:1501](file:///D:/python_3.11/Lib/site-packages/torch/nn/modules/module.py:1501), in Module._call_impl(self, *args, **kwargs) [1496](file:///D:/python_3.11/Lib/site-packages/torch/nn/modules/module.py:1496) # If we don’t have any hooks, we want to skip the rest of the logic in [1497](file:///D:/python_3.11/Lib/site-packages/torch/nn/modules/module.py:1497) # this function, and just call forward. [1498](file:///D:/python_3.11/Lib/site-packages/torch/nn/modules/module.py:1498) if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks [1499](file:///D:/python_3.11/Lib/site-packages/torch/nn/modules/module.py:1499) or _global_backward_pre_hooks or _global_backward_hooks [1500](file:///D:/python_3.11/Lib/site-packages/torch/nn/modules/module.py:1500) or _global_forward_hooks or _global_forward_pre_hooks): → [1501](file:///D:/python_3.11/Lib/site-packages/torch/nn/modules/module.py:1501) return forward_call(*args, **kwargs) [1502](file:///D:/python_3.11/Lib/site-packages/torch/nn/modules/module.py:1502) # Do not call functions when jit is used [1503](file:///D:/python_3.11/Lib/site-packages/torch/nn/modules/module.py:1503) full_backward_hooks, non_full_backward_hooks = <span class="chcklst-box fa fa-square-o fa-fw"></span>, <span class="chcklst-box fa fa-square-o fa-fw"></span> File [d:\python_3.11\Lib\site-packages\torch\nn\modules\loss.py:1174](file:///D:/python_3.11/Lib/site-packages/torch/nn/modules/loss.py:1174), in CrossEntropyLoss.forward(self, input, target) [1173](file:///D:/python_3.11/Lib/site-packages/torch/nn/modules/loss.py:1173) def forward(self, input: Tensor, target: Tensor) → Tensor: → [1174](file:///D:/python_3.11/Lib/site-packages/torch/nn/modules/loss.py:1174) return F.cross_entropy(input, target, weight=self.weight, [1175](file:///D:/python_3.11/Lib/site-packages/torch/nn/modules/loss.py:1175) ignore_index=self.ignore_index, reduction=self.reduction, [1176](file:///D:/python_3.11/Lib/site-packages/torch/nn/modules/loss.py:1176) label_smoothing=self.label_smoothing)</p>
<p>…</p>
<p>[3027](file:///D:/python_3.11/Lib/site-packages/torch/nn/functional.py:3027) if size_average is not None or reduce is not None: [3028](file:///D:/python_3.11/Lib/site-packages/torch/nn/functional.py:3028) reduction = _Reduction.legacy_get_string(size_average, reduce) → [3029](file:///D:/python_3.11/Lib/site-packages/torch/nn/functional.py:3029) return torch._C._nn.cross_entropy_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index, label_smoothing) RuntimeError: “log_softmax_lastdim_kernel_impl” not implemented for ‘Long’</p>
<p>Output is truncated. View as a <a>scrollable element</a> or open in a <a>text editor</a>. Adjust cell output <a>settings</a>…</p>

ptrblck: <p><code>nn.CrossEntropyLoss</code> expects floating point inputs for the logits and does accept integer types for the targets only.</p>