Skip to content

ByteImage: try to guess the image extension if one is not given #595

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

Merged
merged 1 commit into from
Dec 22, 2021
Merged

Conversation

IRDonch
Copy link

@IRDonch IRDonch commented Dec 22, 2021

Summary

This lets us avoid needless re-encoding when a ByteImage is saved as the format it already is in.

Unfortunately, neither OpenCV nor PIL seem to offer functionality to detect the format without loading the image, so we have to implement it ourselves. I only added support for a handful of most common formats, which should cover a majority of cases.

How to test

Checklist

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.
  • I have updated the license header for each file (see an example below)
# Copyright (C) 2021 Intel Corporation
#
# SPDX-License-Identifier: MIT

This lets us avoid needless re-encoding when a `ByteImage` is saved as
the format it already is in.

Unfortunately, neither OpenCV nor PIL seem to offer functionality to detect
the format without loading the image, so we have to implement it ourselves.
I only added support for a handful of most common formats, which should cover
a majority of cases.
@IRDonch IRDonch requested a review from zhiltsov-max December 22, 2021 14:51
Copy link
Contributor

@zhiltsov-max zhiltsov-max left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good PR, but I don't know it has real applications now. Currently, in all cases the extension is known.

@zhiltsov-max zhiltsov-max merged commit 8ef1606 into open-edge-platform:develop Dec 22, 2021
@IRDonch IRDonch deleted the guess-ext branch December 22, 2021 18:16
@IRDonch
Copy link
Author

IRDonch commented Dec 22, 2021

A good PR, but I don't know it has real applications now.

It's useful for TFDS integration, because TFDS does not provide file names for datasets that didn't originally have them (e.g., MNIST).

@zhiltsov-max
Copy link
Contributor

@IRDonch
Copy link
Author

IRDonch commented Dec 23, 2021

TFRecords can contain basically anything. In the case of MNIST you can see that the only features are image and label: https://www.tensorflow.org/datasets/catalog/mnist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants