|
|
|
|
@ -182,23 +182,19 @@ class _Manifest:
|
|
|
|
|
FILE_NAME = 'manifest.jsonl'
|
|
|
|
|
VERSION = '1.1'
|
|
|
|
|
|
|
|
|
|
def __init__(self, path, is_created=False):
|
|
|
|
|
def __init__(self, path, upload_dir=None):
|
|
|
|
|
assert path, 'A path to manifest file not found'
|
|
|
|
|
self._path = os.path.join(path, self.FILE_NAME) if os.path.isdir(path) else path
|
|
|
|
|
self._is_created = is_created
|
|
|
|
|
self._upload_dir = upload_dir
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def path(self):
|
|
|
|
|
return self._path
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def is_created(self):
|
|
|
|
|
return self._is_created
|
|
|
|
|
|
|
|
|
|
@is_created.setter
|
|
|
|
|
def is_created(self, value):
|
|
|
|
|
assert isinstance(value, bool)
|
|
|
|
|
self._is_created = value
|
|
|
|
|
def name(self):
|
|
|
|
|
return os.path.basename(self._path) if not self._upload_dir \
|
|
|
|
|
else os.path.relpath(self._path, self._upload_dir)
|
|
|
|
|
|
|
|
|
|
# Needed for faster iteration over the manifest file, will be generated to work inside CVAT
|
|
|
|
|
# and will not be generated when manually creating a manifest
|
|
|
|
|
@ -266,8 +262,14 @@ class _ManifestManager(ABC):
|
|
|
|
|
'version' : 1,
|
|
|
|
|
'type': 2,
|
|
|
|
|
}
|
|
|
|
|
def __init__(self, path, *args, **kwargs):
|
|
|
|
|
self._manifest = _Manifest(path)
|
|
|
|
|
|
|
|
|
|
def _json_item_is_valid(self, **state):
|
|
|
|
|
for item in self._requared_item_attributes:
|
|
|
|
|
if state.get(item, None) is None:
|
|
|
|
|
raise Exception(f"Invalid '{self.manifest.name} file structure': '{item}' is required, but not found")
|
|
|
|
|
|
|
|
|
|
def __init__(self, path, upload_dir=None, *args, **kwargs):
|
|
|
|
|
self._manifest = _Manifest(path, upload_dir)
|
|
|
|
|
self._index = _Index(os.path.dirname(self._manifest.path))
|
|
|
|
|
|
|
|
|
|
def _parse_line(self, line):
|
|
|
|
|
@ -284,7 +286,9 @@ class _ManifestManager(ABC):
|
|
|
|
|
offset = self._index[line]
|
|
|
|
|
manifest_file.seek(offset)
|
|
|
|
|
properties = manifest_file.readline()
|
|
|
|
|
return json.loads(properties)
|
|
|
|
|
parsed_properties = json.loads(properties)
|
|
|
|
|
self._json_item_is_valid(**parsed_properties)
|
|
|
|
|
return parsed_properties
|
|
|
|
|
|
|
|
|
|
def init_index(self):
|
|
|
|
|
if os.path.exists(self._index.path):
|
|
|
|
|
@ -317,7 +321,9 @@ class _ManifestManager(ABC):
|
|
|
|
|
while line:
|
|
|
|
|
if not line.strip():
|
|
|
|
|
continue
|
|
|
|
|
yield (image_number, json.loads(line))
|
|
|
|
|
parsed_properties = json.loads(line)
|
|
|
|
|
self._json_item_is_valid(**parsed_properties)
|
|
|
|
|
yield (image_number, parsed_properties)
|
|
|
|
|
image_number += 1
|
|
|
|
|
line = manifest_file.readline()
|
|
|
|
|
|
|
|
|
|
@ -347,6 +353,8 @@ class _ManifestManager(ABC):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
class VideoManifestManager(_ManifestManager):
|
|
|
|
|
_requared_item_attributes = {'number', 'pts'}
|
|
|
|
|
|
|
|
|
|
def __init__(self, manifest_path):
|
|
|
|
|
super().__init__(manifest_path)
|
|
|
|
|
setattr(self._manifest, 'TYPE', 'video')
|
|
|
|
|
@ -375,7 +383,6 @@ class VideoManifestManager(_ManifestManager):
|
|
|
|
|
'checksum': item[2]
|
|
|
|
|
}, separators=(',', ':'))
|
|
|
|
|
manifest_file.write(f"{json_item}\n")
|
|
|
|
|
self._manifest.is_created = True
|
|
|
|
|
|
|
|
|
|
def partial_update(self, number, properties):
|
|
|
|
|
pass
|
|
|
|
|
@ -461,8 +468,10 @@ class VideoManifestValidator(VideoManifestManager):
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
class ImageManifestManager(_ManifestManager):
|
|
|
|
|
def __init__(self, manifest_path):
|
|
|
|
|
super().__init__(manifest_path)
|
|
|
|
|
_requared_item_attributes = {'name', 'extension'}
|
|
|
|
|
|
|
|
|
|
def __init__(self, manifest_path, upload_dir=None):
|
|
|
|
|
super().__init__(manifest_path, upload_dir)
|
|
|
|
|
setattr(self._manifest, 'TYPE', 'images')
|
|
|
|
|
|
|
|
|
|
def create(self, content, **kwargs):
|
|
|
|
|
@ -481,7 +490,6 @@ class ImageManifestManager(_ManifestManager):
|
|
|
|
|
key: value for key, value in item.items()
|
|
|
|
|
}, separators=(',', ':'))
|
|
|
|
|
manifest_file.write(f"{json_item}\n")
|
|
|
|
|
self._manifest.is_created = True
|
|
|
|
|
|
|
|
|
|
def partial_update(self, number, properties):
|
|
|
|
|
pass
|
|
|
|
|
|