├── net.png ├── model ├── DWConv ├── SWBCE ├── metric_tool └── network ├── README.md ├── attention ├── coordatt └── BAM └── LICENSE /net.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zjd1836/AERNet/HEAD/net.png -------------------------------------------------------------------------------- /model/DWConv: -------------------------------------------------------------------------------- 1 | import torch.nn as nn 2 | class DWConv(nn.Module): 3 | def __init__(self, in_ch, out_ch): 4 | super(DWConv, self).__init__() 5 | self.depth_conv = nn.Conv2d( 6 | in_channels=in_ch, 7 | out_channels=in_ch, 8 | kernel_size=3, 9 | stride=1, 10 | padding=1, 11 | groups=in_ch 12 | ) 13 | self.point_conv = nn.Sequential( 14 | nn.Conv2d(in_channels=in_ch,out_channels=out_ch,kernel_size=1,stride=1,padding=0,groups=1), 15 | nn.BatchNorm2d(out_ch), 16 | nn.ReLU6(inplace=True)) 17 | 18 | 19 | def forward(self, input): 20 | out = self.depth_conv(input) 21 | out = self.point_conv(out) 22 | return out 23 | 24 | -------------------------------------------------------------------------------- /model/SWBCE: -------------------------------------------------------------------------------- 1 | import torch.nn as nn 2 | import torch 3 | import torch.nn.functional as F 4 | from metric_tool import SegEvaluator 5 | 6 | class WeightedBCEWithLogitsLoss(nn.Module): 7 | def __init__(self): 8 | super(WeightedBCEWithLogitsLoss,self).__init__() 9 | 10 | def forward(self, input, target): 11 | 12 | 13 | evaluator = SegEvaluator(1) 14 | evaluator.reset() 15 | pred = torch.where(torch.sigmoid(input) > 0.5, 1, 0) 16 | evaluator.add_batch(gt_image=target.cpu().numpy(), pre_image=pred.cpu().numpy()) 17 | w_00,w_11 = evaluator.loss_weight() 18 | weight1 = torch.zeros_like(target) 19 | weight1 = torch.fill_(weight1, w_00) 20 | weight1[target > 0] = w_11 21 | loss = F.binary_cross_entropy_with_logits(input, target,weight=weight1,reduction="mean") 22 | 23 | return loss 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AERNet: An Attention-Guided Edge Refinement Network and a Dataset for Remote Sensing Building Change Detection 2 | For more ore information, please see our published paper at [IEEE TGRS](https://ieeexplore.ieee.org/abstract/document/10209204) 3 | ![AERNet](net.png) 4 | # Requirements 5 | Python 3.6 6 | pytorch 1.7.1 7 | torchvision 0.8.2 8 | CUDA 10.1 9 | # HRCUS-CD 10 | HRCUS-CD: 链接:http://www.lmars.whu.edu.cn/prof_web/shaozhenfeng/softwares.html 11 | # Citation 12 | If you use this code or dataset for your research, please cite our paper: 13 | 14 | J. Zhang et al., "AERNet: An Attention-Guided Edge Refinement Network and a Dataset for Remote Sensing Building Change Detection," in IEEE Transactions on Geoscience and Remote Sensing, vol. 61, pp. 1-16, 2023, Art no. 5617116, doi: 10.1109/TGRS.2023.3300533. 15 | 16 | or 17 | 18 | @ARTICLE{10209204, 19 | author={Zhang, Jindou and Shao, Zhenfeng and Ding, Qing and Huang, Xiao and Wang, Yu and Zhou, Xuechao and Li, Deren}, 20 | journal={IEEE Transactions on Geoscience and Remote Sensing}, 21 | title={AERNet: An Attention-Guided Edge Refinement Network and a Dataset for Remote Sensing Building Change Detection}, 22 | year={2023}, 23 | volume={61}, 24 | number={}, 25 | pages={1-16}, 26 | doi={10.1109/TGRS.2023.3300533}} 27 | -------------------------------------------------------------------------------- /attention/coordatt: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | import math 4 | import torch.nn.functional as F 5 | 6 | 7 | class h_sigmoid(nn.Module): 8 | def __init__(self, inplace=True): 9 | super(h_sigmoid, self).__init__() 10 | self.relu = nn.ReLU6(inplace=inplace) 11 | 12 | def forward(self, x): 13 | return self.relu(x + 3) / 6 14 | 15 | 16 | class h_swish(nn.Module): 17 | def __init__(self, inplace=True): 18 | super(h_swish, self).__init__() 19 | self.sigmoid = h_sigmoid(inplace=inplace) 20 | 21 | def forward(self, x): 22 | return x * self.sigmoid(x) 23 | 24 | 25 | class CoordAtt(nn.Module): 26 | def __init__(self, inp, oup, reduction=32): 27 | super(CoordAtt, self).__init__() 28 | self.pool_h = nn.AdaptiveAvgPool2d((None, 1)) 29 | self.pool_w = nn.AdaptiveAvgPool2d((1, None)) 30 | 31 | mip = max(8, inp // reduction) 32 | 33 | self.conv1 = nn.Conv2d(inp, mip, kernel_size=1, stride=1, padding=0) 34 | self.bn1 = nn.BatchNorm2d(mip) 35 | self.act = h_swish() 36 | 37 | self.conv_h = nn.Conv2d(mip, oup, kernel_size=1, stride=1, padding=0) 38 | self.conv_w = nn.Conv2d(mip, oup, kernel_size=1, stride=1, padding=0) 39 | 40 | def forward(self, x): 41 | identity = x 42 | 43 | n, c, h, w = x.size() 44 | x_h = self.pool_h(x) 45 | x_w = self.pool_w(x).permute(0, 1, 3, 2) 46 | 47 | y = torch.cat([x_h, x_w], dim=2) 48 | y = self.conv1(y) 49 | y = self.bn1(y) 50 | y = self.act(y) 51 | 52 | x_h, x_w = torch.split(y, [h, w], dim=2) 53 | x_w = x_w.permute(0, 1, 3, 2) 54 | 55 | a_h = self.conv_h(x_h).sigmoid() 56 | a_w = self.conv_w(x_w).sigmoid() 57 | 58 | out = identity * a_w * a_h 59 | 60 | 61 | return out 62 | 63 | if __name__ == '__main__': 64 | 65 | test_data = torch.rand(2,256,64,64).cuda() 66 | model = CoordAtt(256,256) 67 | model = model.cuda() 68 | output = model(test_data) 69 | 70 | 71 | -------------------------------------------------------------------------------- /attention/BAM: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn.functional as F 3 | from torch import nn 4 | 5 | 6 | class BAM(nn.Module): 7 | """ Basic self-attention module 8 | """ 9 | 10 | def __init__(self, in_dim, ds=8, activation=nn.ReLU): 11 | super(BAM, self).__init__() 12 | self.chanel_in = in_dim 13 | self.key_channel = self.chanel_in //8 14 | self.activation = activation 15 | self.ds = ds # 16 | self.pool = nn.AvgPool2d(self.ds) 17 | self.query_conv = nn.Conv2d(in_channels=in_dim, out_channels=in_dim // 8, kernel_size=1) 18 | self.key_conv = nn.Conv2d(in_channels=in_dim, out_channels=in_dim // 8, kernel_size=1) 19 | self.value_conv = nn.Conv2d(in_channels=in_dim, out_channels=in_dim, kernel_size=1) 20 | self.gamma = nn.Parameter(torch.zeros(1)) 21 | 22 | self.softmax = nn.Softmax(dim=-1) # 23 | 24 | def forward(self, input): 25 | """ 26 | inputs : 27 | x : input feature maps( B X C X W X H) 28 | returns : 29 | out : self attention value + input feature 30 | attention: B X N X N (N is Width*Height) 31 | """ 32 | x = self.pool(input) 33 | m_batchsize, C, width, height = x.size() 34 | proj_query = self.query_conv(x).view(m_batchsize, -1, width * height).permute(0, 2, 1) # B X C X (N)/(ds*ds) 35 | proj_key = self.key_conv(x).view(m_batchsize, -1, width * height) # B X C x (*W*H)/(ds*ds) 36 | energy = torch.bmm(proj_query, proj_key) # transpose check 37 | energy = (self.key_channel**-.5) * energy 38 | 39 | attention = self.softmax(energy) # BX (N) X (N)/(ds*ds)/(ds*ds) 40 | 41 | proj_value = self.value_conv(x).view(m_batchsize, -1, width * height) # B X C X N 42 | 43 | out = torch.bmm(proj_value, attention.permute(0, 2, 1)) 44 | out = out.view(m_batchsize, C, width, height) 45 | 46 | out = F.interpolate(out, [width*self.ds,height*self.ds]) 47 | out = out + input 48 | 49 | return out 50 | 51 | 52 | -------------------------------------------------------------------------------- /model/metric_tool: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | 4 | class SegEvaluator: 5 | def __init__(self, class_num=4): 6 | if class_num == 1: 7 | class_num = 2 8 | self.num_class = class_num 9 | self.confusion_matrix = np.zeros((self.num_class,) * 2) 10 | 11 | def kappa(self,OA): 12 | pe_rows = np.sum(self.confusion_matrix, axis=0) 13 | pe_cols = np.sum(self.confusion_matrix, axis=1) 14 | sum_total = np.sum(self.confusion_matrix) 15 | pe = np.dot(pe_rows, pe_cols) / (sum_total ** 2) 16 | #po = self.pixel_oa() 17 | po = OA 18 | return (po - pe) / (1 - pe) 19 | 20 | def _generate_matrix(self, gt_image, pre_image): 21 | mask = (gt_image >= 0) & (gt_image < self.num_class) 22 | label = self.num_class * gt_image[mask].astype('int') + pre_image[mask] 23 | count = np.bincount(label, minlength=self.num_class ** 2) 24 | confusion_matrix = count.reshape(self.num_class, self.num_class) 25 | return confusion_matrix 26 | 27 | 28 | def add_batch(self, gt_image, pre_image): 29 | assert gt_image.shape == pre_image.shape 30 | self.confusion_matrix += self._generate_matrix(gt_image, pre_image) 31 | self.mat=self.confusion_matrix 32 | 33 | def reset(self): 34 | self.confusion_matrix = np.zeros((self.num_class,) * 2) 35 | 36 | def loss_weight(self): 37 | TN = self.confusion_matrix[0][0] 38 | FP = self.confusion_matrix[0][1] 39 | FN = self.confusion_matrix[1][0] 40 | TP = self.confusion_matrix[1][1] 41 | w_00 = TP / (TP + FP + FN) 42 | w_11 = TN / (TN + FN + FP) 43 | return w_00, w_11 44 | 45 | def matrix(self,class_index): 46 | metric = {} 47 | recall = 0.0 48 | precision = 0.0 49 | for i in range(self.num_class): 50 | recall += self.confusion_matrix[i, i] / (np.sum(self.confusion_matrix[:, i]) + 1e-8) 51 | precision += self.confusion_matrix[i, i] / (np.sum(self.confusion_matrix[i, :]) + 1e-8) 52 | precision_cls = np.diag(self.confusion_matrix) / self.confusion_matrix.sum(axis=1) 53 | recall_cls = np.diag(self.confusion_matrix) / self.confusion_matrix.sum(axis=0) 54 | OA = np.diag(self.confusion_matrix).sum() / self.confusion_matrix.sum() 55 | iou_per_class = np.diag(self.confusion_matrix) / ( 56 | np.sum(self.confusion_matrix, axis=1) + 57 | np.sum(self.confusion_matrix, axis=0) - 58 | np.diag(self.confusion_matrix)) 59 | metric['0_IoU'] = iou_per_class[0] 60 | metric['1_IoU'] = iou_per_class[1] 61 | metric['IoU'] = np.nanmean(iou_per_class) 62 | metric['Precision'] = precision_cls[class_index] #precision / self.num_class 63 | metric['Recall'] = recall_cls[class_index] #recall / self.num_class 64 | metric['OA'] = OA 65 | metric['F1'] = (2 * precision_cls[class_index] * recall_cls[class_index]) / (precision_cls[class_index] + recall_cls[class_index]) 66 | Kappa = self.kappa(OA) 67 | metric['Kappa'] = Kappa 68 | return metric 69 | -------------------------------------------------------------------------------- /model/network: -------------------------------------------------------------------------------- 1 | import math 2 | import cv2 3 | import torch 4 | import torch.nn as nn 5 | from attention.BAM import BAM 6 | import torch.utils.model_zoo as model_zoo 7 | from attention.coordatt import CoordAtt 8 | from models.DWConv import DWConv 9 | 10 | 11 | class zh_net(nn.Module): 12 | def __init__(self, freeze_bn=False): 13 | super(zh_net, self).__init__() 14 | self.encoder = resnet34() #在此处可切换backbone 15 | self.decoder = Decoder() 16 | 17 | if freeze_bn: 18 | self.freeze_bn() 19 | 20 | def forward(self, A, B): 21 | output1 = self.encoder(A) 22 | output2 = self.encoder(B) 23 | result = self.decoder(output1, output2) 24 | return result 25 | 26 | def freeze_bn(self): 27 | for m in self.modules(): 28 | if isinstance(m, nn.BatchNorm2d): 29 | m.eval() 30 | 31 | 32 | 33 | def conv3x3(in_planes, out_planes, stride=1): 34 | "3x3 convolution with padding" 35 | return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, 36 | padding=1, bias=False) 37 | 38 | 39 | model_urls = { 40 | 'resnet18': 'https://download.pytorch.org/models/resnet18-5c106cde.pth', 41 | 'resnet34': 'https://download.pytorch.org/models/resnet34-333f7ec4.pth', 42 | 'resnet50': 'https://download.pytorch.org/models/resnet50-19c8e357.pth',} 43 | 44 | class BasicBlock(nn.Module): 45 | expansion = 1 46 | 47 | def __init__(self, inplanes, planes, stride=1, downsample=None): 48 | super(BasicBlock, self).__init__() 49 | self.conv1 = conv3x3(inplanes, planes, stride) 50 | self.bn1 = nn.BatchNorm2d(planes) 51 | self.relu = nn.ReLU(inplace=True) 52 | self.conv2 = conv3x3(planes, planes) 53 | self.bn2 = nn.BatchNorm2d(planes) 54 | self.downsample = downsample 55 | self.stride = stride 56 | 57 | def forward(self, x): 58 | residual = x 59 | out = self.conv1(x) 60 | out = self.bn1(out) 61 | out = self.relu(out) 62 | out = self.conv2(out) 63 | out = self.bn2(out) 64 | if self.downsample is not None: 65 | residual = self.downsample(x) 66 | out += residual 67 | out = self.relu(out) 68 | 69 | return out 70 | 71 | 72 | class ResNet(nn.Module): 73 | def __init__(self, block, layers): 74 | self.inplanes = 64 75 | super(ResNet, self).__init__() 76 | self.conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3, 77 | bias=False) 78 | self.bn1 = nn.BatchNorm2d(64) 79 | self.relu = nn.ReLU(inplace=True) 80 | self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1) 81 | self.layer1 = self._make_layer(block, 64, layers[0]) 82 | self.layer2 = self._make_layer(block, 128, layers[1], stride=2) 83 | self.layer3 = self._make_layer(block, 256, layers[2], stride=2) 84 | self.layer4 = self._make_layer(block, 512, layers[3], stride=2) 85 | 86 | for m in self.modules(): 87 | if isinstance(m, nn.Conv2d): 88 | n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels 89 | m.weight.data.normal_(0, math.sqrt(2. / n)) 90 | elif isinstance(m, nn.BatchNorm2d): 91 | m.weight.data.fill_(1) 92 | m.bias.data.zero_() 93 | 94 | def _load_pretrained_model(self, model_path): 95 | pretrain_dict = model_zoo.load_url(model_path) 96 | model_dict = {} 97 | state_dict = self.state_dict() 98 | for k, v in pretrain_dict.items(): 99 | if k in state_dict: 100 | model_dict[k] = v 101 | state_dict.update(model_dict) 102 | self.load_state_dict(state_dict) 103 | 104 | def _make_layer(self, block, planes, blocks, stride=1): 105 | downsample = None 106 | if stride != 1 or self.inplanes != planes * block.expansion: 107 | downsample = nn.Sequential( 108 | nn.Conv2d(self.inplanes, planes * block.expansion, 109 | kernel_size=1, stride=stride, bias=False), 110 | nn.BatchNorm2d(planes * block.expansion), 111 | ) 112 | 113 | layers = [] 114 | layers.append(block(self.inplanes, planes, stride, downsample)) 115 | self.inplanes = planes * block.expansion 116 | for i in range(1, blocks): 117 | layers.append(block(self.inplanes, planes)) 118 | 119 | return nn.Sequential(*layers) 120 | 121 | def forward(self, x): 122 | feature = [] 123 | x = self.conv1(x) 124 | x = self.bn1(x) 125 | x = self.relu(x) 126 | feature.append(x) 127 | x = self.maxpool(x) 128 | x = self.layer1(x) 129 | feature.append(x) 130 | x = self.layer2(x) 131 | feature.append(x) 132 | x = self.layer3(x) 133 | feature.append(x) 134 | x = self.layer4(x) 135 | feature.append(x) 136 | return feature 137 | 138 | 139 | def resnet34(pretrained=True): 140 | """Constructs a ResNet-34 model.""" 141 | model = ResNet(BasicBlock, [3, 4, 6, 3]) 142 | if pretrained: 143 | model._load_pretrained_model(model_urls['resnet34']) 144 | return model 145 | 146 | 147 | class decoder_block(nn.Module): 148 | def __init__(self,in_channels, out_channels): 149 | super(decoder_block, self).__init__() 150 | 151 | self.de_block1 = nn.Sequential( 152 | nn.Conv2d(in_channels, out_channels, kernel_size=1), 153 | nn.BatchNorm2d(out_channels), 154 | nn.ReLU()) 155 | 156 | self.de_block2 = DWConv(out_channels, out_channels) 157 | 158 | self.att = CoordAtt(out_channels,out_channels) 159 | 160 | self.de_block3 = DWConv(out_channels, out_channels) 161 | 162 | self.de_block4 = nn.Conv2d(out_channels, 1, 1) 163 | 164 | self.de_block5 = nn.ConvTranspose2d(out_channels, out_channels, kernel_size=2, stride=2) 165 | 166 | def forward(self, input1, input, input2): 167 | 168 | x0 = torch.cat((input1, input, input2), dim=1) 169 | x0 = self.de_block1(x0) 170 | x = self.de_block2(x0) 171 | x = self.att(x) 172 | x = self.de_block3(x) 173 | x = x + x0 174 | al = self.de_block4(x) 175 | result = self.de_block5(x) 176 | 177 | return al, result 178 | 179 | class ref_seg(nn.Module): 180 | def __init__(self): 181 | super(ref_seg, self).__init__() 182 | self.dir_head = nn.Sequential(nn.Conv2d(32, 32, 1, 1), nn.BatchNorm2d(32), nn.ReLU(), nn.Conv2d(32, 8, 1, 1)) 183 | self.conv0=nn.Conv2d(1,8,3,1,1,bias=False) 184 | self.conv0.weight = nn.Parameter(torch.tensor([[[[0,0, 0], [1, 0, 0], [0, 0, 0]]], 185 | [[[1,0, 0], [0, 0, 0], [0, 0, 0]]], 186 | [[[0,1, 0], [0, 0, 0], [0, 0, 0]]], 187 | [[[0,0, 1], [0, 0, 0], [0, 0, 0]]], 188 | [[[0,0, 0], [0, 0, 1], [0, 0, 0]]], 189 | [[[0,0, 0], [0, 0, 0], [0, 0, 1]]], 190 | [[[0,0, 0], [0, 0, 0], [0, 1, 0]]], 191 | [[[0,0, 0], [0, 0, 0], [1, 0, 0]]]]).float()) 192 | def forward(self,x,masks_pred,edge_pred): 193 | direc_pred = self.dir_head(x) 194 | direc_pred=direc_pred.softmax(1) 195 | edge_mask=1*(torch.sigmoid(edge_pred).detach()>0.5) 196 | refined_mask_pred=(self.conv0(masks_pred)*direc_pred).sum(1).unsqueeze(1)*edge_mask+masks_pred*(1-edge_mask) 197 | return refined_mask_pred 198 | 199 | class Decoder(nn.Module): 200 | def __init__(self): 201 | super(Decoder, self).__init__() 202 | 203 | self.bam = BAM(1024) 204 | self.db1 = nn.Sequential( 205 | nn.Conv2d(1024, 512, 1), nn.BatchNorm2d(512), nn.ReLU(), 206 | DWConv(512, 512), 207 | nn.ConvTranspose2d(512, 512, kernel_size=2, stride=2) 208 | ) 209 | 210 | self.db2 = decoder_block(1024, 256) 211 | self.db3 = decoder_block(512, 128) 212 | self.db4 = decoder_block(256, 64) 213 | self.db5 = decoder_block(192, 32) 214 | 215 | self.classifier1 = nn.Sequential( 216 | nn.Conv2d(32, 32, 3, 1, 1), nn.BatchNorm2d(32), nn.ReLU(), nn.Conv2d(32, 1, 1)) 217 | 218 | self.classifier2 = nn.Sequential( 219 | nn.Conv2d(32+1, 32, 3, 1, 1), nn.BatchNorm2d(32), nn.ReLU(), nn.Conv2d(32, 1, 1)) 220 | self.interpo = nn.Upsample(scale_factor=2, mode='bilinear', align_corners=True) 221 | self.refine = ref_seg() 222 | self._init_weight() 223 | 224 | def forward(self,input1,input2): 225 | input1_1, input2_1, input3_1, input4_1, input5_1 = input1[0], input1[1], input1[2], input1[3], input1[4] 226 | input1_2, input2_2, input3_2, input4_2, input5_2 = input2[0], input2[1], input2[2], input2[3], input2[4] 227 | 228 | x = torch.cat((input5_1, input5_2),dim=1) 229 | x = self.bam(x) 230 | x = self.db1(x) 231 | 232 | #512*16*16 233 | al1,x = self.db2(input4_1, x, input4_2) #256*32*32 234 | al2,x = self.db3(input3_1, x, input3_2) #128*64*64 235 | al3,x = self.db4(input2_1, x, input2_2) #64*128*128 236 | al4,x = self.db5(input1_1, x, input1_2) #32*256*256 237 | 238 | edge = self.classifier1(x) 239 | seg = self.classifier2(torch.cat((x, self.interpo(al4)), 1)) 240 | result = self.refine(x, seg, edge) 241 | 242 | return al1,al2,al3,al4,result,seg 243 | 244 | def _init_weight(self): 245 | for m in self.modules(): 246 | if isinstance(m, nn.Conv2d): 247 | torch.nn.init.kaiming_normal_(m.weight) 248 | elif isinstance(m, nn.BatchNorm2d): 249 | m.weight.data.fill_(1) 250 | m.bias.data.zero_() 251 | 252 | 253 | if __name__ == '__main__': 254 | 255 | test_data1 = torch.rand(2,3,256,256).cuda() 256 | test_data2 = torch.rand(2,3,256,256).cuda() 257 | test_label = torch.randint(0, 2, (2,1,256,256)).cuda() 258 | 259 | model = zh_net() 260 | model = model.cuda() 261 | output = model(test_data1,test_data2) 262 | 263 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------