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
c335d997
You need to sign in or sign up before continuing.
Commit
c335d997
authored
4 years ago
by
Frisinghelli Daniel
Browse files
Options
Downloads
Patches
Plain Diff
Moved initialization to NetworkTrainer class
parent
42a7775d
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
main/init.py
+0
-73
0 additions, 73 deletions
main/init.py
with
0 additions
and
73 deletions
main/init.py
deleted
100755 → 0
+
0
−
73
View file @
42a7775d
# -*- coding: utf-8 -*-
"""
Created on Mon Jul 6 16:41:20 2020
@author: Daniel
"""
# builtins
import
os
import
sys
# externals
import
torch
# append path to local files to the python search path
sys
.
path
.
append
(
'
..
'
)
# local modules
from
pytorch.dataset
import
SparcsDataset
,
Cloud95Dataset
from
pytorch.trainer
import
NetworkTrainer
from
pytorch.models
import
SegNet
from
main.config
import
(
dataset_name
,
dataset_path
,
bands
,
tile_size
,
tvratio
,
filters
,
skip_connection
,
kwargs
,
loss_function
,
optimizer
,
lr
,
ttratio
,
batch_size
,
seed
,
patches
)
# check which dataset the model is trained on
if
dataset_name
==
'
Sparcs
'
:
# instanciate the SparcsDataset
dataset
=
SparcsDataset
(
dataset_path
,
use_bands
=
bands
,
tile_size
=
tile_size
)
elif
dataset_name
==
'
Cloud95
'
:
dataset
=
Cloud95Dataset
(
dataset_path
,
use_bands
=
bands
,
tile_size
=
tile_size
,
exclude
=
patches
)
else
:
raise
ValueError
(
'
{} is not a valid dataset. Available datasets are
'
'"
Sparcs
"
and
"
Cloud95
"
.
'
.
format
(
dataset_name
))
# print the bands used for the segmentation
print
(
'
------------------------ Input bands -----------------------------
'
)
print
(
*
[
'
Band {}: {}
'
.
format
(
i
,
b
)
for
i
,
b
in
enumerate
(
dataset
.
use_bands
)],
sep
=
'
\n
'
)
print
(
'
------------------------------------------------------------------
'
)
# print the classes of interest
print
(
'
-------------------------- Classes -------------------------------
'
)
print
(
*
[
'
Class {}: {}
'
.
format
(
k
,
v
[
'
label
'
])
for
k
,
v
in
dataset
.
labels
.
items
()],
sep
=
'
\n
'
)
print
(
'
------------------------------------------------------------------
'
)
# instanciate the segmentation network
print
(
'
------------------- Network architecture -------------------------
'
)
net
=
SegNet
(
in_channels
=
len
(
dataset
.
use_bands
),
nclasses
=
len
(
dataset
.
labels
),
filters
=
filters
,
skip
=
skip_connection
,
**
kwargs
)
print
(
net
)
print
(
'
------------------------------------------------------------------
'
)
# instanciate the optimizer
optimizer
=
optimizer
(
net
.
parameters
(),
lr
)
# file to save model state to
# format: networkname_datasetname_t(tilesize)_b(batchsize)_bands.pt
bformat
=
''
.
join
([
b
[
0
]
for
b
in
bands
])
if
bands
else
'
all
'
state_file
=
'
{}_{}_t{}_b{}_{}.pt
'
.
format
(
net
.
__class__
.
__name__
,
dataset
.
__class__
.
__name__
,
tile_size
,
batch_size
,
bformat
)
# instanciate NetworkTrainer class
print
(
'
------------------------ Dataset split ---------------------------
'
)
trainer
=
NetworkTrainer
(
net
,
dataset
,
loss_function
,
optimizer
,
batch_size
=
batch_size
,
tvratio
=
tvratio
,
ttratio
=
ttratio
,
seed
=
seed
)
print
(
'
------------------------------------------------------------------
'
)
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