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

inference No module named 'detectron2' #19

Open
GISScience opened this issue Jun 12, 2024 · 4 comments
Open

inference No module named 'detectron2' #19

GISScience opened this issue Jun 12, 2024 · 4 comments

Comments

@GISScience
Copy link

GISScience commented Jun 12, 2024

i am executing inference with your checkpoint --- but i am getting error

Google Colab Commands
%cd /content/drive/MyDrive/Colab_Notebooks/htcr_sam/sam_road/sam
!python /content/drive/MyDrive/Colab_Notebooks/htcr_sam/sam_road/inferencer.py --config /content/drive/MyDrive/Colab_Notebooks/htcr_sam/sam_road/config/toponet_vitb_256.yaml --output_dir /content/drive/MyDrive/Colab_Notebooks/htcr_sam/sam_road/output/

Error
/content/drive/MyDrive/Colab_Notebooks/htcr_sam/sam_road/sam
Traceback (most recent call last):
File "/content/drive/MyDrive/Colab_Notebooks/htcr_sam/sam_road/inferencer.py", line 10, in
from model import SAMRoad
File "/content/drive/MyDrive/Colab_Notebooks/htcr_sam/sam_road/model.py", line 24, in
import vitdet
File "/content/drive/MyDrive/Colab_Notebooks/htcr_sam/sam_road/vitdet.py", line 11, in
from detectron2.modeling import ViT
ModuleNotFoundError: No module named 'detectron2'

Then i removed import vitdet

now i am getting this error with checkpoint shared by you.

/content/drive/MyDrive/Colab_Notebooks/htcr_sam/sam_road/sam
Traceback (most recent call last):
File "/content/drive/MyDrive/Colab_Notebooks/htcr_sam/sam_road/inferencer.py", line 247, in
net = SAMRoad(config)
File "/content/drive/MyDrive/Colab_Notebooks/htcr_sam/sam_road/model.py", line 361, in init
new_state_dict = self.resize_sam_pos_embed(ckpt_state_dict, image_size, vit_patch_size, encoder_global_attn_indexes)
File "/content/drive/MyDrive/Colab_Notebooks/htcr_sam/sam_road/model.py", line 383, in resize_sam_pos_embed
pos_embed = new_state_dict['image_encoder.pos_embed']
KeyError: 'image_encoder.pos_embed'

Config
SAM_VERSION: 'vit_b'
SAM_CKPT_PATH: '/content/drive/MyDrive/Colab_Notebooks/htcr_sam/sam_road/sam_ckpts/spacenet_vitb_256_e10.ckpt'
PATCH_SIZE: 256
BATCH_SIZE: 64
DATA_WORKER_NUM: 1

where i am doing mistake .
please look at my shared colab here.

https://drive.google.com/file/d/1IxdmtQ8VIAJ9kENeb5HJbTEloNzITncF/view?usp=sharing

is it true that minimum we need 30 gb RAM to use SAM_Road

@htcr
Copy link
Owner

htcr commented Jun 19, 2024

Were you able to figure this out? I'm on travel right now but I can help take a look after getting back to my workstation.

@liweigis99
Copy link

@GISScience detectron2 needs to be installed following https://detectron2.readthedocs.io/tutorials/install.html

@GISScience
Copy link
Author

Even after installing detectron2 , i am geeeting this error.. please help..
/content/drive/MyDrive/htcr_sam_road/sam_road
Traceback (most recent call last):
File "/content/drive/MyDrive/htcr_sam_road/sam_road/inferencer.py", line 247, in
net = SAMRoad(config)
File "/content/drive/MyDrive/htcr_sam_road/sam_road/model.py", line 363, in init
new_state_dict = self.resize_sam_pos_embed(ckpt_state_dict, image_size, vit_patch_size, encoder_global_attn_indexes)
File "/content/drive/MyDrive/htcr_sam_road/sam_road/model.py", line 385, in resize_sam_pos_embed
pos_embed = new_state_dict['image_encoder.pos_embed']
KeyError: 'image_encoder.pos_embed'

@htcr
Copy link
Owner

htcr commented Aug 8, 2024

Been quite busy recently - re your questions @GISScience:

  1. detectron2 is only used for an ablation experiment which is not very important. I have removed it from the latest codebase. You should no longer see this problem.

  2. As stated in README, inference should use the same config as training. so you should be using toponet_vitb_256_spacenet.yaml for spacenet_vitb_256_e10.ckpt. I ran python inferencer.py --config=config/toponet_vitb_256_spacenet.yaml --checkpoint=/home/congrui/Desktop/sam_road_repro/spacenet_vitb_256_e10.ckpt locally and did not see the issue you encountered.

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

3 participants