Skip to content

Commit

Permalink
clear output
Browse files Browse the repository at this point in the history
  • Loading branch information
Koukyosyumei committed Apr 16, 2021
1 parent bc3b77b commit 1242148
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 684 deletions.
105 changes: 16 additions & 89 deletions example/adversarial_example/example_evasion_attack_svm.ipynb

Large diffs are not rendered by default.

108 changes: 16 additions & 92 deletions example/adversarial_example/example_poison_attack.ipynb

Large diffs are not rendered by default.

128 changes: 29 additions & 99 deletions example/membership_inference/notebook/old/mnist.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "accepted-spank",
"execution_count": null,
"id": "dedicated-device",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -28,19 +28,10 @@
},
{
"cell_type": "code",
"execution_count": 2,
"id": "proved-indonesia",
"execution_count": null,
"id": "russian-profit",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(60000, 28, 28) (60000,)\n",
"(10000, 28, 28) (10000,)\n"
]
}
],
"outputs": [],
"source": [
"# トレーニングデータをダウンロード\n",
"trainset = torchvision.datasets.MNIST(root='./data', train=True, download=True)\n",
Expand All @@ -59,20 +50,10 @@
},
{
"cell_type": "code",
"execution_count": 3,
"id": "closing-celebration",
"execution_count": null,
"id": "ambient-basin",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(1000, 28, 28) (1000,)\n",
"(1000, 28, 28) (1000,)\n",
"(1000, 28, 28) (1000,)\n"
]
}
],
"outputs": [],
"source": [
"victim_idx = random.sample(range(X_train.shape[0]), k=1000)\n",
"attack_idx = random.sample(range(X_test.shape[0]), k=2000)\n",
Expand All @@ -95,8 +76,8 @@
},
{
"cell_type": "code",
"execution_count": 4,
"id": "purple-seating",
"execution_count": null,
"id": "sealed-shadow",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -112,8 +93,8 @@
},
{
"cell_type": "code",
"execution_count": 18,
"id": "czech-congo",
"execution_count": null,
"id": "charitable-brunswick",
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -144,40 +125,10 @@
},
{
"cell_type": "code",
"execution_count": 19,
"id": "overhead-detection",
"execution_count": null,
"id": "substantial-edwards",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.863\n",
"0.899\n",
"0.925\n",
"0.936\n",
"0.918\n",
"0.941\n",
"0.941\n",
"0.942\n",
"0.941\n",
"0.941\n",
"0.94\n",
"0.94\n",
"0.94\n",
"0.939\n",
"0.939\n",
"0.939\n",
"0.939\n",
"0.939\n",
"0.939\n",
"0.939\n",
"Finished Training\n",
"1.0\n",
"0.939\n"
]
}
],
"outputs": [],
"source": [
"# 交差エントロピー\n",
"criterion = nn.CrossEntropyLoss()\n",
Expand Down Expand Up @@ -252,16 +203,16 @@
},
{
"cell_type": "markdown",
"id": "entire-sponsorship",
"id": "complimentary-necessity",
"metadata": {},
"source": [
"# Shadow model"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "referenced-interference",
"execution_count": null,
"id": "classified-lunch",
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -291,23 +242,10 @@
},
{
"cell_type": "code",
"execution_count": 21,
"id": "automated-snapshot",
"execution_count": null,
"id": "related-missouri",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Finished Training\n",
"Finished Training\n",
"Finished Training\n",
"Finished Training\n",
"Finished Training\n",
"Finished Training\n"
]
}
],
"outputs": [],
"source": [
"sm = ShadowModel([Net(), Net(),Net(), Net(), Net(), Net()], 500, shadow_transform=transform)\n",
"y_shadow = np.array(y_shadow)\n",
Expand All @@ -316,16 +254,16 @@
},
{
"cell_type": "markdown",
"id": "electric-possible",
"id": "permanent-eligibility",
"metadata": {},
"source": [
"# Attack model"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "quick-incidence",
"execution_count": null,
"id": "tropical-physiology",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -340,26 +278,18 @@
},
{
"cell_type": "code",
"execution_count": 25,
"id": "visible-contractor",
"execution_count": null,
"id": "younger-camping",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"accuracy is 0.508\n"
]
}
],
"outputs": [],
"source": [
"print(\"accuracy is \", (sum(attack_pred_in) + 1000 - sum(attack_pred_out)) / 2000)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "periodic-raleigh",
"id": "facial-matter",
"metadata": {},
"outputs": [],
"source": []
Expand All @@ -381,7 +311,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.6"
"version": "3.9.1"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 1242148

Please sign in to comment.