-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Image save w/o compression from pil/base64; clean util code; TSV doc (#…
…47) * Add image save without compression from pil or base64; clean up util code; doc on TSV *
- Loading branch information
Showing
25 changed files
with
633 additions
and
314 deletions.
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
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,60 @@ | ||
# Introduction | ||
|
||
TSV format uses a single or multiple *.tvs format to store both the image annotation and image files, where the | ||
- **first column** is the image_id, it can be string, int or any unique identifier | ||
- **second column** being the annotaion | ||
- **third column** being the [base64-encoded](https://en.wikipedia.org/wiki/Base64) string of the image data. | ||
|
||
This repo does not support consuming TSV format, but we provide tools for converting to/from TSV format from/to coco, for limited tasks and data, such as | ||
|
||
```bash | ||
vision_convert_to_tsv {dataset_name} -r {dataset_registry_json} -k {data storage url} -f {local_dir} [-u Usages] | ||
``` | ||
|
||
For more commands and help related to TSV, check out [UTIL_COMMANDS.md](./UTIL_COMMANDS.md). | ||
|
||
# Task-wise Format | ||
|
||
## Image Classifciation | ||
|
||
Below is an example of multiclass classification: | ||
|
||
``` | ||
1 [{"class": "dog"}] /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAA..... | ||
2 [{"class": "cat"}] /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAA..... | ||
3 [{"class": "wolff"}] /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAA..... | ||
... | ||
``` | ||
|
||
For multilabel classification, | ||
|
||
``` | ||
1 [{"class": "dog"}, {"class": "canidae"}, {"class": "pet"}] /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAA..... | ||
2 [{"class": "cat"}, {"class": "Felidae"}, {"class": "pet"}] /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAA..... | ||
3 [{"class": "wolff"}, {"class": "canidae"}}] /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAA..... | ||
... | ||
``` | ||
|
||
## Object Detection | ||
|
||
The format of object detection is very similar to mutlilable classification, with an additonal field `rect: [left, top, right, bottom]` | ||
|
||
``` | ||
1 [{"class": "dog", "rect": [10, 10, 100, 100]}, {"class": "cat", "rect": [10, 10, 100, 100]}] /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAA..... | ||
2 [{"class": "cat", "rect": [10, 20, 250, 100]}] /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAA..... | ||
3 [{"class": "wolff", "rect": [100, 200, 250, 1000]}] /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAA..... | ||
... | ||
``` | ||
|
||
|
||
## Image Caption | ||
|
||
|
||
The format of image caption is straightforward as | ||
|
||
``` | ||
1 [{"caption": "dog playing with a cat"}] /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAA..... | ||
2 [{"caption": "dog eating food"}] /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAA..... | ||
3 [{"caption": "wolff sitting in snow"] /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAA..... | ||
... | ||
``` |
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,10 @@ | ||
# Helpful commands | ||
|
||
- `vision_download`: help you download the dataset files to local disk for consumption, it can be downloaded/converted to TSV directly as well | ||
- `vision_check_dataset`: check if a dataset or [coco json + images] is problematic or not. | ||
- `vision_convert_to_tsv`: convert a dataset or [coco json + images] to TSV format, currently only classification, object detection and caption tasks are supported, TSV format doc can be found at [`TSV_FORMAT.md`](./TSV_FORMAT.md) | ||
- `vision_convert_tsv_to_coco`: convert TSV file to [coco json + images]. | ||
- `vision_convert_od_to_ic`: convert a detection dataset to classification dataset (with or without augmentations). | ||
- `vision_merge_datasets`: merge multiple datasets into one. | ||
|
||
For each commoand, run `command -h` for more details. |
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 |
---|---|---|
|
@@ -4,3 +4,4 @@ requests>=2.23.0 | |
tenacity>=6.2.0 | ||
tqdm | ||
torch>=1.7.1 | ||
matplotlib |
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,29 @@ | ||
import tempfile | ||
import unittest | ||
import pathlib | ||
import numpy | ||
from PIL import Image, ImageChops | ||
from vision_datasets.commands.utils import Base64Utils | ||
|
||
|
||
class TestBase64Utils(unittest.TestCase): | ||
@staticmethod | ||
def _create_rand_img(size=(100, 100)) -> Image.Image: | ||
assert len(size) == 2 | ||
|
||
imarray = numpy.random.rand(size[0], size[1], 3) * 255 | ||
im = Image.fromarray(imarray.astype('uint8')).convert('RGB') | ||
return im | ||
|
||
def test_b64_to_file_loses_no_info(self): | ||
with tempfile.TemporaryDirectory() as temp_dir: | ||
temp_dir = pathlib.Path(temp_dir) | ||
img_filepath_1 = temp_dir / 'temp_1.jpg' | ||
TestBase64Utils._create_rand_img().save(img_filepath_1) | ||
|
||
img_filepath_2 = temp_dir / 'temp_2.jpg' | ||
b64str = Base64Utils.file_to_b64_str(img_filepath_1) | ||
Base64Utils.b64_str_to_file(b64str, img_filepath_2) | ||
img1 = Image.open(img_filepath_1) | ||
img2 = Image.open(img_filepath_2) | ||
assert not ImageChops.difference(img1, img2).getbbox() |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from .common import DatasetRegistry, Usages, DatasetTypes, CocoManifestAdaptor, IrisManifestAdaptor, DatasetManifest, DatasetInfo, ManifestDataset, BaseDatasetInfo, MultiTaskDatasetInfo | ||
from .resources import DatasetHub | ||
from .commands import Base64Utils | ||
|
||
__all__ = ['DatasetRegistry', 'Usages', 'DatasetTypes', 'CocoManifestAdaptor', 'IrisManifestAdaptor', 'DatasetManifest', 'DatasetInfo', 'ManifestDataset', 'BaseDatasetInfo', 'MultiTaskDatasetInfo', | ||
'DatasetHub'] | ||
'DatasetHub', 'Base64Utils'] |
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,3 @@ | ||
from .utils import Base64Utils | ||
|
||
__all__ = ['Base64Utils'] |
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.