Commit 9b54fe1f authored by Gabriel Kirsten's avatar Gabriel Kirsten
Browse files

add threads, open_weight function added and classifier not found message changed
parent 4421d251
......@@ -25,10 +25,11 @@ from util.config import Config
from util.file_utils import File as f
from util.utils import TimeUtils
class Act(object):
"""Store all actions of Pynovisao."""
def __init__(self, tk, args):
def __init__(self, tk, thread, args):
"""Constructor.
Parameters
......@@ -59,9 +60,12 @@ class Act(object):
self._init_dataset(args["dataset"])
self._init_classes(args["classes"], args["colors"])
self.thread = thread
self._dataset_generator = True
self._ground_truth = False
self._gt_segments = None
self.weight_path = None
def _init_dataset(self, directory):
......@@ -152,6 +156,11 @@ class Act(object):
self._gt_segments = None
def open_weight(self):
"""Open a new weight."""
self.weight_path = self.tk.utils.ask_weight_name()
def restore_image(self):
"""Refresh the image and clean the segmentation.
"""
......@@ -424,7 +433,7 @@ class Act(object):
The user must install the required dependencies to classifiers.
"""
if self.classifier is None:
raise IException("You must install python-weka-wrapper")
raise IException("Classifier not found!")
title = "Choosing a classifier"
self.tk.write_log(title)
......@@ -452,7 +461,7 @@ class Act(object):
The user must install the required dependencies to classifiers.
"""
if self.classifier is None:
raise IException("You must install python-weka-wrapper")
raise IException("Classifier not found!")
title = "Configuring %s" % self.classifier.get_name()
self.tk.write_log(title)
......@@ -482,7 +491,7 @@ class Act(object):
If there's no image opened.
"""
if self.classifier is None:
raise IException("You must install python-weka-wrapper")
raise IException("Classifier not found!")
if self._const_image is None:
raise IException("Image not found")
......@@ -502,20 +511,6 @@ class Act(object):
list_segments = self.segmenter.get_list_segments()
self._gt_segments = [None]*(max(list_segments)+1)
# Train the classifier ( this program does not perform the training of ConvNets ).
if self.classifier.must_train():
self.tk.append_log("Creating training data... (%0.3f seconds)", (TimeUtils.get_time() - start_time))
fextractor = FeatureExtractor(self.extractors)
output_file, run_time = fextractor.extract_all(self.dataset, "training", overwrite = False)
self.tk.append_log("Training classifier... (%0.3f seconds)", (TimeUtils.get_time() - start_time))
self.classifier.train(self.dataset, "training")
self._image = self._const_image
# New and optimized classification
tmp = ".tmp"
f.remove_dir(f.make_path(self.dataset, tmp))
......@@ -530,9 +525,8 @@ class Act(object):
len_segments[idx_segment] = size_segment
# Perform the feature extraction of all segments in image ( not applied to ConvNets ).
if self.classifier.must_train():
self.tk.append_log("Running extractors on test images... (%0.3f seconds)", (TimeUtils.get_time() - start_time))
if self.classifier.must_extract_features():
self.tk.append_log("Running extractors on test images... (%0.3f seconds)", (TimeUtils.get_time() - start_time))
output_file, _ = fextractor.extract_all(self.dataset, "test", dirs=[tmp])
self.tk.append_log("Running classifier on test data... (%0.3f seconds)", (TimeUtils.get_time() - start_time))
......@@ -570,7 +564,28 @@ class Act(object):
self.tk.append_log("\nClassification finished")
self.tk.append_log("Time elapsed: %0.3f seconds", (end_time - start_time))
def run_training(self):
start_time = TimeUtils.get_time()
if self._const_image is None:
raise IException("Image not found")
if self.classifier.must_train():
if self.classifier.must_extract_features():
self.tk.append_log("Creating training data... (%0.3f seconds)", (TimeUtils.get_time() - start_time))
fextractor = FeatureExtractor(self.extractors)
output_file, run_time = fextractor.extract_all(self.dataset, "training", overwrite = False)
self.tk.append_log("Training classifier...")
self.thread.start_new_thread(self.classifier.train, (self.dataset, "training"))
self.tk.append_log("DONE (%0.3f seconds)", (TimeUtils.get_time() - start_time))
self._image = self._const_image
def _show_ground_truth(self, list_segments, len_segments, labels, start_time):
"""Paint only wrong classified segments and show ground truth confusion matrix.
......@@ -633,7 +648,7 @@ class Act(object):
The user must install the required dependencies to classifiers.
"""
if self.classifier is None:
raise IException("You must install python-weka-wrapper")
raise IException("Classifier not found!")
if self.classifier.must_train():
self.tk.write_log("Creating training data...")
......@@ -658,7 +673,7 @@ class Act(object):
The user must install the required dependencies to classifiers.
"""
if self.classifier is None:
raise IException("You must install python-weka-wrapper")
raise IException("Classifier not found!")
if self.tk.ask_ok_cancel("Experimenter All", "This may take several minutes to complete. Are you sure?"):
if self.classifier.must_train():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment