diff --git a/config.yaml b/config.yaml index 2a67f10..03b6560 100644 --- a/config.yaml +++ b/config.yaml @@ -1,7 +1,7 @@ # config for shadow CFG: DEBUG: false - num_accessible_probs: 10 # match with accessible classes logits/probability classes number from the target model. usually top 5 for APIs + topk_num_accessible_probs: 10 # topk match with accessible classes logits/probability classes number from the target model. usually top 5 for APIs num_epochs: 25 # number of shadow model train epochs val_acc_goal: -1 # shadow model's goal accuracy working as early stop. -1 for not using early stop num_shadow_models: 100 diff --git a/shadow/make_data.py b/shadow/make_data.py index 5b08e48..709cbd6 100644 --- a/shadow/make_data.py +++ b/shadow/make_data.py @@ -39,7 +39,7 @@ def make_member_nonmember(finetuned_model, trainloader, valloader, criterion, de prob = F.softmax(output, dim=1) # softmax logits # get top inferred classes probability and append to member_dset - top_p, top_class = prob.topk(CFG.num_accessible_probs, dim=1) + top_p, top_class = prob.topk(CFG.topk_num_accessible_probs, dim=1) top_p = top_p.cpu().detach().numpy() # detach from cuda # loss = criterion(output, labels) member_dset.append(top_p) @@ -53,7 +53,7 @@ def make_member_nonmember(finetuned_model, trainloader, valloader, criterion, de prob = F.softmax(output, dim=1) # softmax logits # get top inferred classes probability and append to member_dset - top_p, top_class = prob.topk(CFG.num_accessible_probs, dim=1) + top_p, top_class = prob.topk(CFG.topk_num_accessible_probs, dim=1) top_p = top_p.cpu().detach().numpy() # detach from cuda # append to non_member_dset diff --git a/train_shadow.py b/train_shadow.py index 8c1061a..26e31ed 100644 --- a/train_shadow.py +++ b/train_shadow.py @@ -51,7 +51,7 @@ # define dataset for attack model that shadow models will generate print("mapped classes to ids:", trainset.class_to_idx) -columns_attack_sdet = [f"top_{index}_prob" for index in range(CFG.num_accessible_probs)] +columns_attack_sdet = [f"top_{index}_prob" for index in range(CFG.topk_num_accessible_probs)] df_attack_dset = pd.DataFrame({}, columns=columns_attack_sdet + ["is_member"]) # random subset for shadow model train & validation from the CIFAR trainset