Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PySegCNN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
earth_observation_public
PySegCNN
Commits
ee41cb57
Commit
ee41cb57
authored
4 years ago
by
Frisinghelli Daniel
Browse files
Options
Downloads
Patches
Plain Diff
Moved training initialization to dedicated script.
parent
5e68ee89
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pysegcnn/main/train.py
+72
-9
72 additions, 9 deletions
pysegcnn/main/train.py
with
72 additions
and
9 deletions
pysegcnn/main/train.py
+
72
−
9
View file @
ee41cb57
...
...
@@ -29,21 +29,84 @@ License
# !/usr/bin/env python
# -*- coding: utf-8 -*-
# builtins
from
logging.config
import
dictConfig
# locals
from
pysegcnn.core.trainer
import
NetworkTrainer
from
pysegcnn.core.trainer
import
(
DatasetConfig
,
SplitConfig
,
ModelConfig
,
StateConfig
,
LogConfig
,
MultispectralImageSegmentationTrainer
)
from
pysegcnn.main.config
import
(
src_ds_config
,
src_split_config
,
trg_ds_config
,
trg_split_config
,
model_config
)
from
pysegcnn.core.logging
import
log_conf
if
__name__
==
'
__main__
'
:
# instanciate the network trainer class
trainer
=
NetworkTrainer
.
init_network_trainer
(
src_ds_config
,
src_split_config
,
trg_ds_config
,
trg_split_config
,
model_config
)
# (x) train model
# (i) instanciate the source domain configurations
src_dc
=
DatasetConfig
(
**
src_ds_config
)
# source domain dataset
src_sc
=
SplitConfig
(
**
src_split_config
)
# source domain dataset split
# (ii) instanciate the target domain configuration
trg_dc
=
DatasetConfig
(
**
trg_ds_config
)
# target domain dataset
trg_sc
=
SplitConfig
(
**
trg_split_config
)
# target domain dataset split
# (iii) instanciate the model configuration
net_mc
=
ModelConfig
(
**
model_config
)
# (iv) instanciate the model state file
net_sc
=
StateConfig
(
src_dc
,
src_sc
,
trg_dc
,
trg_sc
,
net_mc
)
state_file
=
net_sc
.
init_state
()
# (v) instanciate logging configuration
net_lc
=
LogConfig
(
state_file
)
dictConfig
(
log_conf
(
net_lc
.
log_file
))
# (vi) instanciate the datasets to train the model on
src_ds
=
src_dc
.
init_dataset
()
trg_ds
=
trg_dc
.
init_dataset
()
# (vii) instanciate the training, validation and test datasets and
# dataloaders for the source domain
src_tra_ds
,
src_val_ds
,
src_tes_ds
=
src_sc
.
train_val_test_split
(
src_ds
)
src_tra_dl
,
src_val_dl
,
src_tes_dl
=
src_sc
.
dataloaders
(
src_tra_ds
,
src_val_ds
,
src_tes_ds
,
batch_size
=
net_mc
.
batch_size
,
shuffle
=
True
,
drop_last
=
False
)
# (viii) instanciate the training, validation and test datasets and
# dataloaders dor the target domain
trg_tra_ds
,
trg_val_ds
,
trg_tes_ds
=
trg_sc
.
train_val_test_split
(
trg_ds
)
trg_tra_dl
,
trg_val_dl
,
trg_tes_dl
=
trg_sc
.
dataloaders
(
trg_tra_ds
,
trg_val_ds
,
trg_tes_ds
,
batch_size
=
net_mc
.
batch_size
,
shuffle
=
True
,
drop_last
=
False
)
# (ix) instanciate the model
net
,
optimizer
,
checkpoint
=
net_mc
.
init_model
(
src_ds
,
state_file
)
# (x) instanciate the network trainer class
trainer
=
MultispectralImageSegmentationTrainer
(
model
=
net
,
optimizer
=
optimizer
,
state_file
=
net
.
state_file
,
src_train_dl
=
src_tra_dl
,
src_valid_dl
=
src_val_dl
,
src_test_dl
=
src_tes_dl
,
epochs
=
net_mc
.
epochs
,
nthreads
=
net_mc
.
nthreads
,
early_stop
=
net_mc
.
early_stop
,
mode
=
net_mc
.
mode
,
delta
=
net_mc
.
delta
,
patience
=
net_mc
.
patience
,
checkpoint_state
=
checkpoint
,
save
=
net_mc
.
save
,
supervised
=
net_mc
.
supervised
,
trg_train_dl
=
trg_tra_dl
,
trg_valid_dl
=
trg_val_dl
,
trg_test_dl
=
trg_tes_dl
,
uda_loss_function
=
net_mc
.
init_uda_loss_function
(),
uda_lambda
=
net_mc
.
uda_lambda
,
uda_pos
=
net_mc
.
uda_pos
)
# (xi) train the model
training_state
=
trainer
.
train
()
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