diff --git a/labelme/app.py b/labelme/app.py index 30df89336d46b0ec285006360fc217d7911f6ba7..ef500561f3047587955f2791d2a3115bb984752b 100644 --- a/labelme/app.py +++ b/labelme/app.py @@ -1,9 +1,6 @@ -import argparse -import codecs import functools import os.path import re -import sys import warnings import webbrowser @@ -13,8 +10,6 @@ from qtpy import QtGui from qtpy import QtWidgets from labelme import __appname__ -from labelme import __version__ -from labelme import logger from labelme import QT5 from labelme.config import get_config @@ -48,9 +43,6 @@ from labelme.widgets import ZoomWidget # - Zoom is too "steppy". -# Utility functions and classes. - - class WindowMixin(object): def menu(self, title, actions=None): menu = self.menuBar().addMenu(title) @@ -1295,113 +1287,3 @@ def read(filename, default=None): return f.read() except Exception: return default - - -def main(): - parser = argparse.ArgumentParser() - parser.add_argument('--version', '-V', action='store_true', - help='show version') - parser.add_argument('filename', nargs='?', help='image or label filename') - parser.add_argument('--output', '-O', '-o', help='output label name') - default_config_file = os.path.join(os.path.expanduser('~'), '.labelmerc') - parser.add_argument( - '--config', - dest='config_file', - help='config file (default: %s)' % default_config_file, - default=default_config_file, - ) - # config for the gui - parser.add_argument( - '--nodata', - dest='store_data', - action='store_false', - help='stop storing image data to JSON file', - default=argparse.SUPPRESS, - ) - parser.add_argument( - '--autosave', - dest='auto_save', - action='store_true', - help='auto save', - default=argparse.SUPPRESS, - ) - parser.add_argument( - '--nosortlabels', - dest='sort_labels', - action='store_false', - help='stop sorting labels', - default=argparse.SUPPRESS, - ) - parser.add_argument( - '--flags', - help='comma separated list of flags OR file containing flags', - default=argparse.SUPPRESS, - ) - parser.add_argument( - '--labels', - help='comma separated list of labels OR file containing labels', - default=argparse.SUPPRESS, - ) - parser.add_argument( - '--validatelabel', - dest='validate_label', - choices=['exact', 'instance'], - help='label validation types', - default=argparse.SUPPRESS, - ) - parser.add_argument( - '--keep-prev', - action='store_true', - help='keep annotation of previous frame', - default=argparse.SUPPRESS, - ) - parser.add_argument( - '--epsilon', - type=float, - help='epsilon to find nearest vertex on canvas', - default=argparse.SUPPRESS, - ) - args = parser.parse_args() - - if args.version: - print('{0} {1}'.format(__appname__, __version__)) - sys.exit(0) - - if hasattr(args, 'flags'): - if os.path.isfile(args.flags): - with codecs.open(args.flags, 'r', encoding='utf-8') as f: - args.flags = [l.strip() for l in f if l.strip()] - else: - args.flags = [l for l in args.flags.split(',') if l] - - if hasattr(args, 'labels'): - if os.path.isfile(args.labels): - with codecs.open(args.labels, 'r', encoding='utf-8') as f: - args.labels = [l.strip() for l in f if l.strip()] - else: - args.labels = [l for l in args.labels.split(',') if l] - - config_from_args = args.__dict__ - config_from_args.pop('version') - filename = config_from_args.pop('filename') - output = config_from_args.pop('output') - config_file = config_from_args.pop('config_file') - config = get_config(config_from_args, config_file) - - if not config['labels'] and config['validate_label']: - logger.error('--labels must be specified with --validatelabel or ' - 'validate_label: true in the config file ' - '(ex. ~/.labelmerc).') - sys.exit(1) - - app = QtWidgets.QApplication(sys.argv) - app.setApplicationName(__appname__) - app.setWindowIcon(newIcon('icon')) - win = MainWindow(config=config, filename=filename, output=output) - win.show() - win.raise_() - sys.exit(app.exec_()) - - -if __name__ == '__main__': - main() diff --git a/labelme/main.py b/labelme/main.py new file mode 100644 index 0000000000000000000000000000000000000000..622c2e29f6123582c25e7bad75843a8f8f922663 --- /dev/null +++ b/labelme/main.py @@ -0,0 +1,119 @@ +import argparse +import codecs +import os +import sys + +from qtpy import QtWidgets + +from labelme import __appname__ +from labelme import __version__ +from labelme.app import MainWindow +from labelme.config import get_config +from labelme import logger +from labelme.utils import newIcon + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--version', '-V', action='store_true', + help='show version') + parser.add_argument('filename', nargs='?', help='image or label filename') + parser.add_argument('--output', '-O', '-o', help='output label name') + default_config_file = os.path.join(os.path.expanduser('~'), '.labelmerc') + parser.add_argument( + '--config', + dest='config_file', + help='config file (default: %s)' % default_config_file, + default=default_config_file, + ) + # config for the gui + parser.add_argument( + '--nodata', + dest='store_data', + action='store_false', + help='stop storing image data to JSON file', + default=argparse.SUPPRESS, + ) + parser.add_argument( + '--autosave', + dest='auto_save', + action='store_true', + help='auto save', + default=argparse.SUPPRESS, + ) + parser.add_argument( + '--nosortlabels', + dest='sort_labels', + action='store_false', + help='stop sorting labels', + default=argparse.SUPPRESS, + ) + parser.add_argument( + '--flags', + help='comma separated list of flags OR file containing flags', + default=argparse.SUPPRESS, + ) + parser.add_argument( + '--labels', + help='comma separated list of labels OR file containing labels', + default=argparse.SUPPRESS, + ) + parser.add_argument( + '--validatelabel', + dest='validate_label', + choices=['exact', 'instance'], + help='label validation types', + default=argparse.SUPPRESS, + ) + parser.add_argument( + '--keep-prev', + action='store_true', + help='keep annotation of previous frame', + default=argparse.SUPPRESS, + ) + parser.add_argument( + '--epsilon', + type=float, + help='epsilon to find nearest vertex on canvas', + default=argparse.SUPPRESS, + ) + args = parser.parse_args() + + if args.version: + print('{0} {1}'.format(__appname__, __version__)) + sys.exit(0) + + if hasattr(args, 'flags'): + if os.path.isfile(args.flags): + with codecs.open(args.flags, 'r', encoding='utf-8') as f: + args.flags = [l.strip() for l in f if l.strip()] + else: + args.flags = [l for l in args.flags.split(',') if l] + + if hasattr(args, 'labels'): + if os.path.isfile(args.labels): + with codecs.open(args.labels, 'r', encoding='utf-8') as f: + args.labels = [l.strip() for l in f if l.strip()] + else: + args.labels = [l for l in args.labels.split(',') if l] + + config_from_args = args.__dict__ + config_from_args.pop('version') + filename = config_from_args.pop('filename') + output = config_from_args.pop('output') + config_file = config_from_args.pop('config_file') + config = get_config(config_from_args, config_file) + + if not config['labels'] and config['validate_label']: + logger.error('--labels must be specified with --validatelabel or ' + 'validate_label: true in the config file ' + '(ex. ~/.labelmerc).') + sys.exit(1) + + app = QtWidgets.QApplication(sys.argv) + app.setApplicationName(__appname__) + app.setWindowIcon(newIcon('icon')) + win = MainWindow(config=config, filename=filename, output=output) + win.show() + win.raise_() + sys.exit(app.exec_()) diff --git a/setup.py b/setup.py index 99d77be3bfa327ebf876dcf3df27c043bb77088f..708890be5e025c18402e137d11bc7be531dfd485 100644 --- a/setup.py +++ b/setup.py @@ -98,7 +98,7 @@ setup( package_data={'labelme': ['icons/*', 'config/*.yaml']}, entry_points={ 'console_scripts': [ - 'labelme=labelme.app:main', + 'labelme=labelme.main:main', 'labelme_draw_json=labelme.cli.draw_json:main', 'labelme_draw_label_png=labelme.cli.draw_label_png:main', 'labelme_json_to_dataset=labelme.cli.json_to_dataset:main',