Skip to content

add tests for SEMEION dataset #3465

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 4 commits into from
Mar 1, 2021
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
18 changes: 18 additions & 0 deletions test/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import shutil
import json
import random
import torch.nn.functional as F
import string
import io

Expand Down Expand Up @@ -1155,5 +1156,22 @@ def _create_captions_txt(self, root, num_images):
fh.write(f"{datasets_utils.create_random_string(10)}\n")


class SEMEIONTestCase(datasets_utils.ImageDatasetTestCase):
DATASET_CLASS = datasets.SEMEION

def inject_fake_data(self, tmpdir, config):
num_images = 3

images = torch.rand(num_images, 256)
labels = F.one_hot(torch.randint(10, size=(num_images,)))
with open(pathlib.Path(tmpdir) / "semeion.data", "w") as fh:
for image, one_hot_labels in zip(images, labels):
image_columns = " ".join([f"{pixel.item():.4f}" for pixel in image])
labels_columns = " ".join([str(label.item()) for label in one_hot_labels])
fh.write(f"{image_columns} {labels_columns}\n")

return num_images


if __name__ == "__main__":
unittest.main()