Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
iamap
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
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
AMAP
iamap
Commits
ee8f0f94
Commit
ee8f0f94
authored
6 months ago
by
paul.tresson_ird.fr
Browse files
Options
Downloads
Patches
Plain Diff
save parameters to json in the output_subdir
parent
c9204126
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
encoder.py
+29
-11
29 additions, 11 deletions
encoder.py
with
29 additions
and
11 deletions
encoder.py
+
29
−
11
View file @
ee8f0f94
...
@@ -9,6 +9,7 @@ import shutil
...
@@ -9,6 +9,7 @@ import shutil
import
numpy
as
np
import
numpy
as
np
from
pathlib
import
Path
from
pathlib
import
Path
from
typing
import
Dict
,
Any
from
typing
import
Dict
,
Any
import
json
import
rasterio
import
rasterio
from
qgis.PyQt.QtCore
import
QCoreApplication
from
qgis.PyQt.QtCore
import
QCoreApplication
...
@@ -52,6 +53,7 @@ from .utils.misc import (QGISLogHandler,
...
@@ -52,6 +53,7 @@ from .utils.misc import (QGISLogHandler,
remove_files
,
remove_files
,
check_disk_space
,
check_disk_space
,
get_unique_filename
,
get_unique_filename
,
convert_qvariant
,
)
)
...
@@ -331,6 +333,20 @@ class EncoderAlgorithm(QgsProcessingAlgorithm):
...
@@ -331,6 +333,20 @@ class EncoderAlgorithm(QgsProcessingAlgorithm):
"""
"""
self
.
process_options
(
parameters
,
context
,
feedback
)
self
.
process_options
(
parameters
,
context
,
feedback
)
## compute parameters hash to have a unique identifier for the run
## some parameters do not change the encoding part of the algorithm
keys_to_remove
=
[
'
MERGE_METHOD
'
,
'
WORKERS
'
,
'
PAUSES
'
]
param_encoder
=
{
key
:
parameters
[
key
]
for
key
in
parameters
if
key
not
in
keys_to_remove
}
param_hash
=
hashlib
.
md5
(
str
(
param_encoder
).
encode
(
"
utf-8
"
)).
hexdigest
()
output_subdir
=
os
.
path
.
join
(
self
.
output_dir
,
param_hash
)
output_subdir
=
Path
(
output_subdir
)
output_subdir
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
self
.
output_subdir
=
output_subdir
feedback
.
pushInfo
(
f
'
output_subdir:
{
output_subdir
}
'
)
self
.
save_parameters_to_json
(
parameters
)
feedback
.
pushInfo
(
f
'
saving parameters to json file
'
)
RasterDataset
.
filename_glob
=
self
.
rlayer_name
RasterDataset
.
filename_glob
=
self
.
rlayer_name
RasterDataset
.
all_bands
=
[
RasterDataset
.
all_bands
=
[
self
.
rlayer
.
bandName
(
i_band
)
for
i_band
in
range
(
1
,
self
.
rlayer
.
bandCount
()
+
1
)
self
.
rlayer
.
bandName
(
i_band
)
for
i_band
in
range
(
1
,
self
.
rlayer
.
bandCount
()
+
1
)
...
@@ -457,17 +473,6 @@ class EncoderAlgorithm(QgsProcessingAlgorithm):
...
@@ -457,17 +473,6 @@ class EncoderAlgorithm(QgsProcessingAlgorithm):
feedback
.
pushInfo
(
f
'
Total batch num:
{
len
(
dataloader
)
}
'
)
feedback
.
pushInfo
(
f
'
Total batch num:
{
len
(
dataloader
)
}
'
)
feedback
.
pushInfo
(
f
'
\n\n
{
"
-
"
*
16
}
\n
Begining inference
\n
{
"
-
"
*
16
}
\n\n
'
)
feedback
.
pushInfo
(
f
'
\n\n
{
"
-
"
*
16
}
\n
Begining inference
\n
{
"
-
"
*
16
}
\n\n
'
)
## compute parameters hash to have a unique identifier for the run
## some parameters do not change the encoding part of the algorithm
keys_to_remove
=
[
'
MERGE_METHOD
'
,
'
WORKERS
'
,
'
PAUSES
'
]
param_encoder
=
{
key
:
parameters
[
key
]
for
key
in
parameters
if
key
not
in
keys_to_remove
}
param_hash
=
hashlib
.
md5
(
str
(
param_encoder
).
encode
(
"
utf-8
"
)).
hexdigest
()
output_subdir
=
os
.
path
.
join
(
self
.
output_dir
,
param_hash
)
output_subdir
=
Path
(
output_subdir
)
output_subdir
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
self
.
output_subdir
=
output_subdir
feedback
.
pushInfo
(
f
'
output_subdir:
{
output_subdir
}
'
)
last_batch_done
=
self
.
get_last_batch_done
()
last_batch_done
=
self
.
get_last_batch_done
()
...
@@ -637,6 +642,19 @@ class EncoderAlgorithm(QgsProcessingAlgorithm):
...
@@ -637,6 +642,19 @@ class EncoderAlgorithm(QgsProcessingAlgorithm):
return
{
"
Output feature path
"
:
self
.
output_subdir
,
'
Patch samples saved
'
:
self
.
iPatch
,
'
OUTPUT_RASTER
'
:
dst_path
,
'
OUTPUT_LAYER_NAME
'
:
layer_name
}
return
{
"
Output feature path
"
:
self
.
output_subdir
,
'
Patch samples saved
'
:
self
.
iPatch
,
'
OUTPUT_RASTER
'
:
dst_path
,
'
OUTPUT_LAYER_NAME
'
:
layer_name
}
def
save_parameters_to_json
(
self
,
parameters
):
dst_path
=
os
.
path
.
join
(
self
.
output_subdir
,
'
parameters.json
'
)
## convert_qvariant does not work properly for 'CKPT'
## converting it to a str
converted_parameters
=
convert_qvariant
(
parameters
)
print
(
parameters
)
converted_parameters
[
'
CKPT
'
]
=
str
(
converted_parameters
[
'
CKPT
'
])
for
key
,
item
in
converted_parameters
.
items
():
print
(
key
,
type
(
item
))
with
open
(
dst_path
,
"
w
"
)
as
json_file
:
json
.
dump
(
converted_parameters
,
json_file
,
indent
=
4
)
def
remove_temp_files
(
self
):
def
remove_temp_files
(
self
):
"""
"""
cleaning up temp tiles
cleaning up temp tiles
...
...
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