Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
inovisao
pynovisao
Commits
9b54fe1f
Commit
9b54fe1f
authored
Dec 26, 2017
by
Gabriel Kirsten
Browse files
add threads, open_weight function added and classifier not found message changed
parent
4421d251
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
23 deletions
+38
-23
src/pynovisao.py
src/pynovisao.py
+38
-23
No files found.
src/pynovisao.py
View file @
9b54fe1f
...
...
@@ -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
(
"
\n
Classification 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
():
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment