Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

运行【k3】代码,批量预测时更改图像文件路径,多张图片预测报错ValueError: uri should not be None when "backend" does not exist in backend_args #12

Open
ggfly12138 opened this issue Dec 19, 2023 · 2 comments

Comments

@ggfly12138
Copy link

PATH_IMAGE = 'new_pic'
os.chdir(PATH_IMAGE)
单张图像预测函数
opacity = 0.3 # 透明度,越大越接近原图
def process_single_img(img_path, save=False):

img_bgr = cv2.imread(img_path)


# 语义分割预测
result = inference_model(model, img_bgr)
pred_mask = result.pred_sem_seg.data[0].cpu().numpy()

# 将预测的整数ID,映射为对应类别的颜色
pred_mask_bgr = np.zeros((pred_mask.shape[0], pred_mask.shape[1], 3))
for idx in palette_dict.keys():
pred_mask_bgr[np.where(pred_mask==idx)] = palette_dict[idx]
pred_mask_bgr = pred_mask_bgr.astype('uint8')

# 将语义分割预测图和原图叠加显示
pred_viz = cv2.addWeighted(img_bgr, opacity, pred_mask_bgr, 1-opacity, 0)

# 保存图像至 outputs/testset-pred 目录
if save:
    save_path = os.path.join('../','../','../','outputs', 'testset-pred', 'pred-'+img_path.split('/')[-1])
    cv2.imwrite(save_path, pred_viz)

测试集批量预测
for each in tqdm(os.listdir()):
process_single_img(each, save=True)
0%| | 0/9 [00:00<?, ?it/s]

ValueError Traceback (most recent call last)
/tmp/ipykernel_19296/3402639611.py in
1 for each in tqdm(os.listdir()):
----> 2 process_single_img(each, save=True)

/tmp/ipykernel_19296/80219051.py in process_single_img(img_path, save)
4
5 # 语义分割预测
----> 6 result = inference_model(model, img_bgr)
7 pred_mask = result.pred_sem_seg.data[0].cpu().numpy()
8

~/work/mmsegmentation/mmseg/apis/inference.py in inference_model(model, img)
141 """
142 # prepare data
--> 143 data, is_batch = _preprare_data(img, model)
144
145 # forward the model

~/work/mmsegmentation/mmseg/apis/inference.py in preprare_data(imgs, model)
119 else:
120 data
= dict(img_path=img)
--> 121 data_ = pipeline(data_)
122 data['inputs'].append(data_['inputs'])
123 data['data_samples'].append(data_['data_samples'])

/environment/miniconda3/lib/python3.7/site-packages/mmengine/dataset/base_dataset.py in call(self, data)
58 """
59 for t in self.transforms:
---> 60 data = t(data)
61 # The transform will return None when it failed to load images or
62 # cannot find suitable augmentation parameters to augment the data.

/environment/miniconda3/lib/python3.7/site-packages/mmcv/transforms/base.py in call(self, results)
10 results: Dict) -> Optional[Union[Dict, Tuple[List, List]]]:
11
---> 12 return self.transform(results)
13
14 @AbstractMethod

/environment/miniconda3/lib/python3.7/site-packages/mmcv/transforms/loading.py in transform(self, results)
105 return None
106 else:
--> 107 raise e
108 if self.to_float32:
109 img = img.astype(np.float32)

/environment/miniconda3/lib/python3.7/site-packages/mmcv/transforms/loading.py in transform(self, results)
98 else:
99 img_bytes = fileio.get(
--> 100 filename, backend_args=self.backend_args)
101 img = mmcv.imfrombytes(
102 img_bytes, flag=self.color_type, backend=self.imdecode_backend)

/environment/miniconda3/lib/python3.7/site-packages/mmengine/fileio/io.py in get(filepath, backend_args)
178 """
179 backend = get_file_backend(
--> 180 filepath, backend_args=backend_args, enable_singleton=True)
181 return backend.get(filepath)
182

/environment/miniconda3/lib/python3.7/site-packages/mmengine/fileio/io.py in get_file_backend(uri, backend_args, enable_singleton)
136 if uri is None and 'backend' not in backend_args:
137 raise ValueError(
--> 138 'uri should not be None when "backend" does not exist in '
139 'backend_args')
140

ValueError: uri should not be None when "backend" does not exist in backend_args

@wyf0414
Copy link

wyf0414 commented Jan 15, 2024

请问如何解决ValueError: uri should not be None when "backend" does not exist in backend_args

@ggfly12138
Copy link
Author

请问如何解决ValueError: uri should not be None when "backend" does not exist in backend_args

请问你解决这个这个问题了嘛?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants