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

transform with resize also changed the image extension from .jpg to .png #606

Closed
shaojun opened this issue Jan 7, 2022 · 4 comments · Fixed by #622
Closed

transform with resize also changed the image extension from .jpg to .png #606

shaojun opened this issue Jan 7, 2022 · 4 comments · Fixed by #622
Assignees
Labels
BUG Something isn't working

Comments

@shaojun
Copy link

shaojun commented Jan 7, 2022

Hi,
thanks for the great tool.

I'm using version 0.2.2, Ubuntu 20.04.3 LTS on x86.
I have a small testing kitti dataset, mixed with .jpg and .jpeg with size 1280x720 and 800x600 images files.
I've tried the steps to use datum:

datum --version
#0.2.2
mkdir datum_proj_real
cd datum_proj_real
datum create
datum import -f kitti ../my_small_kitti_dataset

can see:

Source 'source-1' with format 'kitti' has been added to the project

then do the transform to unify image size:

datum transform -t resize -- -dw 800 -dh 600

now checking the subfolder: source-1 in project folder: datum_proj_real, can see all images files are renamed with .png extension, and none of them can be opened by image viewer.

I also tried manually rename one of the file's extension from png to jpg, and still could not be opened with an error popup like not a valid jpg file.

could you help to check?

@zhiltsov-max zhiltsov-max self-assigned this Jan 10, 2022
@zhiltsov-max zhiltsov-max added BUG Something isn't working QUESTION Further information is requested and removed BUG Something isn't working labels Jan 10, 2022
@zhiltsov-max
Copy link
Contributor

zhiltsov-max commented Jan 10, 2022

Hi, Datumaro should preserve the original image extension by default. The resulting .pngs are segmentation annotations, and KITTI uses special 16-bit PNG encoding for these files (they reuse the Cityscapes format), which is not recognized by regular image viewers (as I understand, the purpose is just re-using PNG compression algorithm for storing a mask).

The dataset produced by the transform command currently doesn't include images, it is a CLI-only limitation. Some formats store image metainfo, which can be used by convert on a dataset produced by the transform command. KITTI doesn't have it, so to obtain the images as well, try to use Python API instead:

from datumaro.components.dataset import Dataset

dataset = Dataset.import_from('path/', 'kitti')
dataset.transform('resize', width=800, height=600)
dataset.export('path2/', 'kitti', save_images=True)

If you need to work inside a Datumaro project, you can use the lazy transform application by providing the --apply=False flag. Then, you can use export to produce the resulting dataset.

@shaojun
Copy link
Author

shaojun commented Jan 12, 2022

thanks, does that mean those generated .png files are expected behavior here?

@nmanovic
Copy link

nmanovic commented Jan 12, 2022

@shaojun , yes, it means. But at the same time it is possible to implement extra parameters for the export operation. Thus it can be a feature request and we are happy to accept contributions in the area.

P.S. At the same time for masks it is important to use lossless format.

@zhiltsov-max
Copy link
Contributor

zhiltsov-max commented Jan 12, 2022

Hi, probably, I was wrong about the images. I was able to reproduce the problem. Apparently, it is a result of a several problems, one of which is already described in #618 (the problem with file reading). KITTI uses the .png extension for images by default, and after resizing the images are treated as "new". Probably, we should save updated images with the same extension, as they had before modification.

You can change the default by using image_ext='.jpg' in the code snippet above:

from datumaro.components.dataset import Dataset

dataset = Dataset.import_from('path/', 'kitti')
dataset.transform('resize', width=800, height=600)
dataset.export('path2/', 'kitti', save_images=True, image_ext='.jpg')

@zhiltsov-max zhiltsov-max added BUG Something isn't working and removed QUESTION Further information is requested labels Jan 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BUG Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants