projects
/
pytorch.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
7abf09d
)
Update.
author
Francois Fleuret
<francois.fleuret@idiap.ch>
Thu, 15 Nov 2018 10:50:40 +0000
(11:50 +0100)
committer
Francois Fleuret
<francois.fleuret@idiap.ch>
Thu, 15 Nov 2018 10:50:40 +0000
(11:50 +0100)
mine_mnist.py
patch
|
blob
|
history
diff --git
a/mine_mnist.py
b/mine_mnist.py
index
82f6530
..
6f65136
100755
(executable)
--- a/
mine_mnist.py
+++ b/
mine_mnist.py
@@
-12,27
+12,30
@@
from torch.nn import functional as F
######################################################################
######################################################################
-# Returns a pair of tensors (a, b, c), where a and b are Nx1x28x28
-# tensors containing images, with a[i] and b[i] of same class for any
-# i, and c is a 1d long tensor with the count of pairs per class used.
+# Returns a pair of tensors (a, b, c), where a and b are tensors
+# containing each half of the samples, with a[i] and b[i] of same
+# class for any i, and c is a 1d long tensor with the count of pairs
+# per class used.
def create_pair_set(used_classes, input, target):
def create_pair_set(used_classes, input, target):
- u
=
[]
+ u
a, ub = [],
[]
for i in used_classes:
used_indices = torch.arange(input.size(0), device = target.device)\
.masked_select(target == i.item())
x = input[used_indices]
x = x[torch.randperm(x.size(0))]
for i in used_classes:
used_indices = torch.arange(input.size(0), device = target.device)\
.masked_select(target == i.item())
x = input[used_indices]
x = x[torch.randperm(x.size(0))]
- # Careful with odd numbers of samples in a class
- x = x[0:2 * (x.size(0) // 2)].reshape(-1, 2, 28, 28)
- u.append(x)
+ ua.append(x.narrow(0, 0, x.size(0)//2))
+ ub.append(x.narrow(0, x.size(0)//2, x.size(0)//2))
- x = torch.cat(u, 0)
- x = x[torch.randperm(x.size(0))]
- c = torch.tensor([x.size(0) for x in u])
+ a = torch.cat(ua, 0)
+ b = torch.cat(ub, 0)
+ perm = torch.randperm(a.size(0))
+ a = a[perm].contiguous()
+ b = b[perm].contiguous()
+ c = torch.tensor([x.size(0) for x in ua])
- return
x.narrow(1, 0, 1).contiguous(), x.narrow(1, 1, 1).contiguous()
, c
+ return
a, b
, c
######################################################################
######################################################################