Skip to content
GitLab
Explore
Sign in
a.rabensteiner
apply_postcards_colorizer
Compare revisions
b134d60f92b8d2c4890c63a9d6ceef7ab5355bfe to 53bf50d5343806a23cb20ca97627fc8c31d4c2ec
Commits on Source (2)
added minor comments
· 2210fc5b
onb1259
authored
Aug 02, 2023
2210fc5b
added lib for iiif support
· 53bf50d5
onb1259
authored
Aug 02, 2023
53bf50d5
Expand all
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
53bf50d5
colorizers/siggraph17-df00044c.pth
colorizers/colorization_release_v2-9b330a0b.pth
colorizers/col_new.pth
__pycache__
*.png
\ No newline at end of file
*.png
.ipynb_checkpoints
iiif_utils.py
0 → 100644
View file @
53bf50d5
import
requests
import
json
import
threading
import
os
def
get_json_by_url
(
url
):
res
=
requests
.
get
(
url
).
content
return
json
.
loads
(
res
)
def
get_manifesturls_from_collectionurl
(
url
):
x
=
get_json_by_url
(
url
)
return
[
el
[
'
@id
'
]
for
el
in
x
[
'
manifests
'
]]
def
get_imgurls_from_manifesturl
(
url
):
x
=
get_json_by_url
(
url
)
res
=
[]
for
s
in
x
[
'
sequences
'
]:
for
c
in
s
[
'
canvases
'
]:
for
i
in
c
[
'
images
'
]:
res
.
append
(
i
[
'
resource
'
][
'
@id
'
])
return
res
def
get_imgurls_from_collectionurl
(
url
):
res
=
[]
for
manifest_url
in
get_manifesturls_from_collectionurl
(
url
):
tmp
=
get_imgurls_from_manifesturl
(
manifest_url
)
for
el
in
tmp
:
res
.
append
(
el
)
return
res
def
download_images
(
img_urls
,
img_paths
):
for
u
,
n
in
zip
(
img_urls
,
img_paths
):
img_bytes
=
requests
.
get
(
u
).
content
with
open
(
n
,
'
+wb
'
)
as
img_file
:
img_file
.
write
(
img_bytes
)
def
download_images_multithreded
(
img_urls
,
img_paths
,
nb_threads
=
5
):
chunk_idcs
=
list
(
range
(
0
,
len
(
img_urls
),
int
(
len
(
img_urls
)
/
nb_threads
)))
+
[
len
(
img_urls
)]
chunks_urls
=
[
img_urls
[
i
:
j
]
for
i
,
j
in
zip
(
chunk_idcs
[:
-
1
],
chunk_idcs
[
1
:])]
chunks_paths
=
[
img_paths
[
i
:
j
]
for
i
,
j
in
zip
(
chunk_idcs
[:
-
1
],
chunk_idcs
[
1
:])]
for
urls
,
paths
in
zip
(
chunks_urls
,
chunks_paths
):
threading
.
Thread
(
target
=
download_images
,
args
=
[
urls
,
paths
]).
start
()
def
create_paths_from_iiifurls
(
img_urls
,
base_path
=
''
):
res
=
[
el
.
split
(
'
images/
'
)[
1
]
for
el
in
img_urls
]
res
=
[
'
_
'
.
join
(
el
.
split
(
'
/
'
)[:
-
4
])
for
el
in
res
]
res
=
[
el
+
'
.
'
+
u
.
split
(
'
.
'
)[
-
1
]
for
el
,
u
in
zip
(
res
,
img_urls
)]
res
=
[
os
.
path
.
join
(
base_path
,
el
)
for
el
in
res
]
return
res
labs_postcards_all_cards.json
deleted
100644 → 0
View file @
b134d60f
This diff is collapsed.
Click to expand it.
postBuild
View file @
53bf50d5
# Seems not to work for Binder
#wget -q -o colorizers/colorization_release_v2-9b330a0b.pth https://colorizers.s3.us-east-2.amazonaws.com/colorization_release_v2-9b330a0b.pth
#wget -q -o colorizers/siggraph17-df00044c.pth https://colorizers.s3.us-east-2.amazonaws.com/siggraph17-df00044c.pth
\ No newline at end of file
test_postcards.ipynb
View file @
53bf50d5
This diff is collapsed.
Click to expand it.