Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Generic Training Dataset
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
Arkindex
Workers
Generic Training Dataset
Merge requests
!2
Implement worker
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Implement worker
implem
into
main
Overview
80
Commits
25
Pipelines
1
Changes
2
Merged
Yoann Schneider
requested to merge
implem
into
main
1 year ago
Overview
80
Commits
25
Pipelines
1
Changes
2
Expand
Closes
#2 (closed)
0
0
Merge request reports
Viewing commit
48f686bf
Prev
Next
Show latest version
2 files
+
6
−
25
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
Verified
48f686bf
use new rc
· 48f686bf
Yoann Schneider
authored
1 year ago
worker_generic_training_dataset/utils.py
+
5
−
24
Options
# -*- coding: utf-8 -*-
import
ast
import
logging
import
os
import
tarfile
import
tempfile
import
time
from
pathlib
import
Path
from
urllib.parse
import
urljoin
import
cv2
import
imageio.v2
as
iio
import
zstandard
as
zstd
from
arkindex_worker.utils
import
close_delete_file
,
create_tar_archive
,
zstd_compress
from
worker_generic_training_dataset.exceptions
import
ImageDownloadError
logger
=
logging
.
getLogger
(
__name__
)
@@ -58,25 +55,9 @@ def download_image(element, folder: Path):
raise
ImageDownloadError
(
element
.
id
,
e
)
def
create_tar_zstd_archive
(
folder_path
,
destination
:
Path
,
chunk_size
=
1024
):
compressor
=
zstd
.
ZstdCompressor
(
level
=
3
)
def
create_tar_zstd_archive
(
folder_path
,
destination
:
Path
):
tar_fd
,
tar_archive
,
_
=
create_tar_archive
(
folder_path
)
# Remove extension from the model filename
_
,
path_to_tar_archive
=
tempfile
.
mkstemp
(
prefix
=
"
teklia-
"
,
suffix
=
"
.tar
"
)
_
,
_
,
_
=
zstd_compress
(
tar_archive
,
destination
)
# Create an uncompressed tar archive with all the needed files
# Files hierarchy ifs kept in the archive.
with
tarfile
.
open
(
path_to_tar_archive
,
"
w
"
)
as
tar
:
for
p
in
folder_path
.
glob
(
"
**/*
"
):
x
=
p
.
relative_to
(
folder_path
)
tar
.
add
(
p
,
arcname
=
x
,
recursive
=
False
)
# Compress the archive
with
destination
.
open
(
"
wb
"
)
as
archive_file
:
with
open
(
path_to_tar_archive
,
"
rb
"
)
as
model_data
:
for
model_chunk
in
iter
(
lambda
:
model_data
.
read
(
chunk_size
),
b
""
):
compressed_chunk
=
compressor
.
compress
(
model_chunk
)
archive_file
.
write
(
compressed_chunk
)
# Remove the tar archive
os
.
remove
(
path_to_tar_archive
)
close_delete_file
(
tar_fd
,
tar_archive
)
Loading