处理报错
/opt/conda/lib/python3.10/site-packages/torch/nn/modules/transformer.py:307: UserWarning: enable_nested_tensor is True, but self.use_nested_tensor is False because encoder_layer.self_attn.batch_first was not True(use batch_first for better inference performance)
  warnings.warn(f"enable_nested_tensor is True, but self.use_nested_tensor is False because {why_not_sparsity_fast_path}")
Epoch 1 / 200 lr=0.001
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[2], line 230
    226     plt.show()
    229 if __name__ == '__main__':
--> 230     main()

Cell In[2], line 93, in main()
     90 resultdatafolder = f'{resultdatafolder}_{i}'
     91 os.makedirs(resultdatafolder)
---> 93 train_model(model, train_loader, test_loader, mixup_loss, optimizer, scheduler, device, resultdatafolder)
     94 test_acc = test_model(model, test_loader, nn.CrossEntropyLoss(), device, resultdatafolder)  # 测试时正常使用交叉熵损失
     95 print(f"Final Test Accuracy: {test_acc:.2f}%")

Cell In[2], line 113, in train_model(model, train_loader, test_loader, loss_func, optimizer, scheduler, device, resultdatafolder)
    110 for epoch in range(args.es):
    111     print(f"Epoch {epoch + 1} / {args.es} lr={optimizer.param_groups[0]['lr']}")
--> 113     train_acc, train_loss = train(model, train_loader, loss_func, optimizer, device)
    114     val_acc, val_loss, _, _ = test(model, test_loader, nn.CrossEntropyLoss(), device)  # 测试时使用标准损失函数
    116     scheduler.step()  # 调整学习率

Cell In[2], line 161, in train(model, train_loader, loss_func, optimizer, device)
    158 total_loss = 0.0
    159 dataset_size = len(train_loader.dataset)
--> 161 for features, labels in train_loader:
    162     features, labels = features.to(device), labels.to(device)
    163     optimizer.zero_grad()

File /opt/conda/lib/python3.10/site-packages/torch/utils/data/dataloader.py:630, in _BaseDataLoaderIter.__next__(self)
    627 if self._sampler_iter is None:
    628     # TODO(https://github.com/pytorch/pytorch/issues/76750)
    629     self._reset()  # type: ignore[call-arg]
--> 630 data = self._next_data()
    631 self._num_yielded += 1
    632 if self._dataset_kind == _DatasetKind.Iterable and \
    633         self._IterableDataset_len_called is not None and \
    634         self._num_yielded > self._IterableDataset_len_called:

File /opt/conda/lib/python3.10/site-packages/torch/utils/data/dataloader.py:673, in _SingleProcessDataLoaderIter._next_data(self)
    671 def _next_data(self):
    672     index = self._next_index()  # may raise StopIteration
--> 673     data = self._dataset_fetcher.fetch(index)  # may raise StopIteration
    674     if self._pin_memory:
    675         data = _utils.pin_memory.pin_memory(data, self._pin_memory_device)

File /opt/conda/lib/python3.10/site-packages/torch/utils/data/_utils/fetch.py:55, in _MapDatasetFetcher.fetch(self, possibly_batched_index)
     53 else:
     54     data = self.dataset[possibly_batched_index]
---> 55 return self.collate_fn(data)

Cell In[2], line 66, in main.<locals>.<lambda>(x)
     58 print('target_set sample num:', len(target_set))
     60 # 使用 MixUp 的 DataLoader
     61 train_loader = DataLoader(
     62     source_set,
     63     batch_size=args.bs,
     64     shuffle=True,
     65     num_workers=0,
---> 66     collate_fn=lambda x: mixup_collate_fn(x, alpha=ALPHA)
     67 )
     69 # test_loader 不需要 MixUp
     70 test_loader = DataLoader(target_set, batch_size=args.bs, shuffle=False, num_workers=0)

File /kaggle/input/mix_up_withmode/other/default/1/myDataset.py:124, in mixup_collate_fn(batch, alpha)
    122 # 应用 MixUp
    123 mixed_features = lambda_ * features + (1 - lambda_) * features[index, :]
--> 124 mixed_labels = lambda_ * labels + (1 - lambda_) * labels[index, :]  # 适配 one-hot 标签
    126 return mixed_features, mixed_labels

IndexError: too many indices for tensor of dimension 1