简体   繁体   中英

Tensorboard - ValueError: too many values to unpack (expected 2)

I have tried to use tensorboard to visualize a model. I was following the pytorch.org tutorial . Here is the code for dataloader.

writer_train = SummaryWriter('runs/training')

train_loader = torch.utils.data.DataLoader(train_dataset, batch_size=config.train_batch_size, shuffle=True,
                                           num_workers=config.num_workers, pin_memory=True)

images, labels = next(iter(train_loader))
writer_train.graph_model(light_net, images)

and I got this error in the iter line.

images, labels = next(iter(train_loader)) ValueError: too many values to unpack (expected 2)

I have debugged the code and found this. 在此处输入图像描述

The error is likely caused by the use of a built-in function instead of the .next() method of the train_loader object.

next() and iter() are builtin methods in Python . See from the docs iter and next .

In the tutorial is shows the following

# get some random training images
dataiter = iter(trainloader)
images, labels = dataiter.next()

Where it uses the next() method to unpack values into the 2 variables. This is not the same as your usage of next(iter(train_loader)) . Do it in the way as shown and it should solve your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM