Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
E
EMADL2CPP
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
10
Issues
10
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
monticore
EmbeddedMontiArc
generators
EMADL2CPP
Commits
18fe21dd
Commit
18fe21dd
authored
Mar 06, 2020
by
Julian Dierkes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated tests
parent
d2ed53ad
Changes
16
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
1790 additions
and
23 deletions
+1790
-23
hs_err_pid794.log
hs_err_pid794.log
+924
-0
pom.xml
pom.xml
+1
-1
src/test/resources/target_code/gluon/CNNDataLoader_mnist_mnistClassifier_net.py
...get_code/gluon/CNNDataLoader_mnist_mnistClassifier_net.py
+97
-0
src/test/resources/target_code/gluon/CNNNet_mnist_mnistClassifier_net.py
...ces/target_code/gluon/CNNNet_mnist_mnistClassifier_net.py
+14
-0
src/test/resources/target_code/gluon/reinforcementModel/cartpole/CNNDataLoader_cartpole_master_dqn.py
...cementModel/cartpole/CNNDataLoader_cartpole_master_dqn.py
+157
-5
src/test/resources/target_code/gluon/reinforcementModel/cartpole/CNNNet_cartpole_master_dqn.py
...reinforcementModel/cartpole/CNNNet_cartpole_master_dqn.py
+14
-0
src/test/resources/target_code/gluon/reinforcementModel/mountaincar/CNNDataLoader_mountaincar_master_actor.py
...del/mountaincar/CNNDataLoader_mountaincar_master_actor.py
+157
-5
src/test/resources/target_code/gluon/reinforcementModel/mountaincar/CNNNet_mountaincar_master_actor.py
...ementModel/mountaincar/CNNNet_mountaincar_master_actor.py
+14
-0
src/test/resources/target_code/gluon/reinforcementModel/mountaincar/reinforcement_learning/CNNNet_mountaincar_agent_mountaincarCritic.py
...nt_learning/CNNNet_mountaincar_agent_mountaincarCritic.py
+17
-0
src/test/resources/target_code/gluon/reinforcementModel/torcs/CNNDataLoader_torcs_agent_torcsAgent_dqn.py
...ntModel/torcs/CNNDataLoader_torcs_agent_torcsAgent_dqn.py
+157
-5
src/test/resources/target_code/gluon/reinforcementModel/torcs/CNNNet_torcs_agent_torcsAgent_dqn.py
...forcementModel/torcs/CNNNet_torcs_agent_torcsAgent_dqn.py
+14
-0
src/test/resources/target_code/gluon/reinforcementModel/torcs/reward/HelperA.h
...rget_code/gluon/reinforcementModel/torcs/reward/HelperA.h
+1
-1
src/test/resources/target_code/gluon/reinforcementModel/torcs_td3/CNNDataLoader_torcs_agent_torcsAgent_actor.py
...l/torcs_td3/CNNDataLoader_torcs_agent_torcsAgent_actor.py
+158
-5
src/test/resources/target_code/gluon/reinforcementModel/torcs_td3/CNNNet_torcs_agent_torcsAgent_actor.py
...entModel/torcs_td3/CNNNet_torcs_agent_torcsAgent_actor.py
+14
-0
src/test/resources/target_code/gluon/reinforcementModel/torcs_td3/reinforcement_learning/CNNNet_torcs_agent_network_torcsCritic.py
...cement_learning/CNNNet_torcs_agent_network_torcsCritic.py
+17
-0
train.log
train.log
+34
-1
No files found.
hs_err_pid794.log
0 → 100644
View file @
18fe21dd
This diff is collapsed.
Click to expand it.
pom.xml
View file @
18fe21dd
...
...
@@ -24,7 +24,7 @@
<cnnarch-gluon-generator.version>
0.2.10-SNAPSHOT
</cnnarch-gluon-generator.version>
<cnnarch-tensorflow-generator.version>
0.1.0-SNAPSHOT
</cnnarch-tensorflow-generator.version>
<Common-MontiCar.version>
0.0.14-20180704.113055-2
</Common-MontiCar.version>
<embedded-montiarc-math-opt-generator>
0.1.
5
</embedded-montiarc-math-opt-generator>
<embedded-montiarc-math-opt-generator>
0.1.
6
</embedded-montiarc-math-opt-generator>
<!-- .. Libraries .................................................. -->
<guava.version>
18.0
</guava.version>
...
...
src/test/resources/target_code/gluon/CNNDataLoader_mnist_mnistClassifier_net.py
View file @
18fe21dd
...
...
@@ -5,6 +5,7 @@ import logging
import
sys
import
numpy
as
np
import
cv2
import
importlib
from
mxnet
import
nd
class
CNNDataLoader_mnist_mnistClassifier_net
:
...
...
@@ -105,6 +106,102 @@ class CNNDataLoader_mnist_mnistClassifier_net:
return
train_iter
,
test_iter
,
data_mean
,
data_std
def
load_preprocessed_data
(
self
,
batch_size
,
preproc_lib
):
train_h5
,
test_h5
=
self
.
load_h5_files
()
wrapper
=
importlib
.
import_module
(
preproc_lib
)
instance
=
getattr
(
wrapper
,
preproc_lib
)()
instance
.
init
()
lib_head
,
_sep
,
tail
=
preproc_lib
.
rpartition
(
'_'
)
inp
=
getattr
(
wrapper
,
lib_head
+
"_input"
)()
train_data
=
{}
train_label
=
{}
data_mean
=
{}
data_std
=
{}
shape_output
=
self
.
preprocess_data
(
instance
,
inp
,
0
,
train_h5
)
train_len
=
len
(
train_h5
[
self
.
_input_names_
[
0
]])
for
input_name
in
self
.
_input_names_
:
if
type
(
getattr
(
shape_output
,
input_name
+
"_out"
))
==
np
.
ndarray
:
cur_shape
=
(
train_len
,)
+
getattr
(
shape_output
,
input_name
+
"_out"
).
shape
else
:
cur_shape
=
(
train_len
,
1
)
train_data
[
input_name
]
=
mx
.
nd
.
zeros
(
cur_shape
)
for
output_name
in
self
.
_output_names_
:
if
type
(
getattr
(
shape_output
,
output_name
+
"_out"
))
==
nd
.
array
:
cur_shape
=
(
train_len
,)
+
getattr
(
shape_output
,
output_name
+
"_out"
).
shape
else
:
cur_shape
=
(
train_len
,
1
)
train_label
[
output_name
]
=
mx
.
nd
.
zeros
(
cur_shape
)
for
i
in
range
(
train_len
):
output
=
self
.
preprocess_data
(
instance
,
inp
,
i
,
train_h5
)
for
input_name
in
self
.
_input_names_
:
train_data
[
input_name
][
i
]
=
getattr
(
output
,
input_name
+
"_out"
)
for
output_name
in
self
.
_output_names_
:
train_label
[
output_name
][
i
]
=
getattr
(
shape_output
,
output_name
+
"_out"
)
for
input_name
in
self
.
_input_names_
:
data_mean
[
input_name
+
'_'
]
=
nd
.
array
(
train_data
[
input_name
][:].
mean
(
axis
=
0
))
data_std
[
input_name
+
'_'
]
=
nd
.
array
(
train_data
[
input_name
][:].
asnumpy
().
std
(
axis
=
0
)
+
1e-5
)
train_iter
=
mx
.
io
.
NDArrayIter
(
data
=
train_data
,
label
=
train_label
,
batch_size
=
batch_size
)
test_data
=
{}
test_label
=
{}
shape_output
=
self
.
preprocess_data
(
instance
,
inp
,
0
,
test_h5
)
test_len
=
len
(
test_h5
[
self
.
_input_names_
[
0
]])
for
input_name
in
self
.
_input_names_
:
if
type
(
getattr
(
shape_output
,
input_name
+
"_out"
))
==
np
.
ndarray
:
cur_shape
=
(
test_len
,)
+
getattr
(
shape_output
,
input_name
+
"_out"
).
shape
else
:
cur_shape
=
(
test_len
,
1
)
test_data
[
input_name
]
=
mx
.
nd
.
zeros
(
cur_shape
)
for
output_name
in
self
.
_output_names_
:
if
type
(
getattr
(
shape_output
,
output_name
+
"_out"
))
==
nd
.
array
:
cur_shape
=
(
test_len
,)
+
getattr
(
shape_output
,
output_name
+
"_out"
).
shape
else
:
cur_shape
=
(
test_len
,
1
)
test_label
[
output_name
]
=
mx
.
nd
.
zeros
(
cur_shape
)
for
i
in
range
(
test_len
):
output
=
self
.
preprocess_data
(
instance
,
inp
,
i
,
test_h5
)
for
input_name
in
self
.
_input_names_
:
test_data
[
input_name
][
i
]
=
getattr
(
output
,
input_name
+
"_out"
)
for
output_name
in
self
.
_output_names_
:
test_label
[
output_name
][
i
]
=
getattr
(
shape_output
,
output_name
+
"_out"
)
test_iter
=
mx
.
io
.
NDArrayIter
(
data
=
test_data
,
label
=
test_label
,
batch_size
=
batch_size
)
return
train_iter
,
test_iter
,
data_mean
,
data_std
def
preprocess_data
(
self
,
instance_wrapper
,
input_wrapper
,
index
,
data_h5
):
for
input_name
in
self
.
_input_names_
:
data
=
data_h5
[
input_name
][
0
]
attr
=
getattr
(
input_wrapper
,
input_name
)
if
(
type
(
data
))
==
np
.
ndarray
:
data
=
np
.
asfortranarray
(
data
).
astype
(
attr
.
dtype
)
else
:
data
=
type
(
attr
)(
data
)
setattr
(
input_wrapper
,
input_name
,
data
)
for
output_name
in
self
.
_output_names_
:
data
=
data_h5
[
output_name
][
0
]
attr
=
getattr
(
input_wrapper
,
output_name
)
if
(
type
(
data
))
==
np
.
ndarray
:
data
=
np
.
asfortranarray
(
data
).
astype
(
attr
.
dtype
)
else
:
data
=
type
(
attr
)(
data
)
setattr
(
input_wrapper
,
output_name
,
data
)
return
instance_wrapper
.
execute
(
input_wrapper
)
def
load_h5_files
(
self
):
train_h5
=
None
test_h5
=
None
...
...
src/test/resources/target_code/gluon/CNNNet_mnist_mnistClassifier_net.py
View file @
18fe21dd
import
mxnet
as
mx
import
numpy
as
np
import
math
from
mxnet
import
gluon
...
...
@@ -147,3 +148,16 @@ class Net_0(gluon.HybridBlock):
return
predictions_
def
getInputs
(
self
):
inputs
=
{}
input_dimensions
=
(
1
,
28
,
28
)
input_domains
=
(
int
,
0.0
,
255.0
)
inputs
[
"image_"
]
=
input_domains
+
(
input_dimensions
,)
return
inputs
def
getOutputs
(
self
):
outputs
=
{}
output_dimensions
=
(
10
,
1
,
1
)
output_domains
=
(
float
,
0.0
,
1.0
)
outputs
[
"predictions_"
]
=
output_domains
+
(
output_dimensions
,)
return
outputs
src/test/resources/target_code/gluon/reinforcementModel/cartpole/CNNDataLoader_cartpole_master_dqn.py
View file @
18fe21dd
# (c) https://github.com/MontiCore/monticore
import
os
import
h5py
import
mxnet
as
mx
import
logging
import
sys
import
numpy
as
np
import
cv2
import
importlib
from
mxnet
import
nd
class
CNNDataLoader_cartpole_master_dqn
:
...
...
@@ -19,15 +21,21 @@ class CNNDataLoader_cartpole_master_dqn:
train_data
=
{}
data_mean
=
{}
data_std
=
{}
train_images
=
{}
for
input_name
in
self
.
_input_names_
:
train_data
[
input_name
]
=
train_h5
[
input_name
]
data_mean
[
input_name
]
=
nd
.
array
(
train_h5
[
input_name
][:].
mean
(
axis
=
0
))
data_std
[
input_name
]
=
nd
.
array
(
train_h5
[
input_name
][:].
std
(
axis
=
0
)
+
1e-5
)
data_mean
[
input_name
+
'_'
]
=
nd
.
array
(
train_h5
[
input_name
][:].
mean
(
axis
=
0
))
data_std
[
input_name
+
'_'
]
=
nd
.
array
(
train_h5
[
input_name
][:].
std
(
axis
=
0
)
+
1e-5
)
if
'images'
in
train_h5
:
train_images
=
train_h5
[
'images'
]
train_label
=
{}
index
=
0
for
output_name
in
self
.
_output_names_
:
train_label
[
output_name
]
=
train_h5
[
output_name
]
train_label
[
index
]
=
train_h5
[
output_name
]
index
+=
1
train_iter
=
mx
.
io
.
NDArrayIter
(
data
=
train_data
,
label
=
train_label
,
...
...
@@ -37,19 +45,163 @@ class CNNDataLoader_cartpole_master_dqn:
if
test_h5
!=
None
:
test_data
=
{}
test_images
=
{}
for
input_name
in
self
.
_input_names_
:
test_data
[
input_name
]
=
test_h5
[
input_name
]
if
'images'
in
test_h5
:
test_images
=
test_h5
[
'images'
]
test_label
=
{}
index
=
0
for
output_name
in
self
.
_output_names_
:
test_label
[
output_name
]
=
test_h5
[
output_name
]
test_label
[
index
]
=
test_h5
[
output_name
]
index
+=
1
test_iter
=
mx
.
io
.
NDArrayIter
(
data
=
test_data
,
label
=
test_label
,
batch_size
=
batch_size
)
return
train_iter
,
test_iter
,
data_mean
,
data_std
,
train_images
,
test_images
def
load_data_img
(
self
,
batch_size
,
img_size
):
train_h5
,
test_h5
=
self
.
load_h5_files
()
width
=
img_size
[
0
]
height
=
img_size
[
1
]
comb_data
=
{}
data_mean
=
{}
data_std
=
{}
for
input_name
in
self
.
_input_names_
:
train_data
=
train_h5
[
input_name
][:]
test_data
=
test_h5
[
input_name
][:]
train_shape
=
train_data
.
shape
test_shape
=
test_data
.
shape
comb_data
[
input_name
]
=
mx
.
nd
.
zeros
((
train_shape
[
0
]
+
test_shape
[
0
],
train_shape
[
1
],
width
,
height
))
for
i
,
img
in
enumerate
(
train_data
):
img
=
img
.
transpose
(
1
,
2
,
0
)
comb_data
[
input_name
][
i
]
=
cv2
.
resize
(
img
,
(
width
,
height
)).
reshape
((
train_shape
[
1
],
width
,
height
))
for
i
,
img
in
enumerate
(
test_data
):
img
=
img
.
transpose
(
1
,
2
,
0
)
comb_data
[
input_name
][
i
+
train_shape
[
0
]]
=
cv2
.
resize
(
img
,
(
width
,
height
)).
reshape
((
train_shape
[
1
],
width
,
height
))
data_mean
[
input_name
+
'_'
]
=
nd
.
array
(
comb_data
[
input_name
][:].
mean
(
axis
=
0
))
data_std
[
input_name
+
'_'
]
=
nd
.
array
(
comb_data
[
input_name
][:].
asnumpy
().
std
(
axis
=
0
)
+
1e-5
)
comb_label
=
{}
for
output_name
in
self
.
_output_names_
:
train_labels
=
train_h5
[
output_name
][:]
test_labels
=
test_h5
[
output_name
][:]
comb_label
[
output_name
]
=
np
.
append
(
train_labels
,
test_labels
,
axis
=
0
)
train_iter
=
mx
.
io
.
NDArrayIter
(
data
=
comb_data
,
label
=
comb_label
,
batch_size
=
batch_size
)
test_iter
=
None
return
train_iter
,
test_iter
,
data_mean
,
data_std
def
load_preprocessed_data
(
self
,
batch_size
,
preproc_lib
):
train_h5
,
test_h5
=
self
.
load_h5_files
()
wrapper
=
importlib
.
import_module
(
preproc_lib
)
instance
=
getattr
(
wrapper
,
preproc_lib
)()
instance
.
init
()
lib_head
,
_sep
,
tail
=
preproc_lib
.
rpartition
(
'_'
)
inp
=
getattr
(
wrapper
,
lib_head
+
"_input"
)()
train_data
=
{}
train_label
=
{}
data_mean
=
{}
data_std
=
{}
shape_output
=
self
.
preprocess_data
(
instance
,
inp
,
0
,
train_h5
)
train_len
=
len
(
train_h5
[
self
.
_input_names_
[
0
]])
for
input_name
in
self
.
_input_names_
:
if
type
(
getattr
(
shape_output
,
input_name
+
"_out"
))
==
np
.
ndarray
:
cur_shape
=
(
train_len
,)
+
getattr
(
shape_output
,
input_name
+
"_out"
).
shape
else
:
cur_shape
=
(
train_len
,
1
)
train_data
[
input_name
]
=
mx
.
nd
.
zeros
(
cur_shape
)
for
output_name
in
self
.
_output_names_
:
if
type
(
getattr
(
shape_output
,
output_name
+
"_out"
))
==
nd
.
array
:
cur_shape
=
(
train_len
,)
+
getattr
(
shape_output
,
output_name
+
"_out"
).
shape
else
:
cur_shape
=
(
train_len
,
1
)
train_label
[
output_name
]
=
mx
.
nd
.
zeros
(
cur_shape
)
for
i
in
range
(
train_len
):
output
=
self
.
preprocess_data
(
instance
,
inp
,
i
,
train_h5
)
for
input_name
in
self
.
_input_names_
:
train_data
[
input_name
][
i
]
=
getattr
(
output
,
input_name
+
"_out"
)
for
output_name
in
self
.
_output_names_
:
train_label
[
output_name
][
i
]
=
getattr
(
shape_output
,
output_name
+
"_out"
)
for
input_name
in
self
.
_input_names_
:
data_mean
[
input_name
+
'_'
]
=
nd
.
array
(
train_data
[
input_name
][:].
mean
(
axis
=
0
))
data_std
[
input_name
+
'_'
]
=
nd
.
array
(
train_data
[
input_name
][:].
asnumpy
().
std
(
axis
=
0
)
+
1e-5
)
train_iter
=
mx
.
io
.
NDArrayIter
(
data
=
train_data
,
label
=
train_label
,
batch_size
=
batch_size
)
test_data
=
{}
test_label
=
{}
shape_output
=
self
.
preprocess_data
(
instance
,
inp
,
0
,
test_h5
)
test_len
=
len
(
test_h5
[
self
.
_input_names_
[
0
]])
for
input_name
in
self
.
_input_names_
:
if
type
(
getattr
(
shape_output
,
input_name
+
"_out"
))
==
np
.
ndarray
:
cur_shape
=
(
test_len
,)
+
getattr
(
shape_output
,
input_name
+
"_out"
).
shape
else
:
cur_shape
=
(
test_len
,
1
)
test_data
[
input_name
]
=
mx
.
nd
.
zeros
(
cur_shape
)
for
output_name
in
self
.
_output_names_
:
if
type
(
getattr
(
shape_output
,
output_name
+
"_out"
))
==
nd
.
array
:
cur_shape
=
(
test_len
,)
+
getattr
(
shape_output
,
output_name
+
"_out"
).
shape
else
:
cur_shape
=
(
test_len
,
1
)
test_label
[
output_name
]
=
mx
.
nd
.
zeros
(
cur_shape
)
for
i
in
range
(
test_len
):
output
=
self
.
preprocess_data
(
instance
,
inp
,
i
,
test_h5
)
for
input_name
in
self
.
_input_names_
:
test_data
[
input_name
][
i
]
=
getattr
(
output
,
input_name
+
"_out"
)
for
output_name
in
self
.
_output_names_
:
test_label
[
output_name
][
i
]
=
getattr
(
shape_output
,
output_name
+
"_out"
)
test_iter
=
mx
.
io
.
NDArrayIter
(
data
=
test_data
,
label
=
test_label
,
batch_size
=
batch_size
)
return
train_iter
,
test_iter
,
data_mean
,
data_std
def
preprocess_data
(
self
,
instance_wrapper
,
input_wrapper
,
index
,
data_h5
):
for
input_name
in
self
.
_input_names_
:
data
=
data_h5
[
input_name
][
0
]
attr
=
getattr
(
input_wrapper
,
input_name
)
if
(
type
(
data
))
==
np
.
ndarray
:
data
=
np
.
asfortranarray
(
data
).
astype
(
attr
.
dtype
)
else
:
data
=
type
(
attr
)(
data
)
setattr
(
input_wrapper
,
input_name
,
data
)
for
output_name
in
self
.
_output_names_
:
data
=
data_h5
[
output_name
][
0
]
attr
=
getattr
(
input_wrapper
,
output_name
)
if
(
type
(
data
))
==
np
.
ndarray
:
data
=
np
.
asfortranarray
(
data
).
astype
(
attr
.
dtype
)
else
:
data
=
type
(
attr
)(
data
)
setattr
(
input_wrapper
,
output_name
,
data
)
return
instance_wrapper
.
execute
(
input_wrapper
)
def
load_h5_files
(
self
):
train_h5
=
None
test_h5
=
None
...
...
src/test/resources/target_code/gluon/reinforcementModel/cartpole/CNNNet_cartpole_master_dqn.py
View file @
18fe21dd
import
mxnet
as
mx
import
numpy
as
np
import
math
from
mxnet
import
gluon
...
...
@@ -122,3 +123,16 @@ class Net_0(gluon.HybridBlock):
return
qvalues_
def
getInputs
(
self
):
inputs
=
{}
input_dimensions
=
(
4
)
input_domains
=
(
float
,
float
(
'-inf'
),
float
(
'inf'
))
inputs
[
"state_"
]
=
input_domains
+
(
input_dimensions
,)
return
inputs
def
getOutputs
(
self
):
outputs
=
{}
output_dimensions
=
(
2
,
1
,
1
)
output_domains
=
(
float
,
float
(
'-inf'
),
float
(
'inf'
))
outputs
[
"qvalues_"
]
=
output_domains
+
(
output_dimensions
,)
return
outputs
src/test/resources/target_code/gluon/reinforcementModel/mountaincar/CNNDataLoader_mountaincar_master_actor.py
View file @
18fe21dd
# (c) https://github.com/MontiCore/monticore
import
os
import
h5py
import
mxnet
as
mx
import
logging
import
sys
import
numpy
as
np
import
cv2
import
importlib
from
mxnet
import
nd
class
CNNDataLoader_mountaincar_master_actor
:
...
...
@@ -19,15 +21,21 @@ class CNNDataLoader_mountaincar_master_actor:
train_data
=
{}
data_mean
=
{}
data_std
=
{}
train_images
=
{}
for
input_name
in
self
.
_input_names_
:
train_data
[
input_name
]
=
train_h5
[
input_name
]
data_mean
[
input_name
]
=
nd
.
array
(
train_h5
[
input_name
][:].
mean
(
axis
=
0
))
data_std
[
input_name
]
=
nd
.
array
(
train_h5
[
input_name
][:].
std
(
axis
=
0
)
+
1e-5
)
data_mean
[
input_name
+
'_'
]
=
nd
.
array
(
train_h5
[
input_name
][:].
mean
(
axis
=
0
))
data_std
[
input_name
+
'_'
]
=
nd
.
array
(
train_h5
[
input_name
][:].
std
(
axis
=
0
)
+
1e-5
)
if
'images'
in
train_h5
:
train_images
=
train_h5
[
'images'
]
train_label
=
{}
index
=
0
for
output_name
in
self
.
_output_names_
:
train_label
[
output_name
]
=
train_h5
[
output_name
]
train_label
[
index
]
=
train_h5
[
output_name
]
index
+=
1
train_iter
=
mx
.
io
.
NDArrayIter
(
data
=
train_data
,
label
=
train_label
,
...
...
@@ -37,19 +45,163 @@ class CNNDataLoader_mountaincar_master_actor:
if
test_h5
!=
None
:
test_data
=
{}
test_images
=
{}
for
input_name
in
self
.
_input_names_
:
test_data
[
input_name
]
=
test_h5
[
input_name
]
if
'images'
in
test_h5
:
test_images
=
test_h5
[
'images'
]
test_label
=
{}
index
=
0
for
output_name
in
self
.
_output_names_
:
test_label
[
output_name
]
=
test_h5
[
output_name
]
test_label
[
index
]
=
test_h5
[
output_name
]
index
+=
1
test_iter
=
mx
.
io
.
NDArrayIter
(
data
=
test_data
,
label
=
test_label
,
batch_size
=
batch_size
)
return
train_iter
,
test_iter
,
data_mean
,
data_std
,
train_images
,
test_images
def
load_data_img
(
self
,
batch_size
,
img_size
):
train_h5
,
test_h5
=
self
.
load_h5_files
()
width
=
img_size
[
0
]
height
=
img_size
[
1
]
comb_data
=
{}
data_mean
=
{}
data_std
=
{}
for
input_name
in
self
.
_input_names_
:
train_data
=
train_h5
[
input_name
][:]
test_data
=
test_h5
[
input_name
][:]
train_shape
=
train_data
.
shape
test_shape
=
test_data
.
shape
comb_data
[
input_name
]
=
mx
.
nd
.
zeros
((
train_shape
[
0
]
+
test_shape
[
0
],
train_shape
[
1
],
width
,
height
))
for
i
,
img
in
enumerate
(
train_data
):
img
=
img
.
transpose
(
1
,
2
,
0
)
comb_data
[
input_name
][
i
]
=
cv2
.
resize
(
img
,
(
width
,
height
)).
reshape
((
train_shape
[
1
],
width
,
height
))
for
i
,
img
in
enumerate
(
test_data
):
img
=
img
.
transpose
(
1
,
2
,
0
)
comb_data
[
input_name
][
i
+
train_shape
[
0
]]
=
cv2
.
resize
(
img
,
(
width
,
height
)).
reshape
((
train_shape
[
1
],
width
,
height
))
data_mean
[
input_name
+
'_'
]
=
nd
.
array
(
comb_data
[
input_name
][:].
mean
(
axis
=
0
))
data_std
[
input_name
+
'_'
]
=
nd
.
array
(
comb_data
[
input_name
][:].
asnumpy
().
std
(
axis
=
0
)
+
1e-5
)
comb_label
=
{}
for
output_name
in
self
.
_output_names_
:
train_labels
=
train_h5
[
output_name
][:]
test_labels
=
test_h5
[
output_name
][:]
comb_label
[
output_name
]
=
np
.
append
(
train_labels
,
test_labels
,
axis
=
0
)
train_iter
=
mx
.
io
.
NDArrayIter
(
data
=
comb_data
,
label
=
comb_label
,
batch_size
=
batch_size
)
test_iter
=
None
return
train_iter
,
test_iter
,
data_mean
,
data_std
def
load_preprocessed_data
(
self
,
batch_size
,
preproc_lib
):
train_h5
,
test_h5
=
self
.
load_h5_files
()
wrapper
=
importlib
.
import_module
(
preproc_lib
)
instance
=
getattr
(
wrapper
,
preproc_lib
)()
instance
.
init
()
lib_head
,
_sep
,
tail
=
preproc_lib
.
rpartition
(
'_'
)
inp
=
getattr
(
wrapper
,
lib_head
+
"_input"
)()
train_data
=
{}
train_label
=
{}
data_mean
=
{}
data_std
=
{}
shape_output
=
self
.
preprocess_data
(
instance
,
inp
,
0
,
train_h5
)
train_len
=
len
(
train_h5
[
self
.
_input_names_
[
0
]])
for
input_name
in
self
.
_input_names_
:
if
type
(
getattr
(
shape_output
,
input_name
+
"_out"
))
==
np
.
ndarray
:
cur_shape
=
(
train_len
,)
+
getattr
(
shape_output
,
input_name
+
"_out"
).
shape
else
:
cur_shape
=
(
train_len
,
1
)
train_data
[
input_name
]
=
mx
.
nd
.
zeros
(
cur_shape
)
for
output_name
in
self
.
_output_names_
:
if
type
(
getattr
(
shape_output
,
output_name
+
"_out"
))
==
nd
.
array
:
cur_shape
=
(
train_len
,)
+
getattr
(
shape_output
,
output_name
+
"_out"
).
shape
else
:
cur_shape
=
(
train_len
,
1
)
train_label
[
output_name
]
=
mx
.
nd
.
zeros
(
cur_shape
)
for
i
in
range
(
train_len
):
output
=
self
.
preprocess_data
(
instance
,
inp
,
i
,
train_h5
)
for
input_name
in
self
.
_input_names_
:
train_data
[
input_name
][
i
]
=
getattr
(
output
,
input_name
+
"_out"
)
for
output_name
in
self
.
_output_names_
:
train_label
[
output_name
][
i
]
=
getattr
(
shape_output
,
output_name
+
"_out"
)
for
input_name
in
self
.
_input_names_
:
data_mean
[
input_name
+
'_'
]
=
nd
.
array
(
train_data
[
input_name
][:].
mean
(
axis
=
0
))
data_std
[
input_name
+
'_'
]
=
nd
.
array
(
train_data
[
input_name
][:].
asnumpy
().
std
(
axis
=
0
)
+
1e-5
)
train_iter
=
mx
.
io
.
NDArrayIter
(
data
=
train_data
,
label
=
train_label
,
batch_size
=
batch_size
)
test_data
=
{}
test_label
=
{}
shape_output
=
self
.
preprocess_data
(
instance
,
inp
,
0
,
test_h5
)
test_len
=
len
(
test_h5
[
self
.
_input_names_
[
0
]])
for
input_name
in
self
.
_input_names_
:
if
type
(
getattr
(
shape_output
,
input_name
+
"_out"
))
==
np
.
ndarray
:
cur_shape
=
(
test_len
,)
+
getattr
(
shape_output
,
input_name
+
"_out"
).
shape
else
:
cur_shape
=
(
test_len
,
1
)
test_data
[
input_name
]
=
mx
.
nd
.
zeros
(
cur_shape
)
for
output_name
in
self
.
_output_names_
:
if
type
(
getattr
(
shape_output
,
output_name
+
"_out"
))
==
nd
.
array
:
cur_shape
=
(
test_len
,)
+
getattr
(
shape_output
,
output_name
+
"_out"
).
shape
else
:
cur_shape
=
(
test_len
,
1
)
test_label
[
output_name
]
=
mx
.
nd
.
zeros
(
cur_shape
)