|
3201 | 3201 | "from pathlib import Path\n", |
3202 | 3202 | "import os \n", |
3203 | 3203 | "\n", |
3204 | | - "DATA_FOLDER = Path(os.path.join(os.path.abspath(os.path.curdir), \"..\", \"..\")) / \"data\"" |
| 3204 | + "DATA_FOLDER = Path(os.path.join(os.path.abspath(os.path.curdir), \"..\")) / \"data\"" |
| 3205 | + ] |
| 3206 | + }, |
| 3207 | + { |
| 3208 | + "cell_type": "code", |
| 3209 | + "execution_count": null, |
| 3210 | + "metadata": {}, |
| 3211 | + "outputs": [], |
| 3212 | + "source": [ |
| 3213 | + "print(DATA_FOLDER)" |
3205 | 3214 | ] |
3206 | 3215 | }, |
3207 | 3216 | { |
|
3268 | 3277 | "metadata": {}, |
3269 | 3278 | "outputs": [], |
3270 | 3279 | "source": [ |
3271 | | - "PRETRAINED_MODEL_WEIGHTS = \"lenet_mnist_model.pth\"\n", |
| 3280 | + "if torch.cuda.is_available():\n", |
| 3281 | + " dev_name = \"cuda\"\n", |
| 3282 | + "else:\n", |
| 3283 | + " dev_name = \"cpu\"\n", |
3272 | 3284 | "\n", |
3273 | | - "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n", |
| 3285 | + "device = torch.device(dev_name)\n", |
| 3286 | + "print(f\"You will be using the {device} device\")" |
| 3287 | + ] |
| 3288 | + }, |
| 3289 | + { |
| 3290 | + "cell_type": "code", |
| 3291 | + "execution_count": null, |
| 3292 | + "metadata": {}, |
| 3293 | + "outputs": [], |
| 3294 | + "source": [ |
| 3295 | + "PRETRAINED_MODEL_WEIGHTS = \"lenet_mnist_model.pth\"\n", |
3274 | 3296 | "\n", |
3275 | 3297 | "# Initialize the network\n", |
3276 | 3298 | "model = Net().to(device)\n", |
|
3519 | 3541 | "\n", |
3520 | 3542 | "# Run test for each epsilon\n", |
3521 | 3543 | "for ε in EPSILONS[1:]:\n", |
3522 | | - " # your code here" |
| 3544 | + " acc, adv_examples = test(model, device, test_loader, ε)\n", |
| 3545 | + " accuracies.append(acc)\n", |
| 3546 | + " adv_examples_map[ε] = adv_examples" |
3523 | 3547 | ] |
3524 | 3548 | }, |
3525 | 3549 | { |
|
3605 | 3629 | "name": "python", |
3606 | 3630 | "nbconvert_exporter": "python", |
3607 | 3631 | "pygments_lexer": "ipython3", |
3608 | | - "version": "3.10.5" |
| 3632 | + "version": "3.9.16" |
3609 | 3633 | } |
3610 | 3634 | }, |
3611 | 3635 | "nbformat": 4, |
|
0 commit comments