# 逐图像处理 for img_id in images_ids: img_info = coco.loadImgs(img_id)[0] ann_ids = coco.getAnnIds(imgIds=img_id) anns = coco.loadAnns(ann_ids)
# 逐实例处理 for ann in anns: rle = coco.annToRLE(ann) # 解码 mask = mask_utils.decode(rle) # 生成原图mask
3 遇到的问题
3.1 ERROR: Could not build wheels for pycocotools
完整报错如下:
1 2 3 4 5 6 7 8 9
cl: 命令行 error D8021 :无效的数值参数“/Wno-cpp” error: command'D:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.40.33807\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2 [end of output]
note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for pycocotools Running setup.py clean for pycocotools Failed to build pycocotools ERROR: Could not build wheels for pycocotools, which is required to install pyproject.toml-based projects
3.2 subprocess.CalledProcessError: Command ‘[‘ninja’, ‘-v’]’ returned non-zero exit status 1.
完整报错如下:
1 2 3 4 5 6 7 8 9
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\include\crt/host_config.h(153): fatal error C1189: #error: -- unsupported Microsoft Visual Studio version! Only the versions between 2017 and 2022 (inclusive) are supported! The nvcc flag '-allow-unsupported-compiler' can be used to override this version check; however, using an unsupported host compiler may cause compilation failure or incorrect run time execution. Use at your own risk. ms_deform_attn_cuda.cu ninja: build stopped: subcommand failed. Traceback (most recent call last): File "F:\anaconda\anaconda3\envs\DeltaZero\lib\site-packages\torch\utils\cpp_extension.py", line 1900, in _run_ninja_build subprocess.run( File "F:\anaconda\anaconda3\envs\DeltaZero\lib\subprocess.py", line 526, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command '['ninja', '-v']' returned non-zero exit status 1.
LINK : fatal error LNK1181: 无法打开输入文件“D:\Code\Paper-code\DINO\models\dino\ops\build\temp.win-amd64-cpython-310\Release\Code\Paper-code\DINO\models\dino\ops\src\cuda\ms_deform_attn_cuda.obj” error: command'D:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.40.33807\\bin\\HostX86\\x64\\link.exe' failed with exit code 1181
通过以下方法得以解决:
将ninja关闭,修改如图所示,添加红框内的内容,setup.py文件中
3.4 –unsupported Microsoft Visual Studio version
完整报错如下:
1 2
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\include\crt/host_config.h(153): fatal error C1189: #error: -- unsupported Microsoft Visual Studio version! Only the versions between 2017 and 2022 (inclusive) are supported! The nvcc flag '-allow-unsupported-compiler' can be used to override this version check; however, using an unsupported host compiler may cause compilation failure or incorrect run time execution. Use at your own risk. error: command'C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.8\\bin\\nvcc.exe' failed with exit code 2
#error -- unsupported Microsoft Visual Studio version! Only the versions between 2017 and 2022 (inclusive) are supported! The nvcc flag '-allow-unsupported-compiler' can be used to override this version check; however, using an unsupported host compiler may cause compilation failure or incorrect run time execution. Use at your own risk.
#elif _MSC_VER >= 1910 && _MSC_VER <= 1940
#pragma message("support for this version of Microsoft Visual Studio has been deprecated! Only the versions between 2017 and 2022 (inclusive) are supported!")
File "D:\Code\Paper-code\DINO\models\dino\dn_components.py", line 36, in prepare_for_cdn known_num = [sum(k) for k in known] File "D:\Code\Paper-code\DINO\models\dino\dn_components.py", line 36, in <listcomp> known_num = [sum(k) for k in known] File "F:\anaconda\anaconda3\envs\DeltaZero\lib\site-packages\torch\_tensor.py", line 916, in __iter__ raise TypeError("iteration over a 0-d tensor") TypeError: iteration over a 0-d tensor
简单来说就行对一个0维的张量进行迭代,导致出错,与其相关的部分代码如下:
1 2 3 4 5 6
targets, dn_number, label_noise_ratio, box_noise_scale = dn_args # positive and negative dn queries dn_number = dn_number * 2 known = [(torch.ones_like(t['labels'])).cuda() for t in targets] batch_size = len(known) known_num = [sum(k) for k in known]
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import json import torch import numpy as np from PIL import Image from pathlib import Path
from coco import make_coco_transforms from DINO.util.box_ops import masks_to_boxes
5 RuntimeError: Expected weight to be a vector of size equal
完整报错如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Traceback (most recent call last): File "/root/autodl-tmp/DINO/main.py", line 401, in <module> main(args) File "/root/autodl-tmp/DINO/main.py", line 286, in main train_stats = train_one_epoch( File "/root/autodl-tmp/DINO/engine.py", line 48, in train_one_epoch outputs = model(samples, targets) File "/root/miniconda3/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl return forward_call(*input, **kwargs) File "/root/autodl-tmp/DINO/models/dino/dino.py", line 254, in forward y = self.test2(y) File "/root/miniconda3/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl return forward_call(*input, **kwargs) File "/root/miniconda3/lib/python3.10/site-packages/torch/nn/modules/normalization.py", line 273, in forward return F.group_norm( File "/root/miniconda3/lib/python3.10/site-packages/torch/nn/functional.py", line 2528, in group_norm return torch.group_norm(input, num_groups, weight, bias, eps, torch.backends.cudnn.enabled) RuntimeError: Expected weight to be a vector of size equal to the number of channels ininput, but got weight of shape [256] andinput of shape [256, 544, 820]