-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Manifest #2763
Merged
Merged
Manifest #2763
Changes from 28 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
5335bfe
Added support for manifest file
Marishka17 417e82f
Added data migration
Marishka17 eca3465
Updated tests
Marishka17 23792f1
Changed script for manually preparing
Marishka17 971ebfe
Fixs
Marishka17 d8afb6e
Fixed paths
Marishka17 6ead5c7
some fix & licence headers
Marishka17 2cd2972
Fixes
Marishka17 79d7a36
Fix stop_frame saving
Marishka17 64f9ec9
Merge branch 'upstream/develop' into mk/manifest
Marishka17 97c1746
Update migration
Marishka17 cbe1066
Fix codacy
Marishka17 01c940d
Bandit issue & json instead marshal
Marishka17 56ea59d
Merge branch 'develop' into mk/manifest
Marishka17 7081a96
f
Marishka17 83c01ed
pylint fixes
Marishka17 e54ce6f
Merge branch 'upstream/develop' into mk/manifest
Marishka17 934c63e
Update CHANGELOG
Marishka17 7b83517
Some fixes
Marishka17 d8c8606
Update manifest documentation
Marishka17 94d5d68
Merge branch 'upstream/develop' into mk/manifest
Marishka17 a643853
Fix create.py
Marishka17 eb88ed0
Fix case with 3d data
Marishka17 4284cac
Modify migration
Marishka17 d31510f
Fixed migration
Marishka17 65e4b12
Refactored script to manually prepare manifest
Marishka17 2d4f456
Update documentation
Marishka17 3afa428
Merge branch 'upstream/develop' into mk/manifest
Marishka17 38b0d0f
Fix some comments
Marishka17 83ca74d
Merge branch 'upstream/develop' into mk/manifest
Marishka17 c7bbd47
Fix
Marishka17 9c3a81d
One more fix
Marishka17 7e9389b
Merge branch 'develop' into mk/manifest
d16022a
Update README
Marishka17 3e58fa2
Revert prettier changes
Marishka17 c0b8a53
Merge branch 'mk/manifest' of https://github.com/opencv/cvat into mk/…
Marishka17 71d1b9a
Update utils/dataset_manifest/README.md
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ branch = true | |
source = | ||
cvat/apps/ | ||
utils/cli/ | ||
utils/dataset_manifest | ||
|
||
omit = | ||
cvat/settings/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Generated by Django 3.1.1 on 2021-02-20 08:36 | ||
|
||
import glob | ||
import os | ||
from re import search | ||
|
||
from django.conf import settings | ||
from django.db import migrations | ||
|
||
from cvat.apps.engine.models import (DimensionType, StorageChoice, | ||
StorageMethodChoice) | ||
from utils.dataset_manifest import (ImageManifestManager, VideoManifestManager, | ||
prepare_meta) | ||
|
||
|
||
def migrate_data(apps, shema_editor): | ||
Data = apps.get_model("engine", "Data") | ||
query_set = Data.objects.filter(storage_method=StorageMethodChoice.CACHE) | ||
for db_data in query_set: | ||
try: | ||
upload_dir = '{}/{}/raw'.format(settings.MEDIA_DATA_ROOT, db_data.id) | ||
if os.path.exists(os.path.join(upload_dir, 'meta_info.txt')): | ||
os.remove(os.path.join(upload_dir, 'meta_info.txt')) | ||
else: | ||
for path in glob.glob(f'{upload_dir}/dummy_*.txt'): | ||
os.remove(path) | ||
# it's necessary for case with long data migration | ||
if os.path.exists(os.path.join(upload_dir, 'manifest.jsonl')): | ||
continue | ||
data_dir = upload_dir if db_data.storage == StorageChoice.LOCAL else settings.SHARE_ROOT | ||
if hasattr(db_data, 'video'): | ||
media_file = os.path.join(data_dir, db_data.video.path) | ||
meta_info, _ = prepare_meta( | ||
data_type='video', | ||
media_file=media_file, | ||
) | ||
manifest = VideoManifestManager(manifest_path=upload_dir) | ||
manifest.create(meta_info) | ||
manifest.init_index() | ||
else: | ||
sources = [] | ||
if db_data.storage == StorageChoice.LOCAL: | ||
for (root, _, files) in os.walk(data_dir): | ||
sources.extend([os.path.join(root, f) for f in files]) | ||
sources.sort() | ||
# using share, this means that we can not explicitly restore the entire data structure | ||
else: | ||
sources = [os.path.join(data_dir, db_image.path) for db_image in db_data.images.all().order_by('frame')] | ||
if any(list(filter(lambda x: x.dimension==DimensionType.DIM_3D, db_data.tasks.all()))): | ||
content = [] | ||
for source in sources: | ||
name, ext = os.path.splitext(os.path.relpath(source, upload_dir)) | ||
content.append({ | ||
'name': name, | ||
'extension': ext | ||
}) | ||
else: | ||
meta_info = prepare_meta(data_type='images', sources=sources, data_dir=data_dir) | ||
content = meta_info.content | ||
manifest = ImageManifestManager(manifest_path=upload_dir) | ||
|
||
if db_data.storage == StorageChoice.SHARE: | ||
def _get_frame_step(str_): | ||
match = search("step\s*=\s*([1-9]\d*)", str_) | ||
return int(match.group(1)) if match else 1 | ||
step = _get_frame_step(db_data.frame_filter) | ||
start = db_data.start_frame | ||
stop = db_data.stop_frame + 1 | ||
images_range = range(start, stop, step) | ||
result_content = [] | ||
for i in range(stop): | ||
item = content.pop(0) if i in images_range else dict() | ||
result_content.append(item) | ||
content = result_content | ||
manifest.create(content) | ||
manifest.init_index() | ||
except Exception as ex: | ||
print(str(ex)) | ||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('engine', '0037_task_subset'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(migrate_data) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest renaming this class to something more descriptive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Marishka17 , a class name shouldn't start with a verb. It should describe a type of entity. Could you please rename?