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

rollback #15 partially #50

Merged
merged 1 commit into from
Jul 15, 2024
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
17 changes: 5 additions & 12 deletions tests/func/test_pytorch.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from pathlib import Path

import open_clip
import pytest
from torch import Size, Tensor
Expand All @@ -10,23 +8,18 @@
from datachain.lib.pytorch import PytorchDataset


@pytest.fixture(scope="module")
def fake_dir(tmpdir_factory):
@pytest.fixture
def fake_dataset(catalog, tmp_path):
# Create fake images in labeled dirs
data_path = Path(tmpdir_factory.mktemp("data"))
data_path = tmp_path / "data" / ""
for i, (img, label) in enumerate(FakeData()):
label = str(label)
(data_path / label).mkdir(parents=True, exist_ok=True)
img.save(data_path / label / f"{i}.jpg")

# Create dataset from images
return data_path.as_uri()


@pytest.fixture
def fake_dataset(fake_dir):
uri = data_path.as_uri()
return (
DataChain.from_storage(fake_dir, type="image")
DataChain.from_storage(uri, type="image")
.map(text=lambda file: file.parent.split("/")[-1], output=str)
.map(label=lambda text: int(text), output=int)
.save("fake")
Expand Down
Loading