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

fix: LEAP-1692: Image export for COCO and YOLO #6855

Draft
wants to merge 18 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
7 changes: 5 additions & 2 deletions label_studio/data_export/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ def get(self, request, *args, **kwargs):
return response


def async_convert(converted_format_id, export_type, project, **kwargs):
def async_convert(converted_format_id, export_type, project, hostname, download_resources=False, **kwargs):
with transaction.atomic():
try:
converted_format = ConvertedFormat.objects.get(id=converted_format_id)
Expand All @@ -583,7 +583,7 @@ def async_convert(converted_format_id, export_type, project, **kwargs):
converted_format.save(update_fields=['status'])

snapshot = converted_format.export
converted_file = snapshot.convert_file(export_type)
converted_file = snapshot.convert_file(export_type, download_resources=download_resources, hostname=hostname)
if converted_file is None:
raise ValidationError('No converted file found, probably there are no annotations in the export snapshot')
md5 = Export.eval_md5(converted_file)
Expand Down Expand Up @@ -645,6 +645,7 @@ def post(self, request, *args, **kwargs):
serializer = ExportConvertSerializer(data=request.data, context={'project': snapshot.project})
serializer.is_valid(raise_exception=True)
export_type = serializer.validated_data['export_type']
download_resources = serializer.validated_data.get('download_resources')

with transaction.atomic():
converted_format, created = ConvertedFormat.objects.get_or_create(export=snapshot, export_type=export_type)
Expand All @@ -657,6 +658,8 @@ def post(self, request, *args, **kwargs):
converted_format.id,
export_type,
snapshot.project,
request.build_absolute_uri('/'),
download_resources=download_resources,
on_failure=set_convert_background_failure,
)
return Response({'export_type': export_type, 'converted_format': converted_format.id})
10 changes: 8 additions & 2 deletions label_studio/data_export/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ def _get_export_serializer_option(serialization_options):
options['context']['interpolate_key_frames'] = serialization_options['interpolate_key_frames']
if serialization_options.get('include_annotation_history') is False:
options['omit'] = ['annotations.history']
# download resources
if serialization_options.get('download_resources') is True:
options['download_resources'] = True
return options

def get_task_queryset(self, ids, annotation_filter_options):
Expand Down Expand Up @@ -303,7 +306,7 @@ def run_file_exporting(self, task_filter_options=None, annotation_filter_options
serialization_options=serialization_options,
)

def convert_file(self, to_format):
def convert_file(self, to_format, download_resources=False, hostname=None):
with get_temp_dir() as tmp_dir:
OUT = 'out'
out_dir = pathlib.Path(tmp_dir) / OUT
Expand All @@ -313,7 +316,10 @@ def convert_file(self, to_format):
config=self.project.get_parsed_config(),
project_dir=None,
upload_dir=out_dir,
download_resources=False,
download_resources=download_resources,
# for downloading resource we need access to the API
access_token=self.project.organization.created_by.auth_token.key,
hostname=hostname,
)
input_name = pathlib.Path(self.file.name).name
input_file_path = pathlib.Path(tmp_dir) / input_name
Expand Down
1 change: 1 addition & 0 deletions label_studio/data_export/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class SerializationOption(serializers.Serializer):

class ExportConvertSerializer(serializers.Serializer):
export_type = serializers.CharField(help_text='Export file format.')
download_resources = serializers.BooleanField(help_text='Download resources in converter.', required=False)

def validate_export_type(self, value):
project = self.context.get('project')
Expand Down
11 changes: 6 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ django-migration-linter = "^5.1.0"
setuptools = ">=75.4.0"

# Humansignal repo dependencies
label-studio-sdk = {url = "https://github.com/HumanSignal/label-studio-sdk/archive/abf1ea4207e22d3d3cdfb8f4bb12ffb4d59384e4.zip"}
label-studio-sdk = {url = "https://github.com/HumanSignal/label-studio-sdk/archive/025aaa8136465f97892adfee7aea498576e05f7a.zip"}

[tool.poetry.group.test.dependencies]
pytest = "7.2.2"
Expand Down
Loading