Pytorch:值错误:要解包的值太多(应为3个)面部识别

rkue9o1l  于 2022-11-09  发布在  其他
关注(0)|答案(1)|浏览(133)

我正在用预测试模型对七个数据集进行评估。所有的数据集都在同一个文件夹中,其中有.bin.npy文件。我尝试了很多方法来修复错误,但仍然无法修复。当我在做训练时,它工作得很好。

原始代码https://github.com/zhongyy/Face-Transformer/blob/main/test_forward.py

存储库:https://github.com/zhongyy/Face-Transformer

代码

import torch
import torch.nn as nn
import sys
from vit_pytorch import ViT_face
from util.utils import get_val_data, perform_val, perform_val_deit, buffer_val, test_forward
from IPython import embed
import sklearn
import cv2
import numpy as np
from image_iter import FaceDataset
import torch.utils.data as data
import argparse
import os

DEVICE = torch.device("cuda:0")
DATA_ROOT = '/home/cvpr/Documents/ms1m-retinaface-t1/'
with open(os.path.join(DATA_ROOT, 'property'), 'r') as f:
    NUM_CLASS, h, w = [int(i) for i in f.read().split(',')]

model = ViT_face(
    image_size=112,
    patch_size=8,
    loss_type='CosFace',
    GPU_ID=DEVICE,
    num_class=NUM_CLASS,
    dim=512,
    depth=20,
    heads=8,
    mlp_dim=2048,
    dropout=0.1,
    emb_dropout=0.1
)

model_root = '/home/cvpr/Documents/Backbone_VIT_Epoch_2_Batch_20000_Time_2021-01-12-16-48_checkpoint.pth'
model.load_state_dict(torch.load(model_root))

TARGET = 'lfw'
vers = get_val_data('/home/cvpr/Documents/OPVT/eval')
print(vers)
for ver in vers:
    name, data_set, issame = ver
    time = test_forward(DEVICE, model, data_set)
    print(time)

打印(版本)

(carray((12000, 3, 112, 112), float32)
  nbytes := 1.68 GB; cbytes := 9.02 MB; ratio: 190.96
  cparams := cparams(clevel=5, shuffle=1, cname='lz4', quantize=0)
  chunklen := 13; chunksize: 1956864; blocksize: 262144
  rootdir := '/home/cvpr/Documents/OPVT/eval/lfw'
  mode    := 'r'
[[[[ 0.92941177  0.94509804  0.96862745 ..., -0.81960785 -0.7647059
    -0.73333335]

回溯

Traceback (most recent call last):
  File "/home/cvpr/Documents/OPVT/test_forward.py", line 42, in <module>
    name, data_set, issame = ver
ValueError: too many values to unpack (expected 3)
bhmjp9jg

bhmjp9jg1#

误差平均值的简单例子:您有序列/可迭代变量(列表、字典等):例如:

my_list = [1, 2, 3, 4]

然后打开列表:
正确答案:

a, b, c, d = my_list

错误:值错误:要解包的值太多

x, y = my_list

在您示例中,您打开了以下内容:您解压缩变量ver,该变量值不超过3个

相关问题