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

Replace mmdet v2 for v3 #893

Merged
merged 7 commits into from
Jun 13, 2023
Merged

Replace mmdet v2 for v3 #893

merged 7 commits into from
Jun 13, 2023

Conversation

i-aki-y
Copy link
Contributor

@i-aki-y i-aki-y commented Jun 7, 2023

This PR tries to replace the code of mmdet v2 for v3 instead of adding a new mmdet3(see #864).

@i-aki-y i-aki-y mentioned this pull request Jun 7, 2023
@i-aki-y
Copy link
Contributor Author

i-aki-y commented Jun 9, 2023

Fixed cli test command.
Note, I moved mmdet config files from mmdet_{model} to mmdet/{model} to fit the original mmdet config structures.

@i-aki-y
Copy link
Contributor Author

i-aki-y commented Jun 12, 2023

I could not reproduce the same error as CI in my local environment.
Hmm, something must be wrong, but I have no idea what the cause of the error.

.github/workflows/ci.yml Outdated Show resolved Hide resolved
Copy link
Collaborator

@fcakyon fcakyon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i-aki-y and others added 2 commits June 13, 2023 19:27
Co-authored-by: fatih <34196005+fcakyon@users.noreply.github.com>
@fcakyon fcakyon merged commit deaed7a into obss:main Jun 13, 2023
@i-aki-y
Copy link
Contributor Author

i-aki-y commented Jun 13, 2023

@fcakyon Thank you for your support!

@fcakyon
Copy link
Collaborator

fcakyon commented Jun 14, 2023

Thank for all your efforts!

@martinurbieta
Copy link

This PR tries to replace the code of mmdet v2 for v3 instead of adding a new mmdet3(see #864).

I have tried the demo and I get the following error message when running

detection_model = AutoDetectionModel.from_pretrained(
    model_type='mmdet',
    model_path=model_path,
    config_path=config_path,
    confidence_threshold=0.4,
    image_size=640,
    device="cpu", # or 'cuda:0'
)
Loads checkpoint by local backend from path: /content/checkpoints/cascade_mask_rcnn_r50_fpn_1x_coco_20200203-9d4dcb24.pth
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
[/usr/local/lib/python3.10/dist-packages/mmengine/config/config.py](https://localhost:8080/#) in __getattr__(self, name)
    105         try:
--> 106             value = super().__getattr__(name)
    107             if isinstance(value, (LazyAttr, LazyObject)) and not self.lazy:

8 frames
KeyError: 'data'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
[/usr/local/lib/python3.10/dist-packages/mmengine/config/config.py](https://localhost:8080/#) in __getattr__(self, name)
    108                 value = value.build()
    109         except KeyError:
--> 110             raise AttributeError(f"'{self.__class__.__name__}' object has no "
    111                                  f"attribute '{name}'")
    112         except Exception as e:

AttributeError: 'ConfigDict' object has no attribute 'data'

@i-aki-y
Copy link
Contributor Author

i-aki-y commented Aug 12, 2023

@martinurbieta, what versions did you use?

You can check them from the output of the following command:

pip list | grep -e mmdet -e mmengine -e mmcv

@martinurbieta
Copy link

@i-aki-y
The versions are:

mmcv                             2.0.1
mmdet                            3.1.0
mmengine                         0.8.4

Martin

@i-aki-y
Copy link
Contributor Author

i-aki-y commented Aug 19, 2023

@martinurbieta Thanks, mmdet version looks OK.

Did you install sahi by using pip sahi?
It seems that the current pip package does not include the latest updates (mmdet3 support).
I hope installing sahi from the main branch will fix the error.

ex.

git clone https://github.com/obss/sahi
cd sahi
pip install -e . -U

@martinurbieta
Copy link

Thanks for your contribution @i-aki-y .

When excecuting

# download cascade mask rcnn model&config
model_path = 'models/cascade_mask_rcnn.pth'
download_mmdet_cascade_mask_rcnn_model(model_path)
config_path = download_mmdet_config(model_name="cascade_rcnn", config_file_name="cascade-mask-rcnn_r50_fpn_1x_coco.py",)

returns

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
[<ipython-input-6-ba6e5ebfa553>](https://localhost:8080/#) in <cell line: 2>()
      1 # config_path = download_mmdet_config(model_name="cascade_rcnn", config_file_name="cascade-mask-rcnn_r50_fpn_1x_coco.py",)
----> 2 config_path = download_mmdet_config(model_name="cascade_rcnn", config_file_name="cascade-mask-rcnn_r50_fpn_1x_coco.py",)

[/usr/local/lib/python3.10/dist-packages/sahi/utils/mmdet.py](https://localhost:8080/#) in download_mmdet_config(model_name, config_file_name, verbose)
    179 
    180         # dump final config as single file
--> 181         from mmcv import Config
    182 
    183         config = Config.fromfile(main_config_path)

ImportError: cannot import name 'Config' from 'mmcv' (/usr/local/lib/python3.10/dist-packages/mmcv/__init__.py)

---------------------------------------------------------------------------

I suppose that from mmcv import Config must be changed for from mmengine.config import Config

@i-aki-y
Copy link
Contributor Author

i-aki-y commented Aug 22, 2023

@martinurbieta Yes, but the code has been fixed in the main branch.

See

sahi/sahi/utils/mmdet.py

Lines 177 to 178 in deaed7a

# dump final config as single file
from mmengine import Config

So, I think you are not using the latest main branch.

@martinurbieta
Copy link

@i-aki-y , thanks again for your feedback.

I had to install SAHI as

!pip install git+https://github.com/obss/sahi.git

and worked perfectly.

Instead the first suggestion
I think that when installing, as you mention, wasn't the latest branch.

Regards.

@W-hary
Copy link

W-hary commented Oct 23, 2023

This PR tries to replace the code of mmdet v2 for v3 instead of adding a new mmdet3(see #864).

I have tried the demo and I get the following error message when running

detection_model = AutoDetectionModel.from_pretrained(
    model_type='mmdet',
    model_path=model_path,
    config_path=config_path,
    confidence_threshold=0.4,
    image_size=640,
    device="cpu", # or 'cuda:0'
)
Loads checkpoint by local backend from path: /content/checkpoints/cascade_mask_rcnn_r50_fpn_1x_coco_20200203-9d4dcb24.pth
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
[/usr/local/lib/python3.10/dist-packages/mmengine/config/config.py](https://localhost:8080/#) in __getattr__(self, name)
    105         try:
--> 106             value = super().__getattr__(name)
    107             if isinstance(value, (LazyAttr, LazyObject)) and not self.lazy:

8 frames
KeyError: 'data'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
[/usr/local/lib/python3.10/dist-packages/mmengine/config/config.py](https://localhost:8080/#) in __getattr__(self, name)
    108                 value = value.build()
    109         except KeyError:
--> 110             raise AttributeError(f"'{self.__class__.__name__}' object has no "
    111                                  f"attribute '{name}'")
    112         except Exception as e:

AttributeError: 'ConfigDict' object has no attribute 'data'

I have encountered the same problem. How can I solve it

@i-aki-y
Copy link
Contributor Author

i-aki-y commented Oct 24, 2023

Hi, @W-hary Did you try this?

I had to install SAHI as

!pip install git+https://github.com/obss/sahi.git

and worked perfectly.

@fcakyon
Copy link
Collaborator

fcakyon commented Nov 5, 2023

@i-aki-y @W-hary @martinurbieta please update your sahi to 0.11.15 and all issues will be gone 👍

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

Successfully merging this pull request may close these issues.

4 participants