-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathutils.py
99 lines (67 loc) · 2.46 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
"""
@author : Ziheng Cheng, Bo Chen
@Email : [email protected] [email protected]
Description:
Citation:
The code prepares for ECCV 2020
Contact:
Ziheng Cheng
Xidian University, Xi'an, China
Bo Chen
Xidian University, Xi'an, China
LICENSE
=======================================================================
The code is for research purpose only. All rights reserved.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
Copyright (c), 2020, Ziheng Cheng
"""
import scipy.io as scio
import numpy as np
def generate_masks(mask_path):
mask = scio.loadmat(mask_path + '/mask.mat')
mask = mask['mask']
mask_s = np.sum(mask, axis=2)
index = np.where(mask_s == 0)
mask_s[index] = 1
return mask.astype(np.float32), mask_s.astype(np.float32)
def generate_masks_metaTest(mask_path):
mask = scio.loadmat(mask_path + '/Mask.mat')
mask = mask['Mask']
mask_s = np.sum(mask, axis=2)
index = np.where(mask_s == 0)
mask_s[index] = 1
mask = np.transpose(mask, [3, 0, 1, 2])
mask_s = np.transpose(mask_s, [2, 0, 1])
mask = mask[3]
mask_s = mask_s[3]
return mask.astype(np.float32), mask_s.astype(np.float32)
def generate_masks_metaTest_v2(mask_path):
mask = scio.loadmat(mask_path + '/Mask.mat')
mask = mask['Mask']
mask_s = np.sum(mask, axis=2)
index = np.where(mask_s == 0)
mask_s[index] = 1
mask = np.transpose(mask, [3, 0, 1, 2])
mask_s = np.transpose(mask_s, [2, 0, 1])
return mask.astype(np.float32), mask_s.astype(np.float32)
def generate_masks_metaTest_v3(mask_path):
mask = scio.loadmat(mask_path)
mask = mask['mask']
mask_s = np.sum(mask, axis=2)
index = np.where(mask_s == 0)
mask_s[index] = 1
return mask.astype(np.float32), mask_s.astype(np.float32)
def generate_masks_MAML(mask_path, num_task):
mask = scio.loadmat(mask_path + '/Mask.mat')
mask = mask['Mask']
mask_s = np.sum(mask, axis=2)
index = np.where(mask_s == 0)
mask_s[index] = 1
mask = np.transpose(mask, [3, 0, 1, 2])
mask_s = np.transpose(mask_s, [2, 0, 1])
mask = mask[:num_task]
mask_s = mask_s[:num_task]
return mask.astype(np.float32), mask_s.astype(np.float32)