It literally means that the the tuple class in Python doesn't have a method called to. Since you're trying to put your labels onto your device, just do labels = torch.tensor(labels).to(device).

If you don't want to do this, you can change the way the DataLoader works by making it return your labels as a PyTorch tensor rather than a tuple.

Edit

Since the labels seem to be strings, I would convert them to one-hot encoded vectors first:

>>> import torch
>>> labels_unique = set(labels)
>>> keys = {key: value for key, value in zip(labels_unique, range(len(labels_unique)))}
>>> labels_onehot = torch.zeros(size=(len(labels), len(keys)))
>>> for idx, label in enumerate(labels_onehot):
...     labels_onehot[idx][keys[label]] = 1
...
>>> labels_onehot = labels.to(device)

I'm shooting a bit in the dark here because I don't know the details exactly, but yeah strings won't work with tensors.

Answer from Sean on Stack Overflow
🌐
PyTorch Forums
discuss.pytorch.org › vision
'tuple' object has no attribute 'to' in pytorch - vision - PyTorch Forums
June 19, 2021 - I got this error while trying to test CNN model. I already checked type about this error point’variable. Here is error point 10. imgs = imgs.to(device) #imgs type <class ‘torch.Tensor’> —> 11 …
🌐
GitHub
github.com › pytorch › pytorch › issues › 116584
ERROR: AttributeError: 'tuple' object has no attribute 'to' · Issue #116584 · pytorch/pytorch
January 1, 2024 - 🐛 Describe the bug While running device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') model.to(device) optimizer = optim.Adam(model.parameters(), lr=0.001) loss_fn = nn.CrossEntropyLoss() def train(epoch): model.train() ...
Author   andysingal
🌐
PyTorch Forums
discuss.pytorch.org › vision
AttributeError: 'tuple' object has no attribute 'to' - vision - PyTorch Forums
April 6, 2021 - I got this error while trying to train a GAN model: run(config) File "t.py", line 417, in run x, y = x.to(device), y.to(device) AttributeError: 'tuple' object has no attribute 'to'
🌐
GitHub
github.com › slundberg › shap › issues › 2809
AttributeError: 'tuple' object has no attribute 'device' for tuple output · Issue #2809 · shap/shap
December 19, 2022 - I've been running a Deep Survival machines (Pytorch model) and have the model object after training. I use e = shap.DeepExplainer(best_model_obj, torch.tensor(x_train[:100,:], dtype=torch.double, device=torch.device('cpu')) ) and get the error: AttributeError: 'tuple' object has no attribute 'device'
Author   mahyahemmat
🌐
PyTorch Forums
discuss.pytorch.org › t › help-me-attributeerror-tuple-object-has-no-attribute-cpu › 114935
Help me: AttributeError: 'tuple' object has no attribute 'cpu' - PyTorch Forums
March 16, 2021 - Hi, can someone help me please: I’m try to run the code below, but I got this issues: rend = rend.cpu().data.numpy().transpose((0, 2, 3, 1)) AttributeError: ‘tuple’ object has no attribute ‘cpu’ I also printed the sh…
🌐
PyTorch Forums
discuss.pytorch.org › vision
'tuple' object has no attribute 'to' in pytorch - #3 by MJChoi - vision - PyTorch Forums
June 19, 2021 - I got this error while trying to test CNN model. I already checked type about this error point’variable. Here is error point 10. imgs = imgs.to(device) #imgs type <class ‘torch.Tensor’> —> 11 …
🌐
GitHub
github.com › PIX2NVS › NVS2Graph › issues › 12
AttributeError: 'tuple' object has no attribute 'view' when trying to run Test.py · Issue #12 · PIX2NVS/NVS2Graph
November 9, 2020 - This mode will increase the runtime and should only be enabled for debugging. with autograd.detect_anomaly(): tensor([2, 2, 5], device='cuda:0') /home/vi/anaconda3/envs/env_for_torch/lib/python3.8/site-packages/torch_sparse/storage.py:382: UserWarning: This overload of nonzero is deprecated: nonzero() Consider using one of the following signatures instead: nonzero(*, bool as_tuple) (Triggered internally at /opt/conda/conda-bld/pytorch_1603729096996/work/torch/csrc/utils/python_arg_parser.cpp:882.) ptr = mask.nonzero().flatten() Traceback (most recent call last): File "/home/vi/Documents/NVS2Gr
Author   vi-codes
Find elsewhere
🌐
GitHub
github.com › YutaroOgawa › pytorch_advanced › issues › 135
1-5_fine_tuningで「AttributeError: 'tuple' object has no attribute 'to'」エラー · Issue #135 · YutaroOgawa/pytorch_advanced
December 9, 2020 - google colaboratoryで1-5_fine_tuning.ipynbを実行したのですが、 AttributeError: 'tuple' object has no attribute 'to'というエラーがでました。 どこがわるいか教えていただけますでしょうか。 エラーメッセージとハードコピーを貼り付けます。 0%| | 0/5 [00:00&...
Author   neogim
🌐
PyTorch Forums
discuss.pytorch.org › vision
Error: AttributeError: 'tuple' object has no attribute 'size' - vision - PyTorch Forums
January 4, 2023 - Hi, I am working on Age and Gender prediction. I get this error "AttributeError: ‘tuple’ object has no attribute ‘size’ ". ‘’’ Combine Gender and Age y_gender_age = np.stack((y_gender, y_age), axis=1) y_gender_age[0:5…
🌐
PyTorch Forums
discuss.pytorch.org › vision
AttributeError: 'tuple' object has no attribute 't' - vision - PyTorch Forums
May 11, 2020 - Hi all, I am using a feature extraction module as given below: class FeatureExtractionModule(nn.Module): def __init__(self,feature_dimension,input_channels, kernel_size = 5, dropout_p = 0.3,leakiness = 0.01): super(FeatureExtractionModule,self).__init__() # Defining the hyperparameters of the ...
🌐
GitHub
github.com › pytorch › data › issues › 869
datapipes.to_graph() throws AttributeError: 'tuple' object has no attribute 'items' · Issue #869 · pytorch/data
November 1, 2022 - from torchdata.datapipes.iter import IterableWrapper from torchdata.datapipes.utils import to_graph items = IterableWrapper(range(10)) items.map(lambda x: x * 2) print(list(items)) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] prints the right result to_graph(items) # AttributeError: 'tuple' object has no attribute 'items'
🌐
PyTorch Forums
discuss.pytorch.org › vision
List type has no attribute 'to' - vision - PyTorch Forums
February 21, 2022 - List type has no attribute ‘to’ print(type(label)) >>> class ‘list’ for data, label in train loader: data=data.to(device) >>label=label.to(device) AttributeError: ‘tuple’ object has no attribute ‘to’ I also tried p…
🌐
PyTorch Forums
discuss.pytorch.org › t › attributeerror-tuple-object-has-no-attribute-dim › 11189
AttributeError: 'tuple' object has no attribute 'dim' - PyTorch Forums
December 15, 2017 - Hi all, I’m modifying the tutorial at http://pytorch.org/tutorials/beginner/transfer_learning_tutorial.html to use a model I’m defining myself with nn.Sequential like so: model = nn.Sequential( ## Encoder Network nn.Conv2d(3, 64, kernel_size=4), nn.ReLU(True), nn.Conv2d(64, 128, kernel_size=4), ...
🌐
PyTorch Forums
discuss.pytorch.org › nlp
AttributeError: 'tuple' object has no attribute 'permute' error in XLM-R pytorch - nlp - PyTorch Forums
March 3, 2022 - I’m trying to convert a BERT-LSTM model to XLM-R - LSTM model. The complete code of BERT-LSTM worked fine without any bugs. The forward function of the BERT-LSTM is as follows. def forward(self, sents): sents_tensor, masks_tensor, sents_lengths = sents_to_tensor(self.tokenizer, sents, self.device) encoded_layers, pooled_output = self.bert(input_ids=sents_tensor, attention_mask=masks_tensor, output_all_encoded_layers=False) encoded_layers = encoded_layers.permute(1, 0, 2)...
🌐
PyTorch Forums
discuss.pytorch.org › t › lstm-module-tuple-object-has-no-attribute-dim › 14400
LSTM module: 'tuple' object has no attribute 'dim' : - PyTorch Forums
March 5, 2018 - Hi All, I am trying to modify this example Link for pytorch, Though I am getting the same error, as discussed here Link .But I have passed the correct dimension: My model is like below: model = torch.nn.Sequential( torch.nn.Linear(1,20), torch.nn.LSTM(input_size = 20, hidden_size = 20,num_layers = 1,bidirectional = False), torch.nn.Linear(20, 1), ) And I’m trying to predict the output by passing the X_train, where X_train is the 3D vector of size (XX,49,1) y_pred = model(X_train...