SysCV/sam-hq

ImportError: cannot import name 'FrozenBatchNorm2d' from 'torchvision.ops'

Guangpengwgp1202 opened this issue · 2 comments

Hello, I followed the readme environment example in windows11conda and the following error occurred.

(sam_hq) C:\Users\Guangpeng\Desktop\model_test\sam-hq>python
Python 3.8.18 | packaged by conda-forge | (default, Oct 10 2023, 15:37:54) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

from segment_anything import SamPredictor, sam_model_registry
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\Guangpeng\Desktop\model_test\sam-hq\segment_anything_init_.py", line 7, in
from .build_sam import (
File "C:\Users\Guangpeng\Desktop\model_test\sam-hq\segment_anything\build_sam.py", line 11, in
from .modeling import ImageEncoderViT, MaskDecoderHQ, PromptEncoder, Sam, TwoWayTransformer, TinyViT
File "C:\Users\Guangpeng\Desktop\model_test\sam-hq\segment_anything\modeling_init_.py", line 13, in
from .tiny_vit_sam import TinyViT
File "C:\Users\Guangpeng\Desktop\model_test\sam-hq\segment_anything\modeling\tiny_vit_sam.py", line 15, in
from timm.models.layers import DropPath as TimmDropPath,
File "C:\Users\Guangpeng\anaconda3\envs\sam_hq\lib\site-packages\timm_init_.py", line 2, in
from .layers import is_scriptable, is_exportable, set_scriptable, set_exportable
File "C:\Users\Guangpeng\anaconda3\envs\sam_hq\lib\site-packages\timm\layers_init_.py", line 7, in
from .classifier import ClassifierHead, create_classifier, NormMlpClassifierHead
File "C:\Users\Guangpeng\anaconda3\envs\sam_hq\lib\site-packages\timm\layers\classifier.py", line 15, in
from .create_norm import get_norm_layer
File "C:\Users\Guangpeng\anaconda3\envs\sam_hq\lib\site-packages\timm\layers\create_norm.py", line 14, in
from torchvision.ops import FrozenBatchNorm2d
ImportError: cannot import name 'FrozenBatchNorm2d' from 'torchvision.ops' (C:\Users\Guangpeng\anaconda3\envs\sam_hq\lib\site-packages\torchvision\ops_init_.py)

Looking forward to your reply and thank you for contributing such an excellent project

I have solved the problem, thanks again for the excellent project

‘’conda update pytorch torchvision -c pytorch‘’