Skip to content

Commit

Permalink
Support linux on labelme_on_docker
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed May 18, 2017
1 parent 02ae920 commit 056df07
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
12 changes: 12 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
FROM ubuntu:trusty

# Replace 1000 with your user / group id
RUN export uid=1000 gid=1000 && \
mkdir -p /home/developer && \
echo "developer:x:${uid}:${gid}:Developer,,,:/home/developer:/bin/bash" >> /etc/passwd && \
echo "developer:x:${uid}:" >> /etc/group && \
echo "developer ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/developer && \
chmod 0440 /etc/sudoers.d/developer && \
chown ${uid}:${gid} -R /home/developer

RUN \
apt-get update -qq && \
apt-get upgrade -qq -y && \
Expand All @@ -19,3 +28,6 @@ RUN apt-get install -qq -y python-scipy
RUN apt-get install -qq -y python-skimage

RUN pip install -v git+https://github.com/wkentaro/labelme.git

USER developer
ENV HOME /home/developer
36 changes: 24 additions & 12 deletions scripts/labelme_on_docker
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,30 @@

import argparse
import json
import os
import os.path as osp
import platform
import shlex
import subprocess
import sys


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:
raise RuntimeError('No ip is found.')
raise RuntimeError('Unsupported platform.')


def labelme_on_docker(image_file, out_file):
Expand All @@ -31,26 +39,30 @@ def labelme_on_docker(image_file, out_file):
else:
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 {1}:{2}' \
' -v {3}:{4}' \
' -w /root' \
' -w /home/developer' \
' labelme' \
' labelme {2} -O {4}'
cmd = cmd.format(
ip,
osp.abspath(image_file),
osp.join('/root', osp.basename(image_file)),
osp.join('/home/developer', osp.basename(image_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))

try:
json.load(open(out_file))
return out_file
except Exception as e:
if open(out_file).read() == '':
os.remove(out_file)
raise RuntimeError('Annotation is cancelled.')


Expand Down

0 comments on commit 056df07

Please sign in to comment.