Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
monticore
EmbeddedMontiArc
generators
CNNArch2MXNet
Commits
3166e571
Commit
3166e571
authored
May 31, 2018
by
Thomas Michael Timmermanns
Browse files
Added CNNTrain parameter 'context'
parent
69ec2e86
Pipeline
#52302
failed with stage
in 46 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/main/resources/templates/CNNCreator.ftl
View file @
3166e571
...
...
@@ -110,9 +110,15 @@ class ${tc.fileNameWithoutEnding}:
optimizer='adam',
optimizer_params=(('learning_rate', 0.001),),
load_checkpoint=True,
context=
mx.
gpu
()
,
context=
'
gpu
'
,
checkpoint_period=5,
normalize=True):
if context == 'gpu':
mx_context = mx.gpu()
elif context == 'cpu':
mx_context = mx.cpu()
else:
logging.error("Context argument is '" + context + "'. Only 'cpu' and 'gpu are valid arguments'.")
if 'weight_decay' in optimizer_params:
optimizer_params['wd'] = optimizer_params['weight_decay']
...
...
@@ -133,13 +139,13 @@ class ${tc.fileNameWithoutEnding}:
train_iter, test_iter, data_mean, data_std = self.load_data(batch_size)
if self.module == None:
if normalize:
self.construct(context, data_mean, data_std)
self.construct(
mx_
context, data_mean, data_std)
else:
self.construct(context)
self.construct(
mx_
context)
begin_epoch = 0
if load_checkpoint:
begin_epoch = self.load(context)
begin_epoch = self.load(
mx_
context)
else:
if os.path.isdir(self._model_dir_):
shutil.rmtree(self._model_dir_)
...
...
src/test/resources/target_code/CNNCreator_Alexnet.py
View file @
3166e571
...
...
@@ -110,9 +110,15 @@ class CNNCreator_Alexnet:
optimizer
=
'adam'
,
optimizer_params
=
((
'learning_rate'
,
0.001
),),
load_checkpoint
=
True
,
context
=
mx
.
gpu
()
,
context
=
'
gpu
'
,
checkpoint_period
=
5
,
normalize
=
True
):
if
context
==
'gpu'
:
mx_context
=
mx
.
gpu
()
elif
context
==
'cpu'
:
mx_context
=
mx
.
cpu
()
else
:
logging
.
error
(
"Context argument is '"
+
context
+
"'. Only 'cpu' and 'gpu are valid arguments'."
)
if
'weight_decay'
in
optimizer_params
:
optimizer_params
[
'wd'
]
=
optimizer_params
[
'weight_decay'
]
...
...
@@ -133,13 +139,13 @@ class CNNCreator_Alexnet:
train_iter
,
test_iter
,
data_mean
,
data_std
=
self
.
load_data
(
batch_size
)
if
self
.
module
==
None
:
if
normalize
:
self
.
construct
(
context
,
data_mean
,
data_std
)
self
.
construct
(
mx_
context
,
data_mean
,
data_std
)
else
:
self
.
construct
(
context
)
self
.
construct
(
mx_
context
)
begin_epoch
=
0
if
load_checkpoint
:
begin_epoch
=
self
.
load
(
context
)
begin_epoch
=
self
.
load
(
mx_
context
)
else
:
if
os
.
path
.
isdir
(
self
.
_model_dir_
):
shutil
.
rmtree
(
self
.
_model_dir_
)
...
...
@@ -417,4 +423,4 @@ class CNNCreator_Alexnet:
self
.
module
=
mx
.
mod
.
Module
(
symbol
=
mx
.
symbol
.
Group
([
predictions
]),
data_names
=
self
.
_input_names_
,
label_names
=
self
.
_output_names_
,
context
=
context
)
\ No newline at end of file
context
=
context
)
src/test/resources/target_code/CNNCreator_CifarClassifierNetwork.py
View file @
3166e571
...
...
@@ -110,9 +110,15 @@ class CNNCreator_CifarClassifierNetwork:
optimizer
=
'adam'
,
optimizer_params
=
((
'learning_rate'
,
0.001
),),
load_checkpoint
=
True
,
context
=
mx
.
gpu
()
,
context
=
'
gpu
'
,
checkpoint_period
=
5
,
normalize
=
True
):
if
context
==
'gpu'
:
mx_context
=
mx
.
gpu
()
elif
context
==
'cpu'
:
mx_context
=
mx
.
cpu
()
else
:
logging
.
error
(
"Context argument is '"
+
context
+
"'. Only 'cpu' and 'gpu are valid arguments'."
)
if
'weight_decay'
in
optimizer_params
:
optimizer_params
[
'wd'
]
=
optimizer_params
[
'weight_decay'
]
...
...
@@ -133,13 +139,13 @@ class CNNCreator_CifarClassifierNetwork:
train_iter
,
test_iter
,
data_mean
,
data_std
=
self
.
load_data
(
batch_size
)
if
self
.
module
==
None
:
if
normalize
:
self
.
construct
(
context
,
data_mean
,
data_std
)
self
.
construct
(
mx_
context
,
data_mean
,
data_std
)
else
:
self
.
construct
(
context
)
self
.
construct
(
mx_
context
)
begin_epoch
=
0
if
load_checkpoint
:
begin_epoch
=
self
.
load
(
context
)
begin_epoch
=
self
.
load
(
mx_
context
)
else
:
if
os
.
path
.
isdir
(
self
.
_model_dir_
):
shutil
.
rmtree
(
self
.
_model_dir_
)
...
...
@@ -655,4 +661,4 @@ class CNNCreator_CifarClassifierNetwork:
self
.
module
=
mx
.
mod
.
Module
(
symbol
=
mx
.
symbol
.
Group
([
softmax
]),
data_names
=
self
.
_input_names_
,
label_names
=
self
.
_output_names_
,
context
=
context
)
\ No newline at end of file
context
=
context
)
src/test/resources/target_code/CNNCreator_VGG16.py
View file @
3166e571
...
...
@@ -110,9 +110,15 @@ class CNNCreator_VGG16:
optimizer
=
'adam'
,
optimizer_params
=
((
'learning_rate'
,
0.001
),),
load_checkpoint
=
True
,
context
=
mx
.
gpu
()
,
context
=
'
gpu
'
,
checkpoint_period
=
5
,
normalize
=
True
):
if
context
==
'gpu'
:
mx_context
=
mx
.
gpu
()
elif
context
==
'cpu'
:
mx_context
=
mx
.
cpu
()
else
:
logging
.
error
(
"Context argument is '"
+
context
+
"'. Only 'cpu' and 'gpu are valid arguments'."
)
if
'weight_decay'
in
optimizer_params
:
optimizer_params
[
'wd'
]
=
optimizer_params
[
'weight_decay'
]
...
...
@@ -133,13 +139,13 @@ class CNNCreator_VGG16:
train_iter
,
test_iter
,
data_mean
,
data_std
=
self
.
load_data
(
batch_size
)
if
self
.
module
==
None
:
if
normalize
:
self
.
construct
(
context
,
data_mean
,
data_std
)
self
.
construct
(
mx_
context
,
data_mean
,
data_std
)
else
:
self
.
construct
(
context
)
self
.
construct
(
mx_
context
)
begin_epoch
=
0
if
load_checkpoint
:
begin_epoch
=
self
.
load
(
context
)
begin_epoch
=
self
.
load
(
mx_
context
)
else
:
if
os
.
path
.
isdir
(
self
.
_model_dir_
):
shutil
.
rmtree
(
self
.
_model_dir_
)
...
...
@@ -453,4 +459,4 @@ class CNNCreator_VGG16:
self
.
module
=
mx
.
mod
.
Module
(
symbol
=
mx
.
symbol
.
Group
([
predictions
]),
data_names
=
self
.
_input_names_
,
label_names
=
self
.
_output_names_
,
context
=
context
)
\ No newline at end of file
context
=
context
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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