__main__.py:AttributeError: module 'labelme.utils' has no attribute 'draw_label'

實現labelme批量json_to_dataset方法中

https://blog.csdn.net/yql_617540298/article/details/81110685#comments

以及後續針對其中的問題:

AttributeError: module 'labelme.utils' has no attribute 'draw_label'

https://blog.csdn.net/yql_617540298/article/details/104182777#comments

我看到有朋友反饋,依舊出現如下問題:

File "C:\Users\zhang\Anaconda3\Scripts\labelme_json_to_dataset.exe\__main__.py", line 9, in <module> File "c:\users\zhang\anaconda3\lib\site-packages\labelme\cli\json_to_dataset.py", line 66, in main lbl_viz = utils.draw_label(lbl, img, captions) AttributeError: module 'labelme.utils' has no attribute 'draw_label' 

根據錯誤:

__main__.py文件中報錯,而不是單純的沒有draw_label()方法。

參考鏈接:http://www.imooc.com/wenda/detail/581549

解釋了什麼是__main__.py文件。

所以該錯誤不是後續代碼中出現的問題,有可能安裝不同的版本,代碼也是不同的,所以,檢查一下labelme的版本號,

在cmd中,輸入:

>>python
>>import labelme as lb
>>lb.__version__
>>

我安裝的是3.3.1版本。 

我電腦上的Python是3.6.2版本。
所以如果不同版本,找不到draw_label()也很正常。

不用管之前的博客的代碼,直接在安裝好的labelme的代碼裏進行更改:

將labelme單張圖片處理改爲批量圖片處理得基本原理就是增加批量的操作,那麼直接在安裝好的labelme自動生成的代碼中更改就可以,其他在安裝labelme後自動生成的代碼都不要更改:

在json_to_dataset.py文件中,增加如下代碼:(之前博客有寫)

count = os.listdir(json_file) 
    for i in range(0, len(count)):
        path = os.path.join(json_file, count[i])
        if os.path.isfile(path):
            data = json.load(open(path))

然後將處理單張圖片的代碼全部寫在for循環內即可。

或者,直接安裝3.3.1版本的labelme也可以。

安裝:https://blog.csdn.net/yql_617540298/article/details/81782827

希望可以幫助大家解決這個問題。

發佈了111 篇原創文章 · 獲贊 110 · 訪問量 14萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章