Skip to content

Commit

Permalink
update learning method and some dpbasicblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
MekAkUActOR committed Dec 14, 2022
1 parent eb63008 commit d25b11c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
38 changes: 25 additions & 13 deletions code/deeppoly.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,34 @@ def forward(self, x):
'''
low > 0
'''
slope_low_1 = (F.relu(up) - F.relu(low)) / (up - low)
bias_low_1 = F.relu(low) - slope_low_1 * low
slope_up_1 = (F.relu(up) - F.relu(low)) / (up - low)
bias_up_1 = F.relu(up) - slope_up_1 * up
# slope_low_1 = (F.relu(up) - F.relu(low)) / (up - low)
# bias_low_1 = F.relu(low) - slope_low_1 * low
# slope_up_1 = (F.relu(up) - F.relu(low)) / (up - low)
# bias_up_1 = F.relu(up) - slope_up_1 * up
slope_low_1 = torch.ones(self.in_features)
bias_low_1 = torch.zeros(self.in_features)
slope_up_1 = torch.ones(self.in_features)
bias_up_1 = torch.zeros(self.in_features)
'''
up < 0
'''
slope_low_2 = (F.relu(up) - F.relu(low)) / (up - low)
bias_low_2 = F.relu(low) - slope_low_2 * low
slope_up_2 = F.relu(up) - F.relu(low) / (up - low)
bias_up_2 = F.relu(up) - slope_up_2 * up
# slope_low_2 = (F.relu(up) - F.relu(low)) / (up - low)
# bias_low_2 = F.relu(low) - slope_low_2 * low
# slope_up_2 = F.relu(up) - F.relu(low) / (up - low)
# bias_up_2 = F.relu(up) - slope_up_2 * up
slope_low_2 = torch.zeros(self.in_features)
bias_low_2 = torch.zeros(self.in_features)
slope_up_2 = torch.zeros(self.in_features)
bias_up_2 = torch.zeros(self.in_features)
'''
low < 0 < up
'''
# print("ALPHA: ", self.alpha)
# slope_low_3 = torch.tan(self.alpha)
# slope_low_3 = self.alpha
# bias_low_3 = slope_low_3 * low - slope_low_3 * low
# slope_up_3 = (F.relu(up) - F.relu(low)) / (up - low)
# bias_up_3 = F.relu(up) - slope_up_3 * up
slope_low_3 = self.alpha
bias_low_3 = slope_low_3 * low - slope_low_3 * low
slope_up_3 = (F.relu(up) - F.relu(low)) / (up - low)
Expand Down Expand Up @@ -339,10 +351,10 @@ def __init__(self, nested: resnet.BasicBlock, in_feature):
self.expansion = nested.expansion
self.path_a = nested.path_a
self.path_b = nested.path_b
self.paths = []
for modu in nested.modules():
if type(modu) == nn.Sequential:
self.paths.append(modu)
# self.paths = []
# for modu in nested.modules():
# if type(modu) == nn.Sequential:
# self.paths.append(modu)
self.in_feature = in_feature
img_height = math.floor(math.sqrt(in_feature / self.in_planes))
self.in_features = (
Expand All @@ -351,7 +363,7 @@ def __init__(self, nested: resnet.BasicBlock, in_feature):
img_height,
)
temp_img = torch.zeros(self.in_features)
output_shape = self.paths[0](temp_img).shape
output_shape = self.path_a(temp_img).shape
self.out_features = output_shape[0] * output_shape[1] * output_shape[2]

def forward(self, x):
Expand Down
4 changes: 2 additions & 2 deletions code/verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
DTYPE = torch.float32
LR = 0.7
num_iter = 10
lr_decay = 0.8
lr_decay = 0.75
lr_destep = 1

# class DeepPoly:
Expand Down Expand Up @@ -299,7 +299,7 @@ def analyze(net, inputs, eps, true_label):
for p in verifiable_net.parameters():
if p.requires_grad:
p.data.clamp_(0, 1)
if scheduler.get_last_lr()[0] > 0.2:
if scheduler.get_last_lr()[0] > 0.1:
scheduler.step()

optimizer.zero_grad()
Expand Down

0 comments on commit d25b11c

Please sign in to comment.