ImportError: cannot import name 'inference_segmentor' from 'mmseg.apis'
Hello, I encountered the following problem, from mmseg.apis import inference_segmentor, init_segmentor, show_seg ImportError: cannot import name 'inference_segmentor' from 'mmseg.apis' . How to solve it.
change the function name in artifact_detection.py
#from mmseg.apis import inference_segmentor, init_segmentor, show_seg from mmseg.apis import inference_model, init_model, show_result_pyplot #from mmseg.core.evaluation import get_palette from mmseg.utils import get_palette
@nnmaitian Did you follow the specific version of mmsegmentation?
@nnmaitian Did you follow the specific version of mmsegmentation?
Yes. I use the following code to specify the mmseg version and installation.
git reset --hard 356215bf586b1404d4cb0c205685fcf589df6148 pip install -v -e . pip install mmcv-full==1.6.1
But still ImportError: cannot import name 'show_seg' from 'mmseg.apis'
change the function name in artifact_detection.py
#from mmseg.apis import inference_segmentor, init_segmentor, show_seg from mmseg.apis import inference_model, init_model, show_result_pyplot #from mmseg.core.evaluation import get_palette from mmseg.utils import get_palette
Hi, I used the solution you recommended, but I got an error when running "result = inference_model(model, gan_img_path)". Error display "Error init() got an unexpected keyword argument 'img_scale'"
@nnmaitian This is a little bit weird. I'll check it this weekend.
@nnmaitian I used the latest version of mmsegmentation, and modified artifact_detection.py as above to use the latest version of mmsegmentation. When editing, be sure to change not only the import part but also the function name used below. Accordingly, an error message may appear saying that the necessary files are not in the appropriate directory, but when I set the file path according to the error message, quick-inference was even executable.
@201210302 Hello, can you get the same results in this situation? If so, I will directly adopt your strategy.
@nnmaitian I uploaded the artifact_detection.py I used.
https://github.com/201210302/DeSRA_execution/tree/main/mmsegmentation/demo
@nnmaitian I uploaded the artifact_detection.py I used.https://github.com/201210302/DeSRA_execution/tree/main/mmsegmentation/demo/artifact_detection.py
Hi, thank you for your answer. Your link is invalid because the question was closed. I can't see your updated artifact_detection.py file. Can you post it directly under the question?
@nnmaitian This is a little bit weird. I'll check it this weekend.
Hello, is there any solution to the problem I encountered?
@nnmaitian I can check the code uploaded by @201210302. You should directly copy the link (not click) to a new webpage. Maybe you can try this modified file first.
@nnmaitian I corrected the link
@201210302 I used your artifact_detection.py, but encountered: ModuleNotFoundError: No module named 'mmseg'. Do you have any suggestions? Thank U.
@nnmaitian I corrected the link
@201210302 hi, thank you for your answer.Now my version is mmcv 2.0.0rc4, mmsegmentation v1.2.2. artifact_detection.py used your link. But I encountered the following problem.
@nnmaitian @haikunzhang95 I will soon summarize the execution method I did and post it on my GitHub Readme. I will also re-upload the artifact_detection.py file used.
@nnmaitian I updated the artifact_detection.py in my github https://github.com/201210302/DeSRA_execution/tree/main/mmsegmentation/demo
@nnmaitian @LiangbinXie I upload the explanation of DeSRA execution: https://github.com/201210302/DeSRA_execution. Also, you need to redownload artifact_detection.py(I modified it)
It seems in the newer version, the inference_segmentor has been changed to inference_model, based on this: https://github.com/open-mmlab/mmsegmentation/issues/3516#issuecomment-2071093363
