lambda -> fn to fix windows test
update libdeeplake version
fix
change version
fix again
Showing 2 of 2 files from the diff.
@@ -810,3 +810,57 @@
Loading
810 | 810 | np.testing.assert_equal(x, i) |
|
811 | 811 | target_y = i if i < 5 else [] |
|
812 | 812 | np.testing.assert_equal(y, target_y) |
|
813 | + | ||
814 | + | ||
815 | + | def json_collate_fn(batch): |
|
816 | + | import torch |
|
817 | + | ||
818 | + | batch = [it["a"][0]["x"] for it in batch] |
|
819 | + | return torch.utils.data._utils.collate.default_collate(batch) |
|
820 | + | ||
821 | + | ||
822 | + | def json_transform_fn(sample): |
|
823 | + | return sample[0]["x"] |
|
824 | + | ||
825 | + | ||
826 | + | def list_collate_fn(batch): |
|
827 | + | import torch |
|
828 | + | ||
829 | + | batch = [np.array([it["a"][0], it["a"][1]]) for it in batch] |
|
830 | + | return torch.utils.data._utils.collate.default_collate(batch) |
|
831 | + | ||
832 | + | ||
833 | + | def list_transform_fn(sample): |
|
834 | + | return np.array([sample[0], sample[1]]) |
|
835 | + | ||
836 | + | ||
837 | + | def test_pytorch_json(local_ds): |
|
838 | + | ds = local_ds |
|
839 | + | with ds: |
|
840 | + | ds.create_tensor("a", htype="json") |
|
841 | + | ds.a.append({"x": 1}) |
|
842 | + | ds.a.append({"x": 2}) |
|
843 | + | ||
844 | + | ptds = ds.pytorch(transform={"a": json_transform_fn}, batch_size=2) |
|
845 | + | batch = next(iter(ptds)) |
|
846 | + | np.testing.assert_equal(batch["a"], np.array([1, 2])) |
|
847 | + | ||
848 | + | ptds = ds.pytorch(collate_fn=json_collate_fn, batch_size=2) |
|
849 | + | batch = next(iter(ptds)) |
|
850 | + | np.testing.assert_equal(batch, np.array([1, 2])) |
|
851 | + | ||
852 | + | ||
853 | + | def test_pytorch_list(local_ds): |
|
854 | + | ds = local_ds |
|
855 | + | with ds: |
|
856 | + | ds.create_tensor("a", htype="list") |
|
857 | + | ds.a.append([1, 2]) |
|
858 | + | ds.a.append([3, 4]) |
|
859 | + | ||
860 | + | ptds = ds.pytorch(transform={"a": list_transform_fn}, batch_size=2) |
|
861 | + | batch = next(iter(ptds)) |
|
862 | + | np.testing.assert_equal(batch["a"], np.array([[1, 2], [3, 4]])) |
|
863 | + | ||
864 | + | ptds = ds.pytorch(collate_fn=list_collate_fn, batch_size=2) |
|
865 | + | batch = next(iter(ptds)) |
|
866 | + | np.testing.assert_equal(batch, np.array([[1, 2], [3, 4]])) |
@@ -650,57 +650,3 @@
Loading
650 | 650 | ptds = dataloader(ds).pytorch(tensors=["x"]) |
|
651 | 651 | for _ in ptds: |
|
652 | 652 | pass |
|
653 | - | ||
654 | - | ||
655 | - | def json_collate_fn(batch): |
|
656 | - | import torch |
|
657 | - | ||
658 | - | batch = [it["a"][0]["x"] for it in batch] |
|
659 | - | return torch.utils.data._utils.collate.default_collate(batch) |
|
660 | - | ||
661 | - | ||
662 | - | def json_transform_fn(sample): |
|
663 | - | return sample[0]["x"] |
|
664 | - | ||
665 | - | ||
666 | - | def list_collate_fn(batch): |
|
667 | - | import torch |
|
668 | - | ||
669 | - | batch = [np.array([it["a"][0], it["a"][1]]) for it in batch] |
|
670 | - | return torch.utils.data._utils.collate.default_collate(batch) |
|
671 | - | ||
672 | - | ||
673 | - | def list_transform_fn(sample): |
|
674 | - | return np.array([sample["a"][0], sample["a"][1]]) |
|
675 | - | ||
676 | - | ||
677 | - | def test_pytorch_json(local_ds): |
|
678 | - | ds = local_ds |
|
679 | - | with ds: |
|
680 | - | ds.create_tensor("a", htype="json") |
|
681 | - | ds.a.append({"x": 1}) |
|
682 | - | ds.a.append({"x": 2}) |
|
683 | - | ||
684 | - | ptds = ds.pytorch(transform={"a": json_transform_fn}, batch_size=2) |
|
685 | - | batch = next(iter(ptds)) |
|
686 | - | np.testing.assert_equal(batch["a"], np.array([1, 2])) |
|
687 | - | ||
688 | - | ptds = ds.pytorch(collate_fn=json_collate_fn, batch_size=2) |
|
689 | - | batch = next(iter(ptds)) |
|
690 | - | np.testing.assert_equal(batch, np.array([1, 2])) |
|
691 | - | ||
692 | - | ||
693 | - | def test_pytorch_list(local_ds): |
|
694 | - | ds = local_ds |
|
695 | - | with ds: |
|
696 | - | ds.create_tensor("a", htype="list") |
|
697 | - | ds.a.append([1, 2]) |
|
698 | - | ds.a.append([3, 4]) |
|
699 | - | ||
700 | - | ptds = ds.pytorch(transform={"a": lambda x: np.array([x[0], x[1]])}, batch_size=2) |
|
701 | - | batch = next(iter(ptds)) |
|
702 | - | np.testing.assert_equal(batch["a"], np.array([[1, 2], [3, 4]])) |
|
703 | - | ||
704 | - | ptds = ds.pytorch(collate_fn=list_collate_fn, batch_size=2) |
|
705 | - | batch = next(iter(ptds)) |
|
706 | - | np.testing.assert_equal(batch, np.array([[1, 2], [3, 4]])) |
Files | Coverage |
---|---|
deeplake | 89.78% |
conftest.py | 100.00% |
setup.py | 0.00% |
Project Totals (253 files) | 89.68% |
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file.
The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files.
The size and color of each slice is representing the number of statements and the coverage, respectively.