facebook's implementation
This commit is contained in:
40
Tune.py
40
Tune.py
@@ -34,7 +34,7 @@ TRAINING_SMPLE = 27
|
||||
|
||||
# learning rate
|
||||
LR_RATE = 0.0001
|
||||
EPOCHS = 20
|
||||
EPOCHS = 10
|
||||
|
||||
# depends on model architecture
|
||||
# ResNet, DenseNet = 224
|
||||
@@ -109,7 +109,7 @@ print(f'> Constants : Classes = {CLASS_SIZE}, Batch = {BATCH_SIZE}, epochs = {EP
|
||||
device = SetUp.get_device()
|
||||
|
||||
|
||||
for i in range(0,CLASS_SIZE):
|
||||
for i in range(0,1):#CLASS_SIZE):
|
||||
FORGET_CLASS_IDX = i
|
||||
# Create model using Factory
|
||||
model = Model.create(
|
||||
@@ -118,13 +118,13 @@ for i in range(0,CLASS_SIZE):
|
||||
size = CLASS_SIZE)
|
||||
|
||||
# we may need to load existing model or finetune
|
||||
model.train(
|
||||
epochs = EPOCHS,
|
||||
loader = train_loader,
|
||||
rate = LR_RATE)
|
||||
#model.train(
|
||||
# epochs = EPOCHS,
|
||||
# loader = train_loader,
|
||||
# rate = LR_RATE)
|
||||
|
||||
# save.
|
||||
model.save(filename=arch.name.lower())
|
||||
#model.save(filename=arch.name.lower())
|
||||
|
||||
|
||||
# done tuning
|
||||
@@ -147,10 +147,10 @@ for i in range(0,CLASS_SIZE):
|
||||
|
||||
# Evaluate
|
||||
current_mode = "Finetuned"
|
||||
accuracy, report_dict = model.evaluate(
|
||||
loader = test_loader,
|
||||
mode=current_mode
|
||||
)
|
||||
#accuracy, report_dict = model.evaluate(
|
||||
# loader = test_loader,
|
||||
# mode=current_mode
|
||||
#)
|
||||
|
||||
Util._log_to_csv(
|
||||
arch=model.__class__.__name__,
|
||||
@@ -161,13 +161,13 @@ for i in range(0,CLASS_SIZE):
|
||||
)
|
||||
|
||||
# unlearning algorithms
|
||||
linear_filtration = LinearFiltration(target_class_idx=FORGET_CLASS_IDX)
|
||||
#linear_filtration = LinearFiltration(target_class_index=FORGET_CLASS_IDX)
|
||||
#filtration.apply(reloaded.model)
|
||||
|
||||
weight_filtration = WeightFiltration(num_classes = CLASS_SIZE,target_class_idx=FORGET_CLASS_IDX)
|
||||
#weight_filtration = WeightFiltration(num_classes = CLASS_SIZE,target_class_idx=FORGET_CLASS_IDX)
|
||||
#weight_filtration.apply(reloaded.model)
|
||||
|
||||
certified_removal = CertifiedRemoval(removal_bound=0.05, epsilon=0.5, l2_reg=0.1)
|
||||
certified_removal = CertifiedRemoval(target_class_index=FORGET_CLASS_IDX,removal_bound=0.05, epsilon=0.5, l2_reg=15)
|
||||
#certified_removal.apply(reloaded.model)
|
||||
|
||||
# to be unlearned
|
||||
@@ -179,14 +179,14 @@ for i in range(0,CLASS_SIZE):
|
||||
|
||||
# to evaluate
|
||||
forget_test_loader, retain_test_loader = get_unlearning_loaders(
|
||||
dataset=test_data,
|
||||
forget_class_idx=FORGET_CLASS_IDX,
|
||||
batch_size=BATCH_SIZE
|
||||
)
|
||||
dataset=test_data,
|
||||
forget_class_idx=FORGET_CLASS_IDX,
|
||||
batch_size=BATCH_SIZE
|
||||
)
|
||||
|
||||
|
||||
strategies = [linear_filtration, weight_filtration, certified_removal]
|
||||
#strategies = [linear_filtration]
|
||||
#strategies = [linear_filtration, weight_filtration, certified_removal]
|
||||
strategies = [certified_removal]
|
||||
for strategy in strategies:
|
||||
# test again
|
||||
reloaded = Model.create(
|
||||
|
||||
Reference in New Issue
Block a user