Skip to content

Commit

Permalink
Merge pull request #2 from Koukyosyumei/same_api
Browse files Browse the repository at this point in the history
Same api
  • Loading branch information
Koukyosyumei authored Jun 20, 2021
2 parents 1242148 + ea3ff65 commit 98c0f5e
Show file tree
Hide file tree
Showing 18 changed files with 203 additions and 1,186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
"outputs": [],
"source": [
"X_minus_1 = X_train[np.where(y_train == \"3\")]\n",
"attacker = Evasion_attack_sklearn(clf = clf, X_minus_1 = X_minus_1,\n",
"attacker = Evasion_attack_sklearn(target_model = clf, X_minus_1 = X_minus_1,\n",
" dmax = (5000 / 255) * 2.5,\n",
" max_iter = 300,\n",
" gamma = 1 / (X_train.shape[1] * np.var(X_train)),\n",
Expand Down
4 changes: 2 additions & 2 deletions example/adversarial_example/example_poison_attack.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
"plt.title(\"poisoning attack against SVM\")\n",
"plt.xlabel(\"num of iterations\")\n",
"plt.ylabel(\"accuracy on validation data\")\n",
"plt.savefig(\"poison_loss.png\")\n",
"# plt.savefig(\"poison_loss.png\")\n",
"plt.show()"
]
},
Expand All @@ -143,7 +143,7 @@
"source": [
"plt.imshow(xc_attacked.reshape(28,28),cmap='gray')\n",
"plt.title(\"After Attack\")\n",
"plt.savefig(\"poison_example.png\")\n",
"# plt.savefig(\"poison_example.png\")\n",
"plt.show()"
]
},
Expand Down
84 changes: 38 additions & 46 deletions example/membership_inference/membership_inference_CIFAR10.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "subtle-teddy",
"id": "round-northern",
"metadata": {
"id": "crucial-backup"
},
Expand Down Expand Up @@ -32,7 +32,7 @@
},
{
"cell_type": "markdown",
"id": "legal-sister",
"id": "indian-candy",
"metadata": {
"id": "7XFU8Q1i9OUt"
},
Expand All @@ -43,7 +43,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "anonymous-junction",
"id": "upper-cambridge",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
Expand All @@ -59,7 +59,7 @@
},
{
"cell_type": "markdown",
"id": "novel-albany",
"id": "cheap-heath",
"metadata": {
"id": "still-column"
},
Expand All @@ -70,7 +70,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "racial-friend",
"id": "cloudy-investing",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
Expand All @@ -89,7 +89,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "coral-cedar",
"id": "terminal-couple",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
Expand All @@ -112,7 +112,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "flush-montgomery",
"id": "organized-visitor",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
Expand Down Expand Up @@ -144,7 +144,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "shaped-gamma",
"id": "dedicated-minister",
"metadata": {
"id": "norwegian-needle"
},
Expand All @@ -163,7 +163,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "developmental-survival",
"id": "regulated-details",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
Expand All @@ -178,7 +178,7 @@
},
{
"cell_type": "markdown",
"id": "provincial-newark",
"id": "brilliant-occasion",
"metadata": {
"id": "reserved-month"
},
Expand All @@ -189,7 +189,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "vulnerable-peter",
"id": "small-rebecca",
"metadata": {
"id": "special-sperm"
},
Expand Down Expand Up @@ -247,7 +247,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "treated-responsibility",
"id": "finished-mathematics",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
Expand All @@ -270,6 +270,7 @@
" inputs, labels = data\n",
" inputs = inputs.to(device)\n",
" labels = labels.to(device)\n",
" labels = labels.to(torch.int64)\n",
" # zero the parameter gradients\n",
" optimizer.zero_grad()\n",
"\n",
Expand Down Expand Up @@ -340,7 +341,7 @@
},
{
"cell_type": "markdown",
"id": "limited-kidney",
"id": "excellent-emission",
"metadata": {
"id": "DmKyjcOI9Wy5"
},
Expand All @@ -351,7 +352,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "innovative-individual",
"id": "stable-spencer",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
Expand Down Expand Up @@ -384,7 +385,7 @@
},
{
"cell_type": "markdown",
"id": "surface-daughter",
"id": "burning-supplier",
"metadata": {
"id": "selected-tournament"
},
Expand All @@ -395,7 +396,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "ahead-payment",
"id": "statistical-dominant",
"metadata": {
"id": "atomic-insulation"
},
Expand Down Expand Up @@ -450,39 +451,30 @@
{
"cell_type": "code",
"execution_count": null,
"id": "corporate-robertson",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "dmHcP0AB1Fqp",
"outputId": "d64a3497-ca7f-417d-dbb0-732e75a258fa"
},
"id": "fitting-webster",
"metadata": {},
"outputs": [],
"source": [
"shadow_models = [Net().to(device),\r\n",
" Net().to(device),\r\n",
" Net().to(device), \r\n",
" Net().to(device), \r\n",
" Net().to(device)]\r\n",
"shadow_data_size = 2000\r\n",
"shadow_transform = transform\r\n",
"\r\n",
"num_label = 10\r\n",
"attack_models = [SVC(probability=True) for i in range(10)]\r\n",
"\r\n",
"y_test = np.array(y_test)\r\n",
"\r\n",
"mi = Membership_Inference(shadow_models, attack_models,\r\n",
" shadow_data_size, shadow_transform)\r\n",
"mi.shadow(X_test, y_test, num_itr=20)\r\n",
"mi.attack()"
"shadow_models = [Net().to(device),\n",
" Net().to(device)]\n",
"shadow_data_size = 2000\n",
"shadow_transform = transform\n",
"\n",
"num_label = 10\n",
"attack_models = [SVC(probability=True) for i in range(num_label)]\n",
"\n",
"y_test = np.array(y_test).astype(np.int64)\n",
"\n",
"mi = Membership_Inference(victim_net, shadow_models, attack_models,\n",
" shadow_data_size, shadow_transform)\n",
"mi.train_shadow(X_test, y_test, num_itr=1)\n",
"mi.train_attacker()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "meaning-spirituality",
"id": "further-broadcasting",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
Expand All @@ -505,7 +497,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "sufficient-cream",
"id": "greenhouse-whole",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
Expand Down Expand Up @@ -535,7 +527,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "attempted-interference",
"id": "sustainable-thomson",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
Expand All @@ -553,7 +545,7 @@
" \r\n",
" plt.title(\"overfitting - membership inference performance\")\r\n",
" plt.xlabel(\"victim model: trian_accuracy - test_accuracy per class\")\r\n",
" plt.ylabel(\"attack model: auc per class\")\r\n",
" plt.ylabel(\"attack model: auc per clas# s\")\r\n",
"\r\n",
" plt.savefig(\"membership_inference_overfitting.png\")"
]
Expand All @@ -580,7 +572,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.6"
"version": "3.9.1"
}
},
"nbformat": 4,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 98c0f5e

Please sign in to comment.