-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add warning when data augmentation is applied on the pool (#229)
Co-authored-by: Parmida Atighehchian <[email protected]>
- Loading branch information
1 parent
deafffa
commit 19fbbb4
Showing
5 changed files
with
99 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from typing import Sequence, Mapping | ||
|
||
import numpy as np | ||
import torch | ||
from torch import Tensor | ||
|
||
|
||
def deep_check(obj1, obj2) -> bool: | ||
if type(obj1) != type(obj2): | ||
return False | ||
elif isinstance(obj1, str): | ||
return bool(obj1 == obj2) | ||
elif isinstance(obj1, Sequence): | ||
return all(deep_check(i1, i2) for i1, i2 in zip(obj1, obj2)) | ||
elif isinstance(obj1, Mapping): | ||
return all(deep_check(val1, obj2[key1]) for key1, val1 in obj1.items()) | ||
elif isinstance(obj1, Tensor): | ||
return torch.equal(obj1, obj2) | ||
elif isinstance(obj1, np.ndarray): | ||
return bool((obj1 == obj2).all()) | ||
else: | ||
return bool(obj1 == obj2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from collections import namedtuple | ||
|
||
import numpy as np | ||
import torch | ||
|
||
from baal.utils.equality import deep_check | ||
|
||
Point = namedtuple('Point', 'x,y') | ||
|
||
|
||
def test_deep_check(): | ||
arr1, arr2 = np.random.rand(10), np.random.rand(10) | ||
tensor1, tensor2 = torch.rand([10]), torch.rand([10]) | ||
s1, s2 = "string1", "string2" | ||
p1, p2 = Point(x=1, y=2), Point(x=2, y=1) | ||
|
||
assert not deep_check(arr1, arr2) | ||
assert not deep_check(tensor1, tensor2) | ||
assert not deep_check(s1, s2) | ||
assert not deep_check(p1, p2) | ||
assert not deep_check([arr1, tensor1], [arr2, tensor2]) | ||
assert not deep_check([arr1, tensor1], (arr1, tensor1)) | ||
assert not deep_check([arr1, tensor1], [tensor1, arr1]) | ||
assert not deep_check({'x': arr1, 'y': tensor1}, {'x': arr2, 'y': tensor2}) | ||
assert not deep_check({'x': arr1, 'y': tensor1}, {'x': tensor1, 'y': arr1}) | ||
|
||
assert deep_check(arr1, arr1) | ||
assert deep_check(tensor1, tensor1) | ||
assert deep_check(s1, s1) | ||
assert deep_check(p1, p1) | ||
assert deep_check([arr1, tensor1], [arr1, tensor1]) | ||
assert deep_check((arr1, tensor1), (arr1, tensor1)) | ||
assert deep_check({'x': arr1, 'y': tensor1}, {'x': arr1, 'y': tensor1}) |