|
@@ -2,22 +2,30 @@
|
|
|
|
|
|
import argparse
|
|
import argparse
|
|
import json
|
|
import json
|
|
|
|
+import os
|
|
import os.path as osp
|
|
import os.path as osp
|
|
|
|
+import platform
|
|
import shlex
|
|
import shlex
|
|
import subprocess
|
|
import subprocess
|
|
import sys
|
|
import sys
|
|
|
|
|
|
|
|
|
|
def get_ip():
|
|
def get_ip():
|
|
- cmd = 'ifconfig en0'
|
|
|
|
- output = subprocess.check_output(shlex.split(cmd))
|
|
|
|
- for row in output.splitlines():
|
|
|
|
- cols = row.strip().split(' ')
|
|
|
|
- if cols[0] == 'inet':
|
|
|
|
- ip = cols[1]
|
|
|
|
- return ip
|
|
|
|
|
|
+ dist = platform.platform().split('-')[0]
|
|
|
|
+ if dist == 'Linux':
|
|
|
|
+ return ''
|
|
|
|
+ elif dist == 'Darwin':
|
|
|
|
+ cmd = 'ifconfig en0'
|
|
|
|
+ output = subprocess.check_output(shlex.split(cmd))
|
|
|
|
+ for row in output.splitlines():
|
|
|
|
+ cols = row.strip().split(' ')
|
|
|
|
+ if cols[0] == 'inet':
|
|
|
|
+ ip = cols[1]
|
|
|
|
+ return ip
|
|
|
|
+ else:
|
|
|
|
+ raise RuntimeError('No ip is found.')
|
|
else:
|
|
else:
|
|
- raise RuntimeError('No ip is found.')
|
|
|
|
|
|
+ raise RuntimeError('Unsupported platform.')
|
|
|
|
|
|
|
|
|
|
def labelme_on_docker(image_file, out_file):
|
|
def labelme_on_docker(image_file, out_file):
|
|
@@ -31,19 +39,21 @@ def labelme_on_docker(image_file, out_file):
|
|
else:
|
|
else:
|
|
open(osp.abspath(out_file), 'w')
|
|
open(osp.abspath(out_file), 'w')
|
|
|
|
|
|
- cmd = 'docker run -it --rm -e DISPLAY={0}:0' \
|
|
|
|
|
|
+ cmd = 'docker run -it --rm' \
|
|
|
|
+ ' -e DISPLAY={0}:0' \
|
|
|
|
+ ' -e QT_X11_NO_MITSHM=1' \
|
|
' -v /tmp/.X11-unix:/tmp/.X11-unix' \
|
|
' -v /tmp/.X11-unix:/tmp/.X11-unix' \
|
|
' -v {1}:{2}' \
|
|
' -v {1}:{2}' \
|
|
' -v {3}:{4}' \
|
|
' -v {3}:{4}' \
|
|
- ' -w /root' \
|
|
|
|
|
|
+ ' -w /home/developer' \
|
|
' labelme' \
|
|
' labelme' \
|
|
' labelme {2} -O {4}'
|
|
' labelme {2} -O {4}'
|
|
cmd = cmd.format(
|
|
cmd = cmd.format(
|
|
ip,
|
|
ip,
|
|
osp.abspath(image_file),
|
|
osp.abspath(image_file),
|
|
- osp.join('/root', osp.basename(image_file)),
|
|
|
|
|
|
+ osp.join('/home/developer', osp.basename(image_file)),
|
|
osp.abspath(out_file),
|
|
osp.abspath(out_file),
|
|
- osp.join('/root', osp.basename(out_file)),
|
|
|
|
|
|
+ osp.join('/home/developer', osp.basename(out_file)),
|
|
)
|
|
)
|
|
subprocess.call(shlex.split(cmd))
|
|
subprocess.call(shlex.split(cmd))
|
|
|
|
|
|
@@ -51,6 +61,8 @@ def labelme_on_docker(image_file, out_file):
|
|
json.load(open(out_file))
|
|
json.load(open(out_file))
|
|
return out_file
|
|
return out_file
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
|
+ if open(out_file).read() == '':
|
|
|
|
+ os.remove(out_file)
|
|
raise RuntimeError('Annotation is cancelled.')
|
|
raise RuntimeError('Annotation is cancelled.')
|
|
|
|
|
|
|
|
|