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

ImportError: cannot import name 'inference_segmentor' from 'mmseg.apis' #9

Open
nnmaitian opened this issue Dec 6, 2023 · 18 comments

Comments

@nnmaitian
Copy link

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.

@201210302
Copy link

change the function name in artifact_detection.py
스크린샷 2023-12-08 123140

#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

@LiangbinXie
Copy link
Collaborator

@nnmaitian Did you follow the specific version of mmsegmentation?

@nnmaitian
Copy link
Author

@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'

@nnmaitian
Copy link
Author

change the function name in artifact_detection.py 스크린샷 2023-12-08 123140

#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'"

@LiangbinXie
Copy link
Collaborator

@nnmaitian This is a little bit weird. I'll check it this weekend.

@201210302
Copy link

201210302 commented Dec 13, 2023

@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.

@LiangbinXie
Copy link
Collaborator

@201210302 Hello, can you get the same results in this situation? If so, I will directly adopt your strategy.

@201210302
Copy link

201210302 commented Dec 15, 2023

@nnmaitian I uploaded the artifact_detection.py I used.

https://github.com/201210302/DeSRA_execution/tree/main/mmsegmentation/demo

@nnmaitian
Copy link
Author

@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
Copy link
Author

nnmaitian commented Dec 19, 2023

@nnmaitian This is a little bit weird. I'll check it this weekend.

Hello, is there any solution to the problem I encountered?

@LiangbinXie
Copy link
Collaborator

@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.

@201210302
Copy link

@nnmaitian I corrected the link

@haikunzhang95
Copy link

@201210302 I used your artifact_detection.py, but encountered:
ModuleNotFoundError: No module named 'mmseg'.
Do you have any suggestions?
Thank U.

@nnmaitian
Copy link
Author

@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.
20240109-164129

@201210302
Copy link

@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.

@201210302
Copy link

@nnmaitian I updated the artifact_detection.py in my github https://github.com/201210302/DeSRA_execution/tree/main/mmsegmentation/demo

@201210302
Copy link

@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)

@shahabe
Copy link

shahabe commented Jul 3, 2024

It seems in the newer version, the inference_segmentor has been changed to inference_model, based on this: open-mmlab/mmsegmentation#3516 (comment)

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

5 participants