Labelme、LabelImg的安装和使用

来源:互联网 发布:电视剧直播软件 编辑:程序博客网 时间:2024/05/17 08:30

#
LabelMe

标注数据集
https://github.com/wkentaro/labelme

笔者:macox
终端代码安装:

brew install qt qt4 || brew install pyqt # qt4 is deprecated(显示报错找不到qt4就直接pyqt4)pip install labelme

Run** labelme –help **for detail.

几种报错:

1、第一种

from matplotlib.backends import _macosxRuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.

解决方法:
vim ~/.matplotlib/matplotlibrc
然后输入以下内容:
backend: TkAgg
注:
$ vi myfile
进入vi之后,是处于「命令行模式」,您要切换到「插入模式」才能够输入文字
i: 「命令行模式」→「插入模式」
ESC: 「插入模式」→「命令行模式」

2)退出
在「命令行模式」下,按一下「:」冒号键进入「Last line mode」,例如
w filename (输入 「w filename」将文章以指定的文件名filename保存)
wq (输入「wq」,存盘并退出vi)
q! (输入q!, 不存盘强制退出vi)

2、第二种

Traceback (most recent call last):File "/usr/local/bin/labelme", line 7, in <module>from labelme.app import mainFile "/Library/Python/2.7/site-packages/labelme/app.py", line 37, in <module>from PyQt4.QtGui import *ImportError: No module named PyQt4.QtGui

解决方法:
**brew uninstall PyQt5
labelme –help**
报错:ImportError: cannot import name QtCore
* brew install PyQt5 *

如果上面的这个方法后还不行就将下面的代码加入~/.bash_profile中:
export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH

3、成功

Run** labelme –help **for detail.

Bad key "ckend" on line 1 in/Users/muaxiu/.matplotlib/matplotlibrc.You probably need to get an updated matplotlibrc file fromhttp://github.com/matplotlib/matplotlib/blob/master/matplotlibrc.templateor from the matplotlib source distributionusage: labelme [-h] [-O OUTPUT] [filename]positional arguments:filename image or label filenameoptional arguments:-h, --help show this help message and exit-O OUTPUT, --output OUTPUToutput label name

操作:

打开labelme可视化窗口
labelme # Open GUI
用labelme打开指定文件
labelme static/apc2016_obj3.jpg # Specify file
用labelme打开指定文件退出后保存为XX.json文件
labelme static/apc2016_obj3.jpg -O static/apc2016_obj3.json # Close window after the save

快速查看json文件,可以使用实用程序脚本:
labelme_draw_json static/apc2016_obj3.json
**Convert to Dataset
To convert the json to set of image and label, you can run following:**
labelme_json_to_dataset static/apc2016_obj3.json
即可得到一个文件夹,有四个文件,*.png,info.yaml,label.png, label_viz.png。
其中label.png即是我们要的label_data.
看起来是全黑的,然而读到像素中,是可以看到对相同类别的文件进行标注了。

笔者还安装了labelImg,综合考量选择了Labelme,以下是LabelImg的安装过程

LabelImg

原作者github:https://github.com/tzutalin/labelImg#macos
安装参考:http://blog.csdn.net/roguesir/article/details/73647695
macOS

Python 2 + Qt4

brew install qt qt4
brew install libxml2
make qt4py2
python labelImg.py
python labelImg.py [IMAGE_PATH] [PRE-DEFINED CLASS FILE]

笔者电脑/装载软件:
Mac os
python2.7.13

1.通过Homebrew安装pyqt

brew install cartr/qt4/pyqt

配置环境变量
whichpython/usr/bin/python which brew
/usr/local/bin/brew
PyQt4是通过brew安装的,明显这两个路径不一致,导致问题,解决如下:
cd/usr/local/lib/python2.7/sitepackages ls
open /.bashprofile.bashprofileexportPYTHONPATH=/usr/local/lib/python2.7/sitepackages:PYTHONPATH
然后关闭terminal,重新开启,进入python中import:

这样,PyQt4就装好了。

2.安装lxml

sudo pip install lxml

3.安装labelImg

sudo pip install labelImg
文件夹内:shift+command+G
前往/usr/local/bin/labelImg
打开labelImg

4.遇到的问题

from PyQt4.QtGui import *
ImportError: No module named PyQt4.QtGui

cd /usr/local/lib/python2.7/site-packages
ls
既有PyQt4也有PyQt5
pip uninstall 所有刚刚装的重新装一遍
**解决:**Pyqt5并不兼容pyqt4,我觉得你需要把pyqt5改成pyqt4,brew uninstall qt5,先把pyqt5卸掉,然后在装pyqt4试试

5.使用步骤

1.利用上述方式,创建启动。
2.击菜单上Change default saved annotation folder
3.点击’Open Dir’
4.点击 ‘Create RectBox’
5.点击左键,选择一个区域来用矩形框注释
6.用右键,拖拽矩形框,复制或移动

这个注释将被存储到你指定的文件夹。

Ctrl + u:Load all of the images from a directory
Ctrl + r:Change the default annotation target dir
Ctrl + s:Save
Ctrl + d:Copy the current label and rect box
Space:Flag the current image as verified
w:Create a rect box
d:Next image
a:Previous image
del:Delete the selected rect box
Ctrl++:Zoom in
Ctrl–:Zoom out
↑→↓←:Keyboard arrows to move selected rect box

⇒ python
Python 2.7.10 (default, Feb 7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.

from PyQt4 import QtCore, QtGui ,QtNetwork
quit()

原创粉丝点击