Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Loading objects from different backends and dumping objects to different backends #1330

Merged
merged 50 commits into from
Oct 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
b2a2257
[Feature] Choose storage backend by the prefix of filepath
zhouzaida Sep 9, 2021
073f73e
refactor FileClient and add unittest
zhouzaida Sep 10, 2021
dfb9fc4
support loading from different backends
zhouzaida Sep 11, 2021
48cfdad
polish docstring
zhouzaida Sep 21, 2021
c2c9fc0
fix unittet
zhouzaida Sep 21, 2021
d641a8c
rename attribute str_like_obj to is_str_like_obj
zhouzaida Sep 22, 2021
68f0ab6
add infer_client method
zhouzaida Sep 23, 2021
31caf8e
add check_exist method
zhouzaida Sep 23, 2021
7e7a80f
rename var client to file_client
zhouzaida Sep 24, 2021
aa8274b
polish docstring
zhouzaida Sep 26, 2021
bb4712d
add join_paths method
zhouzaida Sep 27, 2021
2409531
Merge branch 'master' of https://github.com/open-mmlab/mmcv into load…
zhouzaida Sep 27, 2021
d4b6d96
remove join_paths and add _format_path
zhouzaida Sep 28, 2021
824cff3
Merge branch 'master' of https://github.com/open-mmlab/mmcv into load…
zhouzaida Oct 3, 2021
767f7fb
enhance unittest
zhouzaida Oct 3, 2021
b930678
refactor unittest
zhouzaida Oct 3, 2021
1752698
singleton pattern
zhouzaida Oct 4, 2021
fb9567c
fix test_clientio.py
zhouzaida Oct 4, 2021
00505f8
deprecate CephBackend
zhouzaida Oct 4, 2021
225d3a6
enhance docstring
zhouzaida Oct 6, 2021
22644da
refactor unittest for petrel
zhouzaida Oct 6, 2021
058b7e8
refactor unittest for disk backend
zhouzaida Oct 6, 2021
1692678
update io.md
zhouzaida Oct 6, 2021
01b9807
add concat_paths method
zhouzaida Oct 6, 2021
fed5a39
improve docstring
zhouzaida Oct 8, 2021
4959687
improve docstring
zhouzaida Oct 8, 2021
aea920a
add isdir and copyfile for file backend
zhouzaida Oct 10, 2021
6412103
delete copyfile and add get_local_path
zhouzaida Oct 11, 2021
c557ca3
Merge branch 'master' of https://github.com/open-mmlab/mmcv into load…
zhouzaida Oct 12, 2021
eeda74c
remove isdir method of petrel
zhouzaida Oct 12, 2021
ad52428
fix typo
zhouzaida Oct 12, 2021
941a884
add comment and polish docstring
zhouzaida Oct 13, 2021
198a465
polish docstring
zhouzaida Oct 14, 2021
e0d6a83
rename _path_mapping to _map_path
zhouzaida Oct 15, 2021
ae0cdd3
polish docstring and fix typo
zhouzaida Oct 15, 2021
a2e0162
refactor get_local_path
zhouzaida Oct 16, 2021
50ba26f
add list_dir_or_file for FileClient
zhouzaida Oct 17, 2021
4ad3bf5
add list_dir_or_file for PetrelBackend
zhouzaida Oct 18, 2021
df207d1
fix windows ci
zhouzaida Oct 18, 2021
d29a88d
Add return docstring
zhouzaida Oct 19, 2021
f18a779
polish docstring
zhouzaida Oct 19, 2021
b6eb5d1
fix typo
zhouzaida Oct 19, 2021
150d504
fix typo
zhouzaida Oct 19, 2021
208ff82
deprecate the conversion from Path to str
zhouzaida Oct 20, 2021
9ecfc12
add docs for loading checkpoints with FileClient
zhouzaida Oct 22, 2021
38559f1
refactor map_path
zhouzaida Oct 22, 2021
ea32388
add _ensure_methods to ensure methods have been implemented
zhouzaida Oct 22, 2021
a8cc11d
fix list_dir_or_file
zhouzaida Oct 22, 2021
e66fe61
rename _ensure_method_implemented to has_method
zhouzaida Oct 23, 2021
6987038
fix conflict
zhouzaida Oct 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions mmcv/fileio/file_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class PetrelBackend(BaseStorageBackend):
path. When `path_mapping={'src': 'dst'}`, `src` in `filepath` will
be replaced by `dst`. Default: None.
enable_mc (bool): whether to enable memcached support. Default: True.
enable_multi_cluster (bool): Whether to enable multi clusters.
enable_multi_cluster (bool): Whether to enable multiple clusters.
Default: False.
"""

Expand Down Expand Up @@ -242,22 +242,32 @@ class FileClient:
"""A general file client to access files in different backend.

The client loads a file or text in a specified backend from its path
and return it as a binary file. it can also register other backend
accessor with a given name and backend class.
and return it as a binary or text file. There are two ways to choose a
backend, the name of backend and the prefixes of path. Although both of
them can be used to choose a storage backend, backend has a higher priority
that is if they are all set, the storage backend will be chosen by the
zhouzaida marked this conversation as resolved.
Show resolved Hide resolved
backend argument. If they are all `None`, the dist backend will be chosen.
zhouzaida marked this conversation as resolved.
Show resolved Hide resolved
Note that It can also register other backend accessor with a given name,
prefixes, and backend class.

Args:
backend (str): The storage backend type. Options are "disk", "ceph",
"memcached", "lmdb", "http" and "petrel". Default: None.
prefixes (str or list[str] or tuple[str]): The prefixes of the
registered storage backend. Both backend and prefixes can be used
to choose a storage backend, but backend has a higher priority that
is if they are all set, the storage backend will be chosen by the
backend rather than prefixes. If backend and prefixes are all
`None`. The dist backend is be chosen. Default: None.
registered storage backend. Options are "s3", "http", "https".
Default: None.

.. versionadd:: 1.3.14
The *prefixes* parameter.

Example:
>>> # only set backend
>>> file_client = FileClient(backend='ceph')
>>> # only set prefixes
>>> file_client = FileClient(prefixes='s3')
>>> # set both backend and prefixes but use backend to choose client
>>> file_client = FileClient(backend='ceph', prefixes='s3')

Attributes:
client (:obj:`BaseStorageBackend`): The backend object.
"""
Expand Down Expand Up @@ -309,7 +319,8 @@ def parse_uri_prefix(uri):
return None
else:
prefix, _ = uri.split('://')
# clusterName:s3://
# In the case of ceph, the prefix may contains the cluster name
# like clusterName:s3
if ':' in prefix:
_, prefix = prefix.split(':')
return prefix
Expand Down
12 changes: 6 additions & 6 deletions mmcv/fileio/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ def dump(obj, file=None, file_format=None, file_client_args=None, **kwargs):
return handler.dump_to_str(obj, **kwargs)
elif is_str(file):
if handler.str_like_obj:
f = StringIO()
handler.dump_to_fileobj(obj, f, **kwargs)
client.put_text(f.getvalue(), file)
with StringIO as f:
handler.dump_to_fileobj(obj, f, **kwargs)
client.put_text(f.getvalue(), file)
else:
f = BytesIO()
handler.dump_to_fileobj(obj, f, **kwargs)
client.put(f.getvalue(), file)
with BytesIO() as f:
handler.dump_to_fileobj(obj, f, **kwargs)
client.put(f.getvalue(), file)
elif hasattr(file, 'write'):
handler.dump_to_fileobj(obj, file, **kwargs)
else:
Expand Down