run the demo source,KeyError: 'img' error happen
F:\mmsegmentation\mmseg\models\decode_heads\decode_head.py:120: UserWarning: For binary segmentation, we suggest usingout_channels = 1
to define the outputchannels of segmentor, and use threshold
to convert seg_logits
into a predictionapplying a threshold
warnings.warn('For binary segmentation, we suggest using'
F:\mmsegmentation\mmseg\models\builder.py:36: UserWarning: build_loss
would be deprecated soon, please use mmseg.registry.MODELS.build()
warnings.warn('build_loss
would be deprecated soon, please use '
F:\mmsegmentation\mmseg\models\losses\cross_entropy_loss.py:250: UserWarning: Default avg_non_ignore
is False, if you would like to ignore the certain label and average loss over non-ignore labels, which is the same with PyTorch official cross_entropy, set avg_non_ignore=True
.
warnings.warn(
F:\mmsegmentation\mmseg\structures\sampler\builder.py:11: UserWarning: build_pixel_sampler
would be deprecated soon, please use mmseg.registry.TASK_UTILS.build()
warnings.warn(
Loads checkpoint by local backend from path: deeplabv3plus_r101_512x512_face-occlusion-93ec6695.pth
Traceback (most recent call last):
File "test_aac.py", line 9, in
result = inference_model(model, img)
File "F:\mmsegmentation\mmseg\apis\inference.py", line 112, in inference_model
data, is_batch = preprare_data(img, model)
File "F:\mmsegmentation\mmseg\apis\utils.py", line 37, in preprare_data
data = pipeline(data)
File "C:\ProgramData\miniconda3\envs\openmmlab\lib\site-packages\mmengine\dataset\base_dataset.py", line 60, in call
data = t(data)
File "C:\ProgramData\miniconda3\envs\openmmlab\lib\site-packages\mmcv\transforms\base.py", line 12, in call
return self.transform(results)
File "F:\mmsegmentation\mmseg\datasets\transforms\loading.py", line 172, in transform
img = results['img']
KeyError: 'img'
same problem, do you find solution?
The config file used LoadImageFromNDArray
, hence you need to modify the sample code to read source image with numpy.ndarray
, e.g.
import cv2
img_path = 'face-image.png'
img = cv2.imread(img_path)
result = inference_model(model, img)
Alternatively, modify the config file to use LoadImageFromFile
in test_pipeline
, then you can run the sample successfully with the image path.