diff --git a/README.md b/README.md index 380804f..e155304 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ This project has a web interface to label training data for machine learning task. As of now it can allow you to easily label images with one or many labels +Support both python 2 and python 3 # Requires @@ -25,12 +26,16 @@ Install them using pip { "type": "image-labeling", "task": { - "labels":[ - "class1", - "class2", - "class3", - "class4" - ] + "labels":[[ + "D1", + "D2", + "D3", + "D4", + "D5", + "D6" + ], ["Front", + "Side", + "Back"]] } } ``` @@ -66,7 +71,7 @@ Visit http://localhost:8080 on web browser ## Screenshots -![Image](../master/screenshots/labeling-images.png?raw=true) +![Image](../master/screenshots/multilabel.jpg?raw=true) ## WARNING: diff --git a/app.py b/app.py index 0445c00..b9d5bed 100644 --- a/app.py +++ b/app.py @@ -24,6 +24,10 @@ import logging from datetime import datetime import urllib +try: + from urllib import quote # Python 2.X +except ImportError: + from urllib.parse import quote # Python 3+ from flask import Flask, render_template, request, abort, send_file, redirect, Response app = Flask(__name__) @@ -54,7 +58,7 @@ def webpage(): # redirect with url query param so that user can navigate back later next_rec = service.get_next_unlabelled() if next_rec: - return redirect("/?url=%s" % (urllib.quote(next_rec['url']))) + return redirect("/?url=%s" % (quote(next_rec['url']))) else: featured_content = "No Unlabelled Record Found." else: @@ -84,7 +88,7 @@ def update(): next_rec = service.get_next_unlabelled() target = "/" if next_rec: - target += "?url=%s" % (urllib.quote(next_rec['url'])) + target += "?url=%s" % (quote(next_rec['url'])) return redirect(location=target) else: return abort(400, "Failed... No records updated") @@ -104,7 +108,7 @@ def get_next(url=None): next_rec = service.get_record(url) url = next_rec['url'] template_name = '%s.html' % service.settings['type'] - data_url = url if url.startswith('http') else "/proxy?url=%s" % urllib.quote(next_rec['url']) + data_url = url if url.startswith('http') else "/proxy?url=%s" % quote(next_rec['url']) data = { 'data_url' : data_url, 'url': url, diff --git a/screenshots/multilabel.jpg b/screenshots/multilabel.jpg new file mode 100644 index 0000000..5269afb Binary files /dev/null and b/screenshots/multilabel.jpg differ diff --git a/templates/image-labeling.html b/templates/image-labeling.html index 5954a80..8568e09 100644 --- a/templates/image-labeling.html +++ b/templates/image-labeling.html @@ -4,8 +4,11 @@

Classify this image:

- {% for label in task.labels %} - {{ loop.index }}) {{ label }}
+ {% for labels in task.labels %} +

Category: {{ loop.index }}

+ {% for label in labels %} + {{ loop.index }}) {{ label }}
+ {% endfor %} {% endfor %}
@@ -29,10 +32,12 @@

Classify this image:

let key = String.fromCharCode(e.keyCode); {% for label in task.labels %} - if (key == "{{ loop.index }}") { - let el = document.getElementById("checkbox_{{ label }}"); - el.checked = !el.checked; - } + {% for label in task.labels %} + if (key == "{{ loop.index }}") { + let el = document.getElementById("checkbox_{{ label }}"); + el.checked = !el.checked; + } + {% endfor %} {% endfor %} // submit on enter diff --git a/templates/index.html b/templates/index.html index dde7aef..a49bef9 100644 --- a/templates/index.html +++ b/templates/index.html @@ -4,9 +4,10 @@ Trainer - Create labels for data - - - + + + +
diff --git a/workdir/.Rhistory b/workdir/.Rhistory new file mode 100644 index 0000000..e69de29 diff --git a/workdir/input.txt b/workdir/input.txt new file mode 100644 index 0000000..2cdfa55 --- /dev/null +++ b/workdir/input.txt @@ -0,0 +1,15 @@ +/home/duydo/Heligate/Labeling/Data/download (1).jpeg +/home/duydo/Heligate/Labeling/Data/salons-model.jpg +/home/duydo/Heligate/Labeling/Data/tumblr_static_akrcuuu9magcgco4cgoc8wg40.jpg +/home/duydo/Heligate/Labeling/Data/download.jpeg +/home/duydo/Heligate/Labeling/Data/2013062023115989.jpg +/home/duydo/Heligate/Labeling/Data/240_F_122448278_iUlaPjFaloCml31UZpPt25cb9w4mvKMT.jpg +/home/duydo/Heligate/Labeling/Data/images (2).jpeg +/home/duydo/Heligate/Labeling/Data/images (1).jpeg +/home/duydo/Heligate/Labeling/Data/l_oreal_paris_elvive_camila_cabello.jpg +/home/duydo/Heligate/Labeling/Data/models-wanted.jpg +/home/duydo/Heligate/Labeling/Data/woman_on_white-700x750.jpg +/home/duydo/Heligate/Labeling/Data/images.jpeg +/home/duydo/Heligate/Labeling/Data/grace-jones-inspired-hair.jpeg +/home/duydo/Heligate/Labeling/Data/1c56aec62775e2222c78338a4dbb7cdd.jpg +/home/duydo/Heligate/Labeling/Data/ColorZoom_Mobile_Patricia_01.jpg diff --git a/workdir/settings.json b/workdir/settings.json index 33b4bb4..359c967 100644 --- a/workdir/settings.json +++ b/workdir/settings.json @@ -1,11 +1,15 @@ { "type": "image-labeling", "task": { - "labels":[ - "class1", - "class2", - "class3", - "class4" - ] + "labels":[[ + "D1", + "D2", + "D3", + "D4", + "D5", + "D6" + ], ["Front", + "Side", + "Back"]] } }