darolt / mask_rcnn

Pytorch 1.0 implementation of Mask RCNN
Other
33 stars 7 forks source link

how to solve 'ImportError: cannot import name 'crop_and_resize'' #4

Open q1nwu opened 5 years ago

densechen commented 5 years ago

Do you solve this problem? I have met the same question with you .

q1nwu commented 5 years ago

Not yet.

densechen commented 5 years ago

I have solved this problem. You should mv the build file to corresponding place in models folder, and everything goes well.

nguyen14ck commented 5 years ago

@LittleLampChen Could you explain how to make it works? Which version of Python and Pytorch do you use? Mine are: CentOS 7 Python 3.6.9 Pytorch 1.2 Cuda 9.2

I can run tests in ./test/nms_test.py and ./samples/image_resize_test.py. However, when I run with:

python ./samples/nuclei.py train

There are so many errors with float type like:

TypeError: 'float' object is not subscriptable
float type is not iterable
imgaug not support float64 dtype
   File "samples/nuclei.py", line 90, in <module>
    train(model, dataset_train, dataset_val)
  File "/home/mask_rcnn_pytorch-1.0/mrcnn/actions/train.py", line 28, in train
    model.fit(dataset_train, dataset_val, Config.TRAINING.LEARNING.RATE, Config.TRAINING.NUM_EPOCHS, 'heads', augmentation=augmentation)
  File "/home/mask_rcnn_pytorch-1.0/mrcnn/models/model.py", line 343, in fit
    train_losses = self._train_epoch(train_generator, optimizer)
  File "/home/mask_rcnn_pytorch-1.0/mrcnn/models/model.py", line 367, in _train_epoch
    for step, inputs in enumerate(datagenerator):
  File "/home/anaconda3/envs/pycon/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 819, in __next__
    return self._process_data(data)
  File "/home/anaconda3/envs/pycon/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 846, in _process_data
    data.reraise()
  File "/home/anaconda3/envs/pycon/lib/python3.6/site-packages/torch/_utils.py", line 369, in reraise
    raise self.exc_type(msg)
TypeError: Caught TypeError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/home/anaconda3/envs/pycon/lib/python3.6/site-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
    data = fetcher.fetch(index)
  File "/home/anaconda3/envs/pycon/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/home/anaconda3/envs/pycon/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/home/mask_rcnn_pytorch-1.0/mrcnn/data/data_generator.py", line 259, in __getitem__
    use_mini_mask=Config.MINI_MASK.USE)
  File "/home/mask_rcnn_pytorch-1.0/mrcnn/data/data_generator.py", line 48, in load_image_gt
    image_metas.padding, image_metas.crop)
  File "/home/mask_rcnn_pytorch-1.0/mrcnn/utils/utils.py", line 414, in resize_mask
    mask = scipy.ndimage.zoom(mask, zoom=[scale[0], scale[1], 1], order=0)
TypeError: 'float' object is not subscriptable
densechen commented 5 years ago

I am using Ubuntu 16.04 to run this code with python 3.6, pytorch 1.2And I think the wrong didn't come from crop_size.  Maybe you can repair this problem by changing the dtype into correct one.

------------------ Original ------------------ From: "nguyen14ck"<notifications@github.com>; Date: 2019年10月11日(星期五) 下午2:44 To: "darolt/mask_rcnn"<mask_rcnn@noreply.github.com>; Cc: "densechen"<1428636341@qq.com>; "Mention"<mention@noreply.github.com>; Subject: Re: [darolt/mask_rcnn] how to solve 'ImportError: cannot import name 'crop_and_resize'' (#4)

@LittleLampChen Could you explain how to make it works? Which version of Python and Pytorch do you use? Mine are: CentOS 7 Python 3.6.9 Pytorch 1.2 Cuda 9.2

I can run tests in ./test/nms_test.py and ./samples/image_resize_test.py. However, when I run with: python ./samples/nuclei.py train
There are so many errors with float type like: TypeError: 'float' object is not subscriptable float type is not iterable imgaug not support float64 dtype File "samples/nuclei.py", line 90, in <module> train(model, dataset_train, dataset_val) File "/home/mask_rcnn_pytorch-1.0/mrcnn/actions/train.py", line 28, in train model.fit(dataset_train, dataset_val, Config.TRAINING.LEARNING.RATE, Config.TRAINING.NUM_EPOCHS, 'heads', augmentation=augmentation) File "/home/mask_rcnn_pytorch-1.0/mrcnn/models/model.py", line 343, in fit train_losses = self._train_epoch(train_generator, optimizer) File "/home/mask_rcnn_pytorch-1.0/mrcnn/models/model.py", line 367, in _train_epoch for step, inputs in enumerate(datagenerator): File "/home/anaconda3/envs/pycon/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 819, in next return self._process_data(data) File "/home/anaconda3/envs/pycon/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 846, in _process_data data.reraise() File "/home/anaconda3/envs/pycon/lib/python3.6/site-packages/torch/_utils.py", line 369, in reraise raise self.exc_type(msg) TypeError: Caught TypeError in DataLoader worker process 0. Original Traceback (most recent call last): File "/home/anaconda3/envs/pycon/lib/python3.6/site-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop data = fetcher.fetch(index) File "/home/anaconda3/envs/pycon/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "/home/anaconda3/envs/pycon/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp> data = [self.dataset[idx] for idx in possibly_batched_index] File "/home/mask_rcnn_pytorch-1.0/mrcnn/data/data_generator.py", line 259, in getitem use_mini_mask=Config.MINI_MASK.USE) File "/home/mask_rcnn_pytorch-1.0/mrcnn/data/data_generator.py", line 48, in load_image_gt image_metas.padding, image_metas.crop) File "/home/mask_rcnn_pytorch-1.0/mrcnn/utils/utils.py", line 414, in resize_mask mask = scipy.ndimage.zoom(mask, zoom=[scale[0], scale[1], 1], order=0) TypeError: 'float' object is not subscriptable
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

nguyen14ck commented 5 years ago

@LittleLampChen I did not change the code. Not understand why it has problems with dtype. Coud you give me an example of the command you used to run file "nuclei.py" successfully? And where could I download a pre-trained model to test it? Many thanks

shanniruo commented 4 years ago

@densechen where is the build file?

HosseinHassanzadeh commented 3 years ago

@LittleLampChen I did not change the code. Not understand why it has problems with dtype. Coud you give me an example of the command you used to run file "nuclei.py" successfully? And where could I download a pre-trained model to test it? Many thanks

Did you fix it? I have the same problem

densechen commented 3 years ago

Sorry, I have forgotten the details. But, I think that you should pay attention to this sentence in README.md:

for installation instructions, just *export mrcnn directory to PYTHONPATH* and run: python setup.py install

@nguyen14ck @shanniruo @HosseinHassanzadeh