Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MetaRL
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Wang, Mia
MetaRL
Commits
0db87838
Commit
0db87838
authored
2 years ago
by
Mia Wang
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of gitlab.doc.ic.ac.uk:yw21218/metarl
parents
b6beb405
5d89c89e
No related branches found
No related tags found
No related merge requests found
Pipeline
#272853
failed
2 years ago
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
04_22_evo.py
+1
-1
1 addition, 1 deletion
04_22_evo.py
autoaug/autoaugment_learners/GenLearner.py
+89
-15
89 additions, 15 deletions
autoaug/autoaugment_learners/GenLearner.py
benchmark/pickles/04_22_cf_ln_rssad.pkl
+0
-0
0 additions, 0 deletions
benchmark/pickles/04_22_cf_ln_rssad.pkl
with
90 additions
and
16 deletions
04_22_evo.py
+
1
−
1
View file @
0db87838
...
@@ -76,7 +76,7 @@ def run_benchmark(
...
@@ -76,7 +76,7 @@ def run_benchmark(
train_dataset
=
train_dataset
,
train_dataset
=
train_dataset
,
test_dataset
=
test_dataset
,
test_dataset
=
test_dataset
,
child_network_architecture
=
child_network_architecture
,
child_network_architecture
=
child_network_architecture
,
iterations
=
1
iterations
=
5
)
)
# save agent every iteration
# save agent every iteration
with
open
(
save_file
,
'
wb+
'
)
as
f
:
with
open
(
save_file
,
'
wb+
'
)
as
f
:
...
...
This diff is collapsed.
Click to expand it.
autoaug/autoaugment_learners/GenLearner.py
+
89
−
15
View file @
0db87838
...
@@ -83,6 +83,13 @@ class Genetic_learner(AaLearner):
...
@@ -83,6 +83,13 @@ class Genetic_learner(AaLearner):
def
gen_random_subpol
(
self
):
def
gen_random_subpol
(
self
):
"""
Generates a random subpolicy using the reduced augmentation_space
Returns
--------
subpolicy -> ((transformation, probability, magnitude), (trans., prob., mag.))
"""
choose_items
=
[
x
[
0
]
for
x
in
self
.
augmentation_space
]
choose_items
=
[
x
[
0
]
for
x
in
self
.
augmentation_space
]
trans1
=
str
(
random
.
choice
(
choose_items
))
trans1
=
str
(
random
.
choice
(
choose_items
))
trans2
=
str
(
random
.
choice
(
choose_items
))
trans2
=
str
(
random
.
choice
(
choose_items
))
...
@@ -104,30 +111,50 @@ class Genetic_learner(AaLearner):
...
@@ -104,30 +111,50 @@ class Genetic_learner(AaLearner):
def
gen_random_policy
(
self
):
def
gen_random_policy
(
self
):
"""
Generates a random policy, consisting of sp_num subpolicies
Returns
------------
policy -> [subpolicy, subpolicy, ...]
"""
pol
=
[]
pol
=
[]
for
_
in
range
(
self
.
sp_num
):
for
_
in
range
(
self
.
sp_num
):
pol
.
append
(
self
.
gen_random_subpol
())
pol
.
append
(
self
.
gen_random_subpol
())
return
pol
return
pol
def
bin_to_subpol
(
self
,
subpol
):
def
bin_to_subpol
(
self
,
subpol_bin
):
"""
Converts a binary string representation of a subpolicy to a subpolicy
Parameters
------------
subpol_bin -> str
Binary representation of a subpolicy
Returns
-----------
policy -> [(subpolicy)]
"""
pol
=
[]
pol
=
[]
for
idx
in
range
(
2
):
for
idx
in
range
(
2
):
if
subpol
[
idx
*
12
:(
idx
*
12
)
+
4
]
in
self
.
bin_to_aug
:
if
subpol
_bin
[
idx
*
12
:(
idx
*
12
)
+
4
]
in
self
.
bin_to_aug
:
trans
=
self
.
bin_to_aug
[
subpol
[
idx
*
12
:(
idx
*
12
)
+
4
]]
trans
=
self
.
bin_to_aug
[
subpol
_bin
[
idx
*
12
:(
idx
*
12
)
+
4
]]
else
:
else
:
trans
=
random
.
choice
(
self
.
just_augs
)
trans
=
random
.
choice
(
self
.
just_augs
)
mag_is_none
=
not
self
.
aug_space_dict
[
trans
]
mag_is_none
=
not
self
.
aug_space_dict
[
trans
]
if
subpol
[(
idx
*
12
)
+
4
:
(
idx
*
12
)
+
8
]
in
self
.
bin_to_prob
:
if
subpol
_bin
[(
idx
*
12
)
+
4
:
(
idx
*
12
)
+
8
]
in
self
.
bin_to_prob
:
prob
=
float
(
self
.
bin_to_prob
[
subpol
[(
idx
*
12
)
+
4
:
(
idx
*
12
)
+
8
]])
prob
=
float
(
self
.
bin_to_prob
[
subpol
_bin
[(
idx
*
12
)
+
4
:
(
idx
*
12
)
+
8
]])
else
:
else
:
prob
=
float
(
random
.
randrange
(
0
,
11
,
1
)
/
10
)
prob
=
float
(
random
.
randrange
(
0
,
11
,
1
)
/
10
)
if
subpol
[(
idx
*
12
)
+
8
:(
idx
*
12
)
+
12
]
in
self
.
bin_to_mag
:
if
subpol
_bin
[(
idx
*
12
)
+
8
:(
idx
*
12
)
+
12
]
in
self
.
bin_to_mag
:
mag
=
int
(
self
.
bin_to_mag
[
subpol
[(
idx
*
12
)
+
8
:(
idx
*
12
)
+
12
]])
mag
=
int
(
self
.
bin_to_mag
[
subpol
_bin
[(
idx
*
12
)
+
8
:(
idx
*
12
)
+
12
]])
else
:
else
:
mag
=
int
(
random
.
randrange
(
0
,
10
,
1
))
mag
=
int
(
random
.
randrange
(
0
,
10
,
1
))
...
@@ -139,28 +166,54 @@ class Genetic_learner(AaLearner):
...
@@ -139,28 +166,54 @@ class Genetic_learner(AaLearner):
def
subpol_to_bin
(
self
,
subpol
):
def
subpol_to_bin
(
self
,
subpol
):
pol
=
''
"""
Converts a subpolicy to its binary representation
Parameters
------------
subpol -> ((transforamtion, probability, magnitude), (trans., prob., mag.))
Returns
------------
bin_pol -> str
Binary representation of the subpolicy
"""
bin_pol
=
''
trans1
,
prob1
,
mag1
=
subpol
[
0
]
trans1
,
prob1
,
mag1
=
subpol
[
0
]
trans2
,
prob2
,
mag2
=
subpol
[
1
]
trans2
,
prob2
,
mag2
=
subpol
[
1
]
pol
+=
self
.
aug_to_bin
[
trans1
]
+
self
.
prob_to_bin
[
str
(
prob1
)]
bin_
pol
+=
self
.
aug_to_bin
[
trans1
]
+
self
.
prob_to_bin
[
str
(
prob1
)]
if
mag1
==
None
:
if
mag1
==
None
:
pol
+=
'
1111
'
bin_
pol
+=
'
1111
'
else
:
else
:
pol
+=
self
.
mag_to_bin
[
str
(
mag1
)]
bin_
pol
+=
self
.
mag_to_bin
[
str
(
mag1
)]
pol
+=
self
.
aug_to_bin
[
trans2
]
+
self
.
prob_to_bin
[
str
(
prob2
)]
bin_
pol
+=
self
.
aug_to_bin
[
trans2
]
+
self
.
prob_to_bin
[
str
(
prob2
)]
if
mag2
==
None
:
if
mag2
==
None
:
pol
+=
'
1111
'
bin_
pol
+=
'
1111
'
else
:
else
:
pol
+=
self
.
mag_to_bin
[
str
(
mag2
)]
bin_
pol
+=
self
.
mag_to_bin
[
str
(
mag2
)]
return
pol
return
bin_
pol
def
choose_parents
(
self
,
parents
,
parents_weights
):
def
choose_parents
(
self
,
parents
,
parents_weights
):
"""
Chooses parents from which the next policy will be generated from
Parameters
------------
parents -> [policy, policy, ...]
parents_weights -> [float, float, ...]
Returns
------------
(parent1, parent2) -> (policy, policy)
"""
parent1
=
random
.
choices
(
parents
,
parents_weights
,
k
=
1
)[
0
][
0
]
parent1
=
random
.
choices
(
parents
,
parents_weights
,
k
=
1
)[
0
][
0
]
parent2
=
random
.
choices
(
parents
,
parents_weights
,
k
=
1
)[
0
][
0
]
parent2
=
random
.
choices
(
parents
,
parents_weights
,
k
=
1
)[
0
][
0
]
while
parent2
==
parent1
:
while
parent2
==
parent1
:
...
@@ -171,6 +224,13 @@ class Genetic_learner(AaLearner):
...
@@ -171,6 +224,13 @@ class Genetic_learner(AaLearner):
def
generate_children
(
self
):
def
generate_children
(
self
):
"""
Generates children via the random crossover method
Returns
------------
new_pols -> [child_policy, child_policy, ...]
"""
parent_acc
=
sorted
(
self
.
history
,
key
=
lambda
x
:
x
[
1
],
reverse
=
True
)
parent_acc
=
sorted
(
self
.
history
,
key
=
lambda
x
:
x
[
1
],
reverse
=
True
)
parents
=
[
x
[
0
]
for
x
in
parent_acc
]
parents
=
[
x
[
0
]
for
x
in
parent_acc
]
parents_weights
=
[
x
[
1
]
for
x
in
parent_acc
]
parents_weights
=
[
x
[
1
]
for
x
in
parent_acc
]
...
@@ -188,6 +248,20 @@ class Genetic_learner(AaLearner):
...
@@ -188,6 +248,20 @@ class Genetic_learner(AaLearner):
def
learn
(
self
,
train_dataset
,
test_dataset
,
child_network_architecture
,
iterations
=
100
):
def
learn
(
self
,
train_dataset
,
test_dataset
,
child_network_architecture
,
iterations
=
100
):
"""
Generates policies through a genetic algorithm.
Parameters
------------
train_dataset -> torchvision.dataset
test_dataset -> torchvision.dataset
child_network_architecture ->
iterations -> int
number of iterations to run the instance for
"""
for
idx
in
range
(
iterations
):
for
idx
in
range
(
iterations
):
print
(
"
ITERATION:
"
,
idx
)
print
(
"
ITERATION:
"
,
idx
)
...
...
This diff is collapsed.
Click to expand it.
benchmark/pickles/04_22_cf_ln_rssad.pkl
0 → 100644
+
0
−
0
View file @
0db87838
File added
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment