Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
nni
Commits
96d30baf
Unverified
Commit
96d30baf
authored
Apr 12, 2022
by
Jiahang Xu
Committed by
GitHub
Apr 12, 2022
Browse files
Refine weight loading in SPOS (#4755)
parent
047a9e22
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
21 deletions
+24
-21
examples/nas/oneshot/spos/search.py
examples/nas/oneshot/spos/search.py
+24
-21
No files found.
examples/nas/oneshot/spos/search.py
View file @
96d30baf
...
@@ -66,14 +66,33 @@ def test_acc(model, criterion, log_freq, loader):
...
@@ -66,14 +66,33 @@ def test_acc(model, criterion, log_freq, loader):
return
meters
.
acc1
.
avg
return
meters
.
acc1
.
avg
def
evaluate_acc
(
class_cls
,
criterion
,
args
,
train_dataset
,
val_dataset
):
def
evaluate_acc
(
class_cls
,
criterion
,
args
):
model
=
class_cls
()
model
=
class_cls
()
with
original_state_dict_hooks
(
model
):
with
original_state_dict_hooks
(
model
):
model
.
load_state_dict
(
load_and_parse_state_dict
(
args
.
checkpoint
),
strict
=
False
)
model
.
load_state_dict
(
load_and_parse_state_dict
(
args
.
checkpoint
),
strict
=
False
)
model
.
cuda
()
model
.
cuda
()
train_loader
=
torch
.
utils
.
data
.
DataLoader
(
train_dataset
,
batch_size
=
args
.
train_batch_size
,
num_workers
=
args
.
workers
)
if
args
.
spos_preprocessing
:
test_loader
=
torch
.
utils
.
data
.
DataLoader
(
val_dataset
,
batch_size
=
args
.
test_batch_size
,
num_workers
=
args
.
workers
)
train_trans
=
transforms
.
Compose
([
transforms
.
RandomResizedCrop
(
224
),
transforms
.
ColorJitter
(
brightness
=
0.4
,
contrast
=
0.4
,
saturation
=
0.4
),
transforms
.
RandomHorizontalFlip
(
0.5
),
ToBGRTensor
()
])
else
:
train_trans
=
transforms
.
Compose
([
transforms
.
RandomResizedCrop
(
224
),
transforms
.
ToTensor
()
])
val_trans
=
transforms
.
Compose
([
transforms
.
RandomResizedCrop
(
224
),
ToBGRTensor
()
])
train_dataset
=
datasets
.
ImageNet
(
args
.
imagenet_dir
,
split
=
'train'
,
transform
=
train_trans
)
val_dataset
=
datasets
.
ImageNet
(
args
.
imagenet_dir
,
split
=
'val'
,
transform
=
val_trans
)
train_loader
=
torch
.
utils
.
data
.
DataLoader
(
train_dataset
,
batch_size
=
args
.
train_batch_size
,
num_workers
=
args
.
workers
,
shuffle
=
True
)
test_loader
=
torch
.
utils
.
data
.
DataLoader
(
val_dataset
,
batch_size
=
args
.
test_batch_size
,
num_workers
=
args
.
workers
,
shuffle
=
True
)
acc_before
=
test_acc
(
model
,
criterion
,
args
.
log_frequency
,
test_loader
)
acc_before
=
test_acc
(
model
,
criterion
,
args
.
log_frequency
,
test_loader
)
nni
.
report_intermediate_result
(
acc_before
)
nni
.
report_intermediate_result
(
acc_before
)
...
@@ -144,29 +163,13 @@ def _main():
...
@@ -144,29 +163,13 @@ def _main():
base_model
=
ShuffleNetV2OneShot
()
base_model
=
ShuffleNetV2OneShot
()
criterion
=
CrossEntropyLabelSmooth
(
1000
,
args
.
label_smoothing
)
criterion
=
CrossEntropyLabelSmooth
(
1000
,
args
.
label_smoothing
)
if
args
.
spos_preprocessing
:
# ``nni.trace`` is used to make transforms serializable, so that the trials can run other processes or on remote servers.
trans
=
nni
.
trace
(
transforms
.
Compose
)([
nni
.
trace
(
transforms
.
RandomResizedCrop
)(
224
),
nni
.
trace
(
transforms
.
ColorJitter
)(
brightness
=
0.4
,
contrast
=
0.4
,
saturation
=
0.4
),
nni
.
trace
(
transforms
.
RandomHorizontalFlip
)(
0.5
),
nni
.
trace
(
ToBGRTensor
)(),
])
else
:
# ``nni.trace`` is used to make transforms serializable, so that the trials can run other processes or on remote servers.
trans
=
nni
.
trace
(
transforms
.
Compose
)([
nni
.
trace
(
transforms
.
RandomResizedCrop
)(
224
),
nni
.
trace
(
transforms
.
ToTensor
)()
])
train_dataset
=
nni
.
trace
(
datasets
.
ImageNet
)(
args
.
imagenet_dir
,
split
=
'train'
,
transform
=
trans
)
val_dataset
=
nni
.
trace
(
datasets
.
ImageNet
)(
args
.
imagenet_dir
,
split
=
'val'
,
transform
=
trans
)
if
args
.
latency_filter
:
if
args
.
latency_filter
:
latency_filter
=
LatencyFilter
(
threshold
=
args
.
latency_threshold
,
predictor
=
args
.
latency_filter
)
latency_filter
=
LatencyFilter
(
threshold
=
args
.
latency_threshold
,
predictor
=
args
.
latency_filter
)
else
:
else
:
latency_filter
=
None
latency_filter
=
None
evaluator
=
FunctionalEvaluator
(
evaluate_acc
,
criterion
=
criterion
,
args
=
args
,
train_dataset
=
train_dataset
,
val_dataset
=
val_dataset
)
evaluator
=
FunctionalEvaluator
(
evaluate_acc
,
criterion
=
criterion
,
args
=
args
)
evolution_strategy
=
strategy
.
RegularizedEvolution
(
evolution_strategy
=
strategy
.
RegularizedEvolution
(
model_filter
=
latency_filter
,
model_filter
=
latency_filter
,
sample_size
=
args
.
evolution_sample_size
,
population_size
=
args
.
evolution_population_size
,
cycles
=
args
.
evolution_cycles
)
sample_size
=
args
.
evolution_sample_size
,
population_size
=
args
.
evolution_population_size
,
cycles
=
args
.
evolution_cycles
)
...
...
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