From 749a4afbd88527077ef51c006242809623dd9d82 Mon Sep 17 00:00:00 2001 From: Greg Heinrich Date: Mon, 27 Jul 2015 17:26:01 +0200 Subject: [PATCH] Enable use of server files in dataset creation - closes #106 --- digits/dataset/images/classification/forms.py | 44 ++++++++- digits/dataset/images/classification/views.py | 49 +++++---- .../datasets/images/classification/new.html | 99 ++++++++++++++----- 3 files changed, 144 insertions(+), 48 deletions(-) diff --git a/digits/dataset/images/classification/forms.py b/digits/dataset/images/classification/forms.py index d08840119..d3864b3eb 100644 --- a/digits/dataset/images/classification/forms.py +++ b/digits/dataset/images/classification/forms.py @@ -106,9 +106,19 @@ def validate_folder_path(form, field): ### Method - textfile + textfile_use_local_files = wtforms.BooleanField(u'Use local files', + default=False) + textfile_train_images = wtforms.FileField(u'Training images', validators=[ - validate_required_iff(method='textfile') + validate_required_iff(method='textfile', + textfile_use_local_files=False) + ] + ) + textfile_local_train_images = wtforms.StringField(u'Training images', + validators=[ + validate_required_iff(method='textfile', + textfile_use_local_files=True) ] ) textfile_train_folder = wtforms.StringField(u'Training images folder') @@ -134,7 +144,16 @@ def validate_textfile_train_folder(form, field): validators=[ validate_required_iff( method='textfile', - textfile_use_val=True) + textfile_use_val=True, + textfile_use_local_files=False) + ] + ) + textfile_local_val_images = wtforms.StringField(u'Validation images', + validators=[ + validate_required_iff( + method='textfile', + textfile_use_val=True, + textfile_use_local_files=True) ] ) textfile_val_folder = wtforms.StringField(u'Validation images folder') @@ -160,7 +179,16 @@ def validate_textfile_val_folder(form, field): validators=[ validate_required_iff( method='textfile', - textfile_use_test=True) + textfile_use_test=True, + textfile_use_local_files=False) + ] + ) + textfile_local_test_images = wtforms.StringField(u'Test images', + validators=[ + validate_required_iff( + method='textfile', + textfile_use_test=True, + textfile_use_local_files=True) ] ) textfile_test_folder = wtforms.StringField(u'Test images folder') @@ -191,7 +219,15 @@ def validate_textfile_test_folder(form, field): textfile_labels_file = wtforms.FileField(u'Labels', validators=[ - validate_required_iff(method='textfile') + validate_required_iff(method='textfile', + textfile_use_local_files=False) + ] + ) + + textfile_local_labels_file = wtforms.StringField(u'Labels', + validators=[ + validate_required_iff(method='textfile', + textfile_use_local_files=True) ] ) diff --git a/digits/dataset/images/classification/views.py b/digits/dataset/images/classification/views.py index ac36e4b8c..ef5c9a77e 100644 --- a/digits/dataset/images/classification/views.py +++ b/digits/dataset/images/classification/views.py @@ -118,20 +118,25 @@ def from_files(job, form): Add tasks for creating a dataset by reading textfiles """ ### labels - - flask.request.files[form.textfile_labels_file.name].save( - os.path.join(job.dir(), utils.constants.LABELS_FILE) - ) - job.labels_file = utils.constants.LABELS_FILE + if form.textfile_use_local_files.data: + job.labels_file = form.textfile_local_labels_file.data.strip() + else: + flask.request.files[form.textfile_labels_file.name].save( + os.path.join(job.dir(), utils.constants.LABELS_FILE) + ) + job.labels_file = utils.constants.LABELS_FILE encoding = form.encoding.data shuffle = bool(form.textfile_shuffle.data) ### train - - flask.request.files[form.textfile_train_images.name].save( - os.path.join(job.dir(), utils.constants.TRAIN_FILE) - ) + if form.textfile_use_local_files.data: + train_file = form.textfile_local_train_images.data.strip() + else: + flask.request.files[form.textfile_train_images.name].save( + os.path.join(job.dir(), utils.constants.TRAIN_FILE) + ) + train_file = utils.constants.TRAIN_FILE image_folder = form.textfile_train_folder.data.strip() if not image_folder: @@ -140,7 +145,7 @@ def from_files(job, form): job.tasks.append( tasks.CreateDbTask( job_dir = job.dir(), - input_file = utils.constants.TRAIN_FILE, + input_file = train_file, db_name = utils.constants.TRAIN_DB, image_dims = job.image_dims, image_folder= image_folder, @@ -155,9 +160,13 @@ def from_files(job, form): ### val if form.textfile_use_val.data: - flask.request.files[form.textfile_val_images.name].save( - os.path.join(job.dir(), utils.constants.VAL_FILE) - ) + if form.textfile_use_local_files.data: + val_file = form.textfile_local_val_images.data.strip() + else: + flask.request.files[form.textfile_val_images.name].save( + os.path.join(job.dir(), utils.constants.VAL_FILE) + ) + val_file = utils.constants.VAL_FILE image_folder = form.textfile_val_folder.data.strip() if not image_folder: @@ -166,7 +175,7 @@ def from_files(job, form): job.tasks.append( tasks.CreateDbTask( job_dir = job.dir(), - input_file = utils.constants.VAL_FILE, + input_file = val_file, db_name = utils.constants.VAL_DB, image_dims = job.image_dims, image_folder= image_folder, @@ -180,9 +189,13 @@ def from_files(job, form): ### test if form.textfile_use_test.data: - flask.request.files[form.textfile_test_images.name].save( - os.path.join(job.dir(), utils.constants.TEST_FILE) - ) + if form.textfile_use_local_files.data: + test_file = form.textfile_local_test_images.data.strip() + else: + flask.request.files[form.textfile_test_images.name].save( + os.path.join(job.dir(), utils.constants.TEST_FILE) + ) + test_file = utils.constants.TEST_FILE image_folder = form.textfile_test_folder.data.strip() if not image_folder: @@ -191,7 +204,7 @@ def from_files(job, form): job.tasks.append( tasks.CreateDbTask( job_dir = job.dir(), - input_file = utils.constants.TEST_FILE, + input_file = test_file, db_name = utils.constants.TEST_DB, image_dims = job.image_dims, image_folder= image_folder, diff --git a/digits/templates/datasets/images/classification/new.html b/digits/templates/datasets/images/classification/new.html index 3c6e61a5d..156f627d0 100644 --- a/digits/templates/datasets/images/classification/new.html +++ b/digits/templates/datasets/images/classification/new.html @@ -127,7 +127,7 @@

New Image Classification Dataset

@@ -234,7 +234,7 @@

New Image Classification Dataset

Set Text file @@ -245,11 +245,29 @@

New Image Classification Dataset

title="Paths in the text files will be appended with this value before reading" > + + + + + + + + Training - + {{ form.textfile_train_images(class='form-control') }} + + {{ form.textfile_local_train_images(class='form-control',placeholder='enter path') }} + {{ form.textfile_train_folder(class='form-control') }} @@ -261,9 +279,12 @@

New Image Classification Dataset

Validation - + {{ form.textfile_val_images(class='form-control') }} + + {{ form.textfile_local_val_images(class='form-control',placeholder='enter path') }} + {{ form.textfile_val_folder(class='form-control') }} @@ -275,35 +296,18 @@

New Image Classification Dataset

Test - + {{ form.textfile_test_images(class='form-control') }} + + {{ form.textfile_local_test_images(class='form-control',placeholder='enter path') }} + {{ form.textfile_test_folder(class='form-control') }} - -
@@ -317,7 +321,7 @@

New Image Classification Dataset

>
-
+
{{ form.textfile_labels_file.label }}
{{ form.textfile_labels_file(class='form-control') }} @@ -328,6 +332,17 @@

New Image Classification Dataset

>
+
+ {{ form.textfile_local_labels_file.label }} +
+ {{ form.textfile_local_labels_file(class='form-control',placeholder='enter path') }} + +
+
@@ -337,6 +352,38 @@

New Image Classification Dataset

{{ form.method(style="display:none;") }}