介绍
这段时间太忙了,一直没有抽出时间写博客,说好一个月一篇的,还是拉下了,争取这个月再写一篇。偶然间看到SAM已经集成进labelme中,想试着用用看,是不是传说中的分割一切。谁知道以前python3.8版本的时候还能用,然后我装了最新版本labelme后直接寄了,淦!!!后来查了下,终于知道原因了
___哈哈哈小小记录下 damn!
具体报错信息
报错如下:
(py38) C:\Users\86182>labelme
Traceback (most recent call last):
File "D:\miniconda3\envs\py38\lib\runpy.py", line 192, in _run_module_as_main
return _run_code(code, main_globals, None,
File "D:\miniconda3\envs\py38\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "D:\miniconda3\envs\py38\Scripts\labelme.exe\__main__.py", line 4, in <module>
from labelme.__main__ import main
File "D:\miniconda3\envs\py38\lib\site-packages\labelme\__main__.py", line 14, in <module>
from labelme.app import MainWindow
File "D:\miniconda3\envs\py38\lib\site-packages\labelme\app.py", line 22, in <module>
from labelme import ai
File "D:\miniconda3\envs\py38\lib\site-packages\labelme\ai\__init__.py", line 5, in <module>
from .text_to_annotation import get_rectangles_from_texts # NOQA: F401
File "D:\miniconda3\envs\py38\lib\site-packages\labelme\ai\text_to_annotation.py", line 10, in <module>
model: str, image: np.ndarray, texts: list[str]
TypeError: 'type' object is not subscriptable
截图如下:
源码修改和报错原因
直接说原因,不墨迹:Python 3.8 及更早版本中的 list
类型不支持使用 list[str]
这样的下标类型注解,这种语法只有在 Python 3.9 或更高版本中才被支持。所以,list[str]
在 Python 3.8 环境中会引发 TypeError: 'type' object is not subscriptable
错误
下面是我的python版本
验证:
我们验证是不是这个原因,可以看到跟上面报错一模一样
我们将它改一下,改成下面这种方式,可以看到代码跑起来了兄弟们!按照这个思路,我们直接改源码
源码修改
从报错中我们知道报错文件他是在"D:\miniconda3\envs\py38\Lib\site-packages\labelme\ai\text_to_annotation.py"中的,具体文件位置每个人都不同,但一定是text_to_annotation.py文件
跑起来了!!!!
完结!!!!(派蒙真可爱!)