Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.bio.base
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package 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
bob
bob.bio.base
Commits
493da265
Commit
493da265
authored
4 years ago
by
Tiago de Freitas Pereira
Browse files
Options
Downloads
Patches
Plain Diff
Memory optimizing CSVWriter
parent
f178ce66
No related branches found
No related tags found
2 merge requests
!185
Wrappers and aggregators
,
!180
[dask] Preparing bob.bio.base for dask pipelines
Pipeline
#39635
failed
4 years ago
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bob/bio/base/pipelines/vanilla_biometrics/score_writers.py
+30
-11
30 additions, 11 deletions
bob/bio/base/pipelines/vanilla_biometrics/score_writers.py
bob/bio/base/pipelines/vanilla_biometrics/wrappers.py
+3
-0
3 additions, 0 deletions
bob/bio/base/pipelines/vanilla_biometrics/wrappers.py
with
33 additions
and
11 deletions
bob/bio/base/pipelines/vanilla_biometrics/score_writers.py
+
30
−
11
View file @
493da265
...
...
@@ -34,7 +34,7 @@ class FourColumnsScoreWriter(ScoreWriter):
)
for
biometric_reference
in
probe
]
filename
=
os
.
path
.
join
(
path
,
probe
.
subject
)
+
"
.txt
"
filename
=
os
.
path
.
join
(
path
,
str
(
probe
.
subject
)
)
+
"
.txt
"
open
(
filename
,
"
w
"
).
writelines
(
lines
)
checkpointed_scores
.
append
(
SampleSet
(
...
...
@@ -69,8 +69,18 @@ class FourColumnsScoreWriter(ScoreWriter):
class
CSVScoreWriter
(
ScoreWriter
):
"""
Read and write scores in CSV format, shipping all metadata with the scores
Parameters
----------
n_sample_sets:
Number of samplesets in one chunk
"""
def
__init__
(
self
,
n_sample_sets
=
1000
):
self
.
n_sample_sets
=
n_sample_sets
def
write
(
self
,
probe_sampleset
,
path
):
"""
Write scores and returns a :any:`bob.pipelines.DelayedSample` containing
...
...
@@ -108,7 +118,7 @@ class CSVScoreWriter(ScoreWriter):
header
,
probe_dict
,
bioref_dict
=
create_csv_header
(
probe_sampleset
[
0
])
for
probe
in
probe_sampleset
:
filename
=
os
.
path
.
join
(
path
,
probe
.
subject
)
+
"
.csv
"
filename
=
os
.
path
.
join
(
path
,
str
(
probe
.
subject
)
)
+
"
.csv
"
with
open
(
filename
,
"
w
"
)
as
f
:
csv_write
=
csv
.
writer
(
f
)
...
...
@@ -150,14 +160,23 @@ class CSVScoreWriter(ScoreWriter):
"""
Given a list of samplsets, write them all in a single file
"""
os
.
makedirs
(
os
.
path
.
dirname
(
filename
),
exist_ok
=
True
)
f
=
open
(
filename
,
"
w
"
)
first
=
True
for
samplesets
in
samplesets_list
:
# CSV files tends to be very big
# here, here we write them in chunks
base_dir
=
os
.
path
.
splitext
(
filename
)[
0
]
os
.
makedirs
(
base_dir
,
exist_ok
=
True
)
f
=
None
for
i
,
samplesets
in
enumerate
(
samplesets_list
):
if
i
%
self
.
n_sample_sets
==
0
:
if
f
is
not
None
:
f
.
close
()
del
f
filename
=
os
.
path
.
join
(
base_dir
,
f
"
chunk_
{
i
}
.csv
"
)
f
=
open
(
filename
,
"
w
"
)
for
sset
in
samplesets
:
for
s
in
sset
:
if
first
:
f
.
writelines
(
s
.
data
)
first
=
False
else
:
f
.
writelines
(
s
.
data
[
1
:])
f
.
writelines
(
s
.
data
)
samplesets_list
[
i
]
=
None
\ No newline at end of file
This diff is collapsed.
Click to expand it.
bob/bio/base/pipelines/vanilla_biometrics/wrappers.py
+
3
−
0
View file @
493da265
...
...
@@ -122,6 +122,9 @@ class BioAlgorithmCheckpointWrapper(BioAlgorithm):
class
BioAlgorithmDaskWrapper
(
BioAlgorithm
):
def
__init__
(
self
,
biometric_algorithm
,
**
kwargs
):
self
.
biometric_algorithm
=
biometric_algorithm
# Copying attribute
if
hasattr
(
biometric_algorithm
,
"
score_writer
"
):
self
.
score_writer
=
biometric_algorithm
.
score_writer
def
enroll_samples
(
self
,
biometric_reference_features
):
...
...
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