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 '_mask' #410

Open
rongxuanhong opened this issue Dec 28, 2018 · 26 comments
Open

ImportError: cannot import name '_mask' #410

rongxuanhong opened this issue Dec 28, 2018 · 26 comments

Comments

@rongxuanhong
Copy link

I use pytorch-1.0 and python3.6.7,and build under conda.the process of building did't show error.but,when start to train trainval.net,it shows the following error:

File "trainval_net.py", line 27, in
from roi_data_layer.roidb import combined_roidb
File "/home/ccyoung/workspace/faster-rcnn.pytorch/lib/roi_data_layer/roidb.py", line 9, in
from datasets.factory import get_imdb
File "/home/ccyoung/workspace/faster-rcnn.pytorch/lib/datasets/factory.py", line 15, in
from datasets.coco import coco
File "/home/ccyoung/workspace/faster-rcnn.pytorch/lib/datasets/coco.py", line 23, in
from pycocotools.coco import COCO
File "/home/ccyoung/workspace/faster-rcnn.pytorch/lib/pycocotools/coco.py", line 60, in
from . import mask
File "/home/ccyoung/workspace/faster-rcnn.pytorch/lib/pycocotools/mask.py", line 3, in
from . import _mask
ImportError: cannot import name '_mask'

it seems the building problem of coco API

@geekli
Copy link

geekli commented Dec 28, 2018

make sure the branch is pytorch-1.0
and
cd lib && python setup.py build develop
then retry?

@rongxuanhong
Copy link
Author

make sure the branch is pytorch-1.0
and
cd lib && python setup.py build develop
then retry?
make sure. I clone it with --b

@KwanWaiChung
Copy link

make sure the branch is pytorch-1.0
and
cd lib && python setup.py build develop
then retry?

Having the same problem as well. I am using the pytorch-1.0 branch and has run "python setup.py build develop".

@KwanWaiChung
Copy link

Just find out that you have to install the CoCO API.

cd data

git clone https://github.com/pdollar/coco.git cd coco/PythonAPI

make

cd ../../..

@Bijiazhou
Copy link

Just find out that you have to install the CoCO API.

cd data

git clone https://github.com/pdollar/coco.git cd coco/PythonAPI

make

cd ../../..

thx a lot

@shahmustafa
Copy link

I am using pytorch 1.0 and python 3.6.7

Traceback (most recent call last):
File "demo.py", line 27, in
from roi_data_layer.roidb import combined_roidb
File "D:\OCR\Code\PyTorch\faster-rcnn.pytorch-pytorch-1.0\lib\roi_data_layer\roidb.py", line 9, in
from datasets.factory import get_imdb
File "D:\OCR\Code\PyTorch\faster-rcnn.pytorch-pytorch-1.0\lib\datasets\factory.py", line 15, in
from datasets.coco import coco
File "D:\OCR\Code\PyTorch\faster-rcnn.pytorch-pytorch-1.0\lib\datasets\coco.py", line 23, in
from pycocotools.coco import COCO
File "D:\OCR\Code\PyTorch\faster-rcnn.pytorch-pytorch-1.0\data\coco\PythonAPI\pycocotools\coco.py", line 55, in
from . import mask as maskUtils
File "D:\OCR\Code\PyTorch\faster-rcnn.pytorch-pytorch-1.0\data\coco\PythonAPI\pycocotools\mask.py", line 3, in
import pycocotools._mask as _mask
File "init.pxd", line 872, in init pycocotools._mask
ValueError: numpy.ufunc has the wrong size, try recompiling. Expected 192, got 216

@zc-alexfan
Copy link

Just a side note. If which python does not refer to the python version that you use, you might want to modify the MakeFile. In my case, I need to change python to python3.6 in the MakeFile.

@EMCP
Copy link
Contributor

EMCP commented Mar 5, 2019

I tried and failed to get things working...

CoCO API is now at https://github.com/cocodataset/cocoapi

I am seeing the following error even after @JojoFisherman 's suggestions

(pytorch1_py36) myPC:/git/jwyang/faster-rcnn.pytorch$ CUDA_VISIBLE_DEVICES=$GPU_ID python trainval_net.py --dataset pascal_voc --net res101 --bs 1 --nw 1 --lr $LEARNING_RATE --lr_decay_step $DECAY_STEP --cuda
Traceback (most recent call last):
  File "trainval_net.py", line 27, in <module>
    from roi_data_layer.roidb import combined_roidb
  File "/git/jwyang/faster-rcnn.pytorch/lib/roi_data_layer/roidb.py", line 9, in <module>
    from datasets.factory import get_imdb
  File "/git/jwyang/faster-rcnn.pytorch/lib/datasets/factory.py", line 15, in <module>
    from datasets.coco import coco
  File "/git/jwyang/faster-rcnn.pytorch/lib/datasets/coco.py", line 23, in <module>
    from pycocotools.coco import COCO
  File "/git/jwyang/faster-rcnn.pytorch/lib/pycocotools/coco.py", line 60, in <module>
    from . import mask
  File "/git/jwyang/faster-rcnn.pytorch/lib/pycocotools/mask.py", line 3, in <module>
    from . import _mask
ImportError: cannot import name '_mask'

I am using Anaconda with Python 3.6

(pytorch1_py36) myPC:/git/jwyang/faster-rcnn.pytorch$ python --version
Python 3.6.8 :: Anaconda, Inc.

@EMCP
Copy link
Contributor

EMCP commented Mar 5, 2019

progress, I fixed the stale COCO pytools

see: cocodataset/cocoapi#59 (comment)

This was referenced Jun 11, 2019
@marcunzueta
Copy link

Just find out that you have to install the CoCO API.

cd data

git clone https://github.com/pdollar/coco.git cd coco/PythonAPI

make

cd ../../..

Please @jwyang add into the readme for easy install.

@WUT-xiaoming
Copy link

我使用pytorch-1.0和python3.6.7,并在conda下进行构建。构建过程未显示错误。但是,当开始训练trainval.net时,它显示以下错误:

文件“trainval_net.py”,第27行,在
从roi_data_layer.roidb进口combined_roidb
文件“/home/ccyoung/workspace/faster-rcnn.pytorch/lib/roi_data_layer/roidb.py”,9号线,在
从datasets.factory进口get_imdb
文件“ /home/ccyoung/workspace/faster-rcnn.pytorch/lib/datasets/factory.py”,第15行,
来自datasets.coco import coco
文件“ /home/ccyoung/workspace/faster-rcnn.pytorch/ pycocotools.coco中的“ lib / datasets / coco.py”行23,
从中导入COCO
文件“ /home/ccyoung/workspace/faster-rcnn.pytorch/lib/pycocotools/coco.py”,行60

从中导入遮罩文件“ /home/ccyoung/workspace/faster-rcnn.pytorch/lib/pycocotools/mask.py”,第3行

ImportError:无法导入名称“ _mask”

似乎可可API的构建问题

请问您是怎么解决这个问题的

@rongxuanhong
Copy link
Author

rongxuanhong commented Nov 15, 2019 via email

@WUT-xiaoming
Copy link

WUT-xiaoming commented Nov 15, 2019 via email

@rongxuanhong
Copy link
Author

rongxuanhong commented Nov 15, 2019 via email

@WUT-xiaoming
Copy link

WUT-xiaoming commented Nov 15, 2019 via email

@rongxuanhong
Copy link
Author

rongxuanhong commented Nov 15, 2019 via email

@caohe115
Copy link

非常感谢您的回答!!这个COCO的安装目录有要求吗?

------------------ 原始邮件 ------------------ 发件人: "rongxuanHong"<notifications@github.com>; 发送时间: 2019年11月15日(星期五) 下午2:46 收件人: "jwyang/faster-rcnn.pytorch"<faster-rcnn.pytorch@noreply.github.com>; 抄送: "1254305549"<1254305549@qq.com>; "Comment"<comment@noreply.github.com>; 主题: Re: [jwyang/faster-rcnn.pytorch] ImportError: cannot import name '_mask' (#410) https://github.com/cocodataset/cocoapi
------------------&nbsp;原始邮件&nbsp;------------------ 发件人:&nbsp;"WUT-xiaoming"<notifications@github.com&gt;; 发送时间:&nbsp;2019年11月15日(星期五) 中午11:36 收件人:&nbsp;"jwyang/faster-rcnn.pytorch"<faster-rcnn.pytorch@noreply.github.com&gt;; 抄送:&nbsp;"洪荣宣"<389817374@qq.com&gt;;"Author"<author@noreply.github.com&gt;; 主题:&nbsp;Re: [jwyang/faster-rcnn.pytorch] ImportError: cannot import name '_mask' (#410) 请问这个COCO要怎么安装呢? 作者在README中写用python2.7编译ROI等模块,是不是跟这个有关系
------------------&amp;nbsp;原始邮件&amp;nbsp;------------------ 发件人: "rongxuanHong"<notifications@github.com&amp;gt;; 发送时间: 2019年11月15日(星期五) 中午11:33 收件人: "jwyang/faster-rcnn.pytorch"<faster-rcnn.pytorch@noreply.github.com&amp;gt;; 抄送: "1254305549"<1254305549@qq.com&amp;gt;; "Comment"<comment@noreply.github.com&amp;gt;; 主题: Re: [jwyang/faster-rcnn.pytorch] ImportError: cannot import name &amp;#39;_mask&amp;#39; (#410) 你好,我那时是COCO的安装包没安装好。
------------------&amp;amp;nbsp;原始邮件&amp;amp;nbsp;------------------ 发件人:&amp;amp;nbsp;"WUT-xiaoming"<notifications@github.com&amp;amp;gt;; 发送时间:&amp;amp;nbsp;2019年11月15日(星期五) 中午11:31 收件人:&amp;amp;nbsp;"jwyang/faster-rcnn.pytorch"<faster-rcnn.pytorch@noreply.github.com&amp;amp;gt;; 抄送:&amp;amp;nbsp;"洪荣宣"<389817374@qq.com&amp;amp;gt;;"Author"<author@noreply.github.com&amp;amp;gt;; 主题:&amp;amp;nbsp;Re: [jwyang/faster-rcnn.pytorch] ImportError: cannot import name '_mask' (#410) 我使用pytorch-1.0和python3.6.7,并在conda下进行构建。构建过程未显示错误。但是,当开始训练trainval.net时,它显示以下错误: 文件“trainval_net.py”,第27行,在 从roi_data_layer.roidb进口combined_roidb 文件“/home/ccyoung/workspace/faster-rcnn.pytorch/lib/roi_data_layer/roidb.py”,9号线,在 从datasets.factory进口get_imdb 文件“ /home/ccyoung/workspace/faster-rcnn.pytorch/lib/datasets/factory.py”,第15行, 来自datasets.coco import coco 文件“ /home/ccyoung/workspace/faster-rcnn.pytorch/ pycocotools.coco中的“ lib / datasets / coco.py”行23, 从中导入COCO 文件“ /home/ccyoung/workspace/faster-rcnn.pytorch/lib/pycocotools/coco.py”,行60 。 从中导入遮罩文件“ /home/ccyoung/workspace/faster-rcnn.pytorch/lib/pycocotools/mask.py”,第3行 。 ImportError:无法导入名称“ _mask” 似乎可可API的构建问题 请问您是怎么解决这个问题的 — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe. — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe. — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.
https://blog.csdn.net/weixin_42279610/article/details/103086379

非常感谢您的回答!!这个COCO的安装目录有要求吗?

------------------ 原始邮件 ------------------ 发件人: "rongxuanHong"<notifications@github.com>; 发送时间: 2019年11月15日(星期五) 下午2:46 收件人: "jwyang/faster-rcnn.pytorch"<faster-rcnn.pytorch@noreply.github.com>; 抄送: "1254305549"<1254305549@qq.com>; "Comment"<comment@noreply.github.com>; 主题: Re: [jwyang/faster-rcnn.pytorch] ImportError: cannot import name '_mask' (#410) https://github.com/cocodataset/cocoapi
------------------&nbsp;原始邮件&nbsp;------------------ 发件人:&nbsp;"WUT-xiaoming"<notifications@github.com&gt;; 发送时间:&nbsp;2019年11月15日(星期五) 中午11:36 收件人:&nbsp;"jwyang/faster-rcnn.pytorch"<faster-rcnn.pytorch@noreply.github.com&gt;; 抄送:&nbsp;"洪荣宣"<389817374@qq.com&gt;;"Author"<author@noreply.github.com&gt;; 主题:&nbsp;Re: [jwyang/faster-rcnn.pytorch] ImportError: cannot import name '_mask' (#410) 请问这个COCO要怎么安装呢? 作者在README中写用python2.7编译ROI等模块,是不是跟这个有关系
------------------&amp;nbsp;原始邮件&amp;nbsp;------------------ 发件人: "rongxuanHong"<notifications@github.com&amp;gt;; 发送时间: 2019年11月15日(星期五) 中午11:33 收件人: "jwyang/faster-rcnn.pytorch"<faster-rcnn.pytorch@noreply.github.com&amp;gt;; 抄送: "1254305549"<1254305549@qq.com&amp;gt;; "Comment"<comment@noreply.github.com&amp;gt;; 主题: Re: [jwyang/faster-rcnn.pytorch] ImportError: cannot import name &amp;#39;_mask&amp;#39; (#410) 你好,我那时是COCO的安装包没安装好。
------------------&amp;amp;nbsp;原始邮件&amp;amp;nbsp;------------------ 发件人:&amp;amp;nbsp;"WUT-xiaoming"<notifications@github.com&amp;amp;gt;; 发送时间:&amp;amp;nbsp;2019年11月15日(星期五) 中午11:31 收件人:&amp;amp;nbsp;"jwyang/faster-rcnn.pytorch"<faster-rcnn.pytorch@noreply.github.com&amp;amp;gt;; 抄送:&amp;amp;nbsp;"洪荣宣"<389817374@qq.com&amp;amp;gt;;"Author"<author@noreply.github.com&amp;amp;gt;; 主题:&amp;amp;nbsp;Re: [jwyang/faster-rcnn.pytorch] ImportError: cannot import name '_mask' (#410) 我使用pytorch-1.0和python3.6.7,并在conda下进行构建。构建过程未显示错误。但是,当开始训练trainval.net时,它显示以下错误: 文件“trainval_net.py”,第27行,在 从roi_data_layer.roidb进口combined_roidb 文件“/home/ccyoung/workspace/faster-rcnn.pytorch/lib/roi_data_layer/roidb.py”,9号线,在 从datasets.factory进口get_imdb 文件“ /home/ccyoung/workspace/faster-rcnn.pytorch/lib/datasets/factory.py”,第15行, 来自datasets.coco import coco 文件“ /home/ccyoung/workspace/faster-rcnn.pytorch/ pycocotools.coco中的“ lib / datasets / coco.py”行23, 从中导入COCO 文件“ /home/ccyoung/workspace/faster-rcnn.pytorch/lib/pycocotools/coco.py”,行60 。 从中导入遮罩文件“ /home/ccyoung/workspace/faster-rcnn.pytorch/lib/pycocotools/mask.py”,第3行 。 ImportError:无法导入名称“ _mask” 似乎可可API的构建问题 请问您是怎么解决这个问题的 — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe. — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe. — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.
没有要求,在随意一个空的目录下,下载最新的并编译就好。你可以参考下我的,我刚解决这个问题,运行成功fasterrcnn https://blog.csdn.net/weixin_42279610/article/details/103086379

@n0obcoder
Copy link

Just find out that you have to install the CoCO API.

cd data

git clone https://github.com/pdollar/coco.git cd coco/PythonAPI

make

cd ../../..

I am using Windows 10, how do i solve the problem ( from . import _mask
ImportError: cannot import name '_mask' from 'pycocotools' ())

Please help.

1 similar comment
@n0obcoder
Copy link

Just find out that you have to install the CoCO API.

cd data

git clone https://github.com/pdollar/coco.git cd coco/PythonAPI

make

cd ../../..

I am using Windows 10, how do i solve the problem ( from . import _mask
ImportError: cannot import name '_mask' from 'pycocotools' ())

Please help.

@Flashkong
Copy link

Just find out that you have to install the CoCO API.

cd data

git clone https://github.com/pdollar/coco.git cd coco/PythonAPI

make

cd ../../..

it works. thank you!!!

@wwl33
Copy link

wwl33 commented Mar 25, 2020

Just find out that you have to install the CoCO API.

cd data

git clone https://github.com/pdollar/coco.git cd coco/PythonAPI

make

cd ../../..

I am sorry,i cannot understand "make" and"cd../../",Can you explain it in more detail?

@JiafengLiao
Copy link

I tried pip install pycocotools. And it worked

@JiafengLiao
Copy link

JiafengLiao commented Apr 15, 2020

make sure the branch is pytorch-1.0
and
cd lib && python setup.py build develop
then retry?

Having the same problem as well. I am using the pytorch-1.0 branch and has run "python setup.py build develop".

Same issue here and I tried "pip install pycocotools" or "conda install". It worked

@aDecisionTree
Copy link

make sure the branch is pytorch-1.0
and
cd lib && python setup.py build develop
then retry?

Having the same problem as well. I am using the pytorch-1.0 branch and has run "python setup.py build develop".

Same issue here and I tried "pip install pycocotools" or "conda install". It worked

thank you , it worked well!

@decoli
Copy link

decoli commented May 10, 2020

Just find out that you have to install the CoCO API.

cd data

git clone https://github.com/pdollar/coco.git cd coco/PythonAPI

make

cd ../../..

When I tried to make, got

error: command 'D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\bin\HostX86\x64\cl.exe' failed with exit status 2
make: *** [Makefile:3: all] Error 1

Dose anyone know what this means ?

@TheLostIn
Copy link

Just find out that you have to install the CoCO API.
cd data
git clone https://github.com/pdollar/coco.git cd coco/PythonAPI
make
cd ../../..

When I tried to make, got

error: command 'D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\bin\HostX86\x64\cl.exe' failed with exit status 2
make: *** [Makefile:3: all] Error 1

Dose anyone know what this means ?

After generating pycocotools directory('xxx/xxx/data/coco/PythonAPI/pycocotools'), replace the original pycocotools with this new one. The new pycocotools should include file.so like '_mask.cpython-36m-x86_64-linux-gnu.so'.

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