Skip to content

Commit

Permalink
fix changesim
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorKey committed Mar 4, 2023
1 parent 2927b39 commit da13cff
Show file tree
Hide file tree
Showing 4 changed files with 270 additions and 14 deletions.
9 changes: 5 additions & 4 deletions src/dataset/changesim.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def extract_class_from_seg(self,img_seg):
classes_str = [self.idx2name[idx] for idx in classes_idx]
return classes_idx, classes_str

def colormap2classmap(self,seg_array):
def colormap2classmap(self, seg_array):
seg_array_flattened = torch.LongTensor(seg_array.reshape(-1,3))
seg_map_class_flattened = torch.zeros((seg_array.shape[0],seg_array.shape[1],1)).view(-1,1)
for color, cls in self.color2idx.items():
Expand Down Expand Up @@ -197,7 +197,8 @@ def get_ChangeSim(args, train=True, num_class=2):
seg_class_num = 5
else:
seg_class_num = 32
seg = SegHelper(idx2color_path=os.path.join(raw_root, 'idx2color.txt'), num_class=seg_class_num)
# seg = SegHelper(idx2color_path=os.path.join(raw_root, 'idx2color.txt'), num_class=seg_class_num)
seg = SegHelper(idx2color_path=os.path.join('./src/dataset/idx2color.txt'), num_class=seg_class_num)

mean=(0.485, 0.456, 0.406)
std=(0.229, 0.224, 0.225)
Expand All @@ -216,11 +217,11 @@ def get_ChangeSim(args, train=True, num_class=2):
augs.append(T.Normalize(mean=mean, std=std))
augs.append(T.ConcatImages())
elif num_class == 5:
augs.append(T.ToTensor(seg.colormap2classmap))
augs.append(T.PILToTensor(seg.colormap2classmap))
augs.append(T.Normalize(mean=mean, std=std))
augs.append(T.ConcatImages())
else:
augs.append(T.ToTensor(seg.colormap2classmap))
augs.append(T.PILToTensor(seg.colormap2classmap))
augs.append(T.Normalize(mean=mean, std=std))

transforms = T.Compose(augs)
Expand Down
257 changes: 257 additions & 0 deletions src/dataset/idx2color.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
[[ 0 0 0]
[ 81 38 0]
[ 41 36 132]
[ 25 48 16]
[131 192 13]
[157 131 11]
[ 21 1 4]
[ 43 110 139]
[ 90 104 2]
[ 61 101 116]
[ 3 2 145]
[ 33 1 220]
[226 37 73]
[ 84 144 2]
[ 7 25 89]
[ 14 178 44]
[ 0 214 0]
[140 3 0]
[ 48 14 2]
[ 0 9 13]
[ 73 8 15]
[194 76 70]
[ 78 53 104]
[137 5 0]
[155 47 90]
[168 8 11]
[166 20 160]
[129 61 128]
[ 9 16 155]
[ 34 249 86]
[ 51 1 50]
[ 1 58 15]
[139 216 58]
[ 28 251 109]
[119 245 24]
[ 26 92 226]
[145 3 0]
[253 0 200]
[ 4 140 231]
[182 93 7]
[ 23 253 171]
[ 80 0 56]
[ 27 3 36]
[159 200 26]
[ 52 17 7]
[ 31 9 17]
[ 53 56 218]
[186 81 39]
[ 23 80 4]
[106 15 3]
[ 4 55 52]
[ 10 1 3]
[ 60 10 47]
[178 51 43]
[ 47 0 147]
[192 57 27]
[235 26 1]
[ 8 83 224]
[150 30 83]
[122 72 119]
[ 29 206 6]
[ 59 231 59]
[116 132 3]
[ 0 186 134]
[ 31 226 35]
[ 26 99 180]
[ 13 9 177]
[ 75 13 57]
[152 33 154]
[175 19 17]
[210 1 243]
[ 39 157 2]
[ 94 137 1]
[ 86 2 214]
[ 87 42 24]
[233 2 39]
[ 14 1 4]
[118 169 27]
[102 115 5]
[ 8 126 75]
[237 147 40]
[ 2 12 108]
[ 32 2 222]
[132 139 71]
[249 4 14]
[224 18 76]
[216 3 67]
[ 47 202 23]
[ 2 4 38]
[ 19 31 253]
[ 42 90 3]
[ 17 8 228]
[ 13 194 251]
[ 6 35 18]
[ 0 210 175]
[ 1 224 33]
[ 27 1 16]
[134 255 136]
[251 5 94]
[ 2 109 47]
[123 228 204]
[101 208 30]
[228 173 72]
[ 16 63 1]
[ 89 42 33]
[171 27 1]
[ 98 66 74]
[ 33 39 118]
[ 9 46 53]
[ 0 112 3]
[ 5 12 31]
[125 65 81]
[ 24 159 32]
[ 16 73 196]
[214 4 126]
[173 0 173]
[ 1 166 13]
[ 42 7 60]
[ 7 5 12]
[180 34 54]
[ 10 222 63]
[196 59 166]
[ 72 16 149]
[177 106 120]
[243 5 42]
[160 52 14]
[190 125 241]
[ 15 75 6]
[220 23 1]
[ 38 44 190]
[ 10 171 2]
[115 74 6]
[ 7 128 105]
[184 22 7]
[ 83 97 178]
[ 12 177 129]
[144 116 49]
[149 71 101]
[ 58 0 1]
[ 55 129 42]
[ 93 196 41]
[ 6 86 112]
[ 13 23 68]
[ 46 136 93]
[ 1 3 19]
[147 6 102]
[ 17 21 0]
[ 11 4 168]
[ 16 4 192]
[ 29 190 5]
[ 22 102 182]
[ 88 10 106]
[ 1 26 216]
[ 3 29 22]
[ 4 149 239]
[ 12 16 162]
[ 56 212 37]
[204 43 5]
[ 4 17 29]
[218 198 82]
[ 11 168 9]
[ 1 28 96]
[ 67 108 0]
[ 66 98 255]
[ 45 27 26]
[120 0 125]
[ 96 2 11]
[ 71 218 137]
[ 0 87 5]
[ 18 39 210]
[ 77 0 48]
[ 68 0 235]
[202 62 144]
[ 0 11 208]
[206 243 20]
[ 70 41 10]
[126 15 84]
[ 0 123 12]
[ 64 188 194]
[ 49 120 186]
[ 97 233 0]
[109 0 66]
[222 11 164]
[239 6 0]
[ 22 21 8]
[188 239 98]
[ 24 1 77]
[ 40 113 45]
[142 22 2]
[212 160 51]
[ 0 18 6]
[110 2 8]
[ 82 88 245]
[ 76 40 159]
[ 99 204 1]
[162 237 150]
[ 20 155 80]
[113 184 169]
[ 2 0 4]
[231 45 8]
[ 37 14 131]
[ 2 145 65]
[104 24 99]
[ 62 150 10]
[ 0 6 23]
[ 36 54 110]
[108 241 142]
[105 105 64]
[198 68 21]
[ 0 154 123]
[ 2 11 237]
[208 32 19]
[ 54 13 36]
[ 3 24 87]
[ 65 84 249]
[ 5 0 62]
[ 1 31 115]
[ 19 77 188]
[ 57 119 122]
[ 39 50 4]
[ 11 64 29]
[164 29 28]
[ 50 7 1]
[ 63 142 92]
[128 1 0]
[ 5 180 78]
[154 70 61]
[241 19 16]
[ 18 13 113]
[ 5 235 18]
[ 1 82 0]
[ 44 60 1]
[ 0 49 212]
[112 36 202]
[ 1 47 0]
[ 35 0 31]
[ 8 57 9]
[ 3 134 2]
[ 2 96 97]
[ 0 89 21]
[ 36 6 57]
[ 6 175 34]
[255 33 184]
[ 3 78 140]
[169 182 25]
[ 15 162 198]
[ 30 122 22]
[ 21 220 206]
[245 94 55]
[136 0 233]
[ 4 2 88]
[200 67 152]
[ 57 10 9]
[ 74 164 0]
[ 92 152 46]
[255 255 255]]

13 changes: 3 additions & 10 deletions src/dataset/path_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,11 @@ def get_dataset_path(name):

if name == 'ChangeSim':
"""
├── dark_test_list.txt
├── dust_test_list.txt
├── idx2color.txt
├── Query
│ ├── Query_Seq_Test
│ └── Query_Seq_Train
├── Reference
│ ├── Ref_Seq_Test
│ └── Ref_Seq_Train
├── test_list.txt
├── test_split.txt
├── train_list.txt
└── train_split.txt
└── Reference
├── Ref_Seq_Test
└── Ref_Seq_Train
"""
return '/data_path/ChangeSim'
5 changes: 5 additions & 0 deletions src/dataset/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,15 @@ def __call__(self, image, target):
return image, target

class PILToTensor:
def __init__(self, target_transform=None):
self.target_transform = target_transform

def __call__(self, image, target):
#image = F.pil_to_tensor(image)
image = proc_image(image, F.to_tensor)
target = torch.as_tensor(np.array(target).copy(), dtype=torch.int64)
if self.target_transform:
target = self.target_transform(target)
return image, target

class ConvertImageDtype:
Expand Down

0 comments on commit da13cff

Please sign in to comment.