Skip to main content

Observe dataset of images and targets in few shots

Project description


# ImageDatasetViz
[![Build Status](https://travis-ci.org/vfdev-5/ImageDatasetViz.svg?branch=master)](https://travis-ci.org/vfdev-5/ImageDatasetViz)
[![Coverage Status](https://coveralls.io/repos/github/vfdev-5/ImageDatasetViz/badge.svg?branch=master)](https://coveralls.io/github/vfdev-5/ImageDatasetViz?branch=master)

Observe dataset of images and targets in few shots

![VEDAI example](examples/vedai_example.png)

## Descriptions

Idea is to create tools to store images, targets from a dataset as a few large images to observe the dataset
in few shots.


## Installation

```bash
python setup.py install
```
or
```bash
pip install git+https://github.com/vfdev-5/ImageDatasetViz.git
```

## Usage

### Render a single datapoint

First, we can just take a look on a single data point rendering. Let's assume that we
have `img` as, for example, `PIL.Image` and `target` as acceptable target type (`str` or list of points or
`PIL.Image` mask, etc), thus we can generate a single image with target.

```python
from image_dataset_viz import render_datapoint

# if target is a simple label
res = render_datapoint(img, "test label", text_color=(0, 255, 0), text_size=10)
plt.imshow(res)

# if target is a mask image (PIL.Image)
res = render_datapoint(img, target, blend_alpha=0.5)
plt.imshow(res)

# if target is a bounding box, e.g. np.array([[10, 10], [55, 10], [55, 77], [10, 77]])
res = render_datapoint(img, target, geom_color=(255, 0, 0))
plt.imshow(res)
```

#### Example output on Leaf Segmentation dataset from CVPPP2017

![image with mask](examples/image_mask.png) ![image with label](examples/image_label.png) ![image with bbox label](examples/image_bbox_label.png)

### Export complete dataset
For example, we have a dataset of image files and annotations files (polygons with labels):
```python
img_files = [
'/path/to/image_1.ext',
'/path/to/image_2.ext',
...
'/path/to/image_1000.ext',
]
target_files = [
'/path/to/target_1.ext2',
'/path/to/target_2.ext2',
...
'/path/to/target_1000.ext2',
]
```
We can produce a single image composed of 20x50 small samples with targets to better visualize the whole dataset.
Let's assume that we do need a particular processing to open the images in RGB 8bits format:
```python
from PIL import Image

def read_img_fn(img_filepath):
return Image.open(img_filepath).convert('RGB')
```
and let's say the annotations are just lines with points and a label, e.g. `12 23 34 45 56 67 car`
```python
from pathlib import Path
import numpy as np

def read_target_fn(target_filepath):
with Path(target_filepath).open('r') as handle:
points_labels = []
while True:
line = handle.readline()
if len(line) == 0:
break
splt = line[:-1].split(' ') # Split into points and labels
label = splt[-1]
points = np.array(splt[:-1]).reshape(-1, 2)
points_labels.append((points, label))
return points_labels
```
Now we can export the dataset
```python
de = DatasetExporter(read_img_fn=read_img_fn, read_target_fn=read_target_fn,
img_id_fn=lambda fp: Path(fp).stem, n_cols=20)
de.export(img_files, target_files, output_folder="dataset_viz")
```
and thus we should obtain a single png image with composed of 20x50 small samples.


## Examples

- [CIFAR10](examples/example_CIFAR10.ipynb)
- [VEDAI](examples/example_VEDAI.ipynb)


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

image_dataset_viz-0.2.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

image_dataset_viz-0.2-py2.py3-none-any.whl (8.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file image_dataset_viz-0.2.tar.gz.

File metadata

File hashes

Hashes for image_dataset_viz-0.2.tar.gz
Algorithm Hash digest
SHA256 95826cbf5326c9dbb106be4974e7f3f8fac0b9acbd9c3ef8906809992c4b61bf
MD5 90bc787a8618411f86fc1a61c19c588b
BLAKE2b-256 258305b6d87fb1c63110a18fe2fa8e84b1aadd40c1804cf32b53891b820b7523

See more details on using hashes here.

File details

Details for the file image_dataset_viz-0.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for image_dataset_viz-0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 df47c734420de9ce1e8a95b6e6d2f1a6f565f6c0d84db301ee2b32b204566b49
MD5 2acbe57b7e8317d5e9e1b354da5bcd24
BLAKE2b-256 f3e5c87dd62ce0498bd265b02109346628da76b1f1920d935b20e6939d283e14

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page