Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Add a simple example for SiameseDataset #531

Merged
merged 2 commits into from
Mar 5, 2018
Merged
Changes from all commits
Commits
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
20 changes: 20 additions & 0 deletions chainercv/datasets/siamese_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@ class SiameseDataset(chainer.dataset.DatasetMixin):
In this mode, the base datasets are assumed to be label datasets that
return an image and a label as a sample.

Example:

We construct a siaemse dataset from MNIST.

.. code::

>>> from chainer.datasets import get_mnist
>>> from chainercv.datasets import SiameseDataset
>>> mnist, _ = get_mnist()
>>> dataset = SiameseDataset(mnist, mnist, pos_ratio=0.3)
# The probability of the two samples having the same label
# is 0.3 as specified by pos_ratio.
>>> img_0, label_0, img_1, label_1 = dataset[0]
Copy link
Member

Choose a reason for hiding this comment

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

It would be helpful to show that SiameseDataset returns examples randomly.
How about adding following lines?

...
>>> img_0, label_0, img_1, label_1 = dataset[0]
Note that the returned examples may change in the next call because :class:`SiameseDataset` picks examples randomly.
>>> img_0_new, label_0_new, img_1_new, label_1_new = dataset[0]
In this case, :obj:`img_0_new` may differ :obj:`img_0`.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice!

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, differ -> differ from.

# The returned examples may change in the next
# call even if the index is the same as before
# because SiameseDataset picks examples randomly
# (e.g., img_0_new may differ from img_0).
>>> img_0_new, label_0_new, img_1_new, label_1_new = dataset[0]


Args:
dataset_0: The first base dataset.
dataset_1: The second base dataset.
Expand Down