SlowFast报错:ValueError: too many values to unpack (expected 4)
报错细节
File "/home/user/yuanjinmin/SlowFast/tools/visualization.py", line 81, in run_visualizationfor inputs, labels, _, meta in tqdm.tqdm(vis_loader):
ValueError: too many values to unpack (expected 4)
报错原因
cfg.TENSORBOARD.MODEL_VIS
设置为True
,此时会执行SlowFast/tools/visualization.py
下第83
行的代码:
for inputs, labels, _, meta in tqdm.tqdm(vis_loader):
但vis_loader
中每个可迭代的对象是
可以加个
first_batch = next(iter(vis_loader))
print(first_batch)
进行验证
debug流程及修改
debug方法可参考之前的博文
我是在测试SlowFast模型时遇到的问题,而cfg.TENSORBOARD.MODEL_VIS
是TENSORBOARD
的可视化,这个是测试完最后执行的,测试大概需要4-5个小时的时间(单卡3090),因此为了尽快debug需要复制run_net.py
为visualization_net.py
,并修改为:
#!/usr/bin/env python3"""可视化模型"""
from slowfast.config.defaults import assert_and_infer_cfg
from slowfast.utils.misc import launch_job
from slowfast.utils.parser import load_config, parse_argsfrom demo_net import demo
from test_net import test
from train_net import train
from visualization import visualizedef main():"""Main function to spawn the train and test process."""# todoimport pydevd_pycharmpydevd_pycharm.settrace('localhost', port=29501, stdoutToServer=True, stderrToServer=True)args = parse_args()print("config files: {}".format(args.cfg_files))for path_to_config in args.cfg_files:cfg = load_config(args, path_to_config)cfg = assert_and_infer_cfg(cfg)# Perform model visualization.if cfg.TENSORBOARD.ENABLE and (cfg.TENSORBOARD.MODEL_VIS.ENABLEor cfg.TENSORBOARD.WRONG_PRED_VIS.ENABLE):launch_job(cfg=cfg, init_method=args.init_method, func=visualize)if __name__ == "__main__":main()
在此基础上debugSlowFast/tools/visualization.py
下第83
行的代码,可以看到:
每个可迭代的对象有5个成员,因此在这里多加一个_,
即可
# todo 此处增加了一个_,因为vis_loader的返回值是5个,而原来的是4个# for inputs, labels, _, meta in tqdm.tqdm(vis_loader):for inputs, labels, _, _, meta in tqdm.tqdm(vis_loader):
当然,也可直接将cfg.TENSORBOARD.MODEL_VIS
设置为False
,建议这个还是不要打开,非常地耗时…