Automatize Tutorials html, py files creation (#496)
* workflow to export tutorials ---------
This commit is contained in:
committed by
FilippoOlivo
parent
8dfc9d19db
commit
3ff9f0c9a2
33
tutorials/tutorial4/tutorial.ipynb
vendored
33
tutorials/tutorial4/tutorial.ipynb
vendored
@@ -35,26 +35,27 @@
|
||||
"source": [
|
||||
"## routine needed to run the notebook on Google Colab\n",
|
||||
"try:\n",
|
||||
" import google.colab\n",
|
||||
" IN_COLAB = True\n",
|
||||
"except:\n",
|
||||
" IN_COLAB = False\n",
|
||||
"if IN_COLAB:\n",
|
||||
" !pip install \"pina-mathlab\"\n",
|
||||
" import google.colab\n",
|
||||
"\n",
|
||||
"import torch \n",
|
||||
"import matplotlib.pyplot as plt \n",
|
||||
"import torchvision # for MNIST dataset\n",
|
||||
" IN_COLAB = True\n",
|
||||
"except:\n",
|
||||
" IN_COLAB = False\n",
|
||||
"if IN_COLAB:\n",
|
||||
" !pip install \"pina-mathlab\"\n",
|
||||
"\n",
|
||||
"import torch\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"import torchvision # for MNIST dataset\n",
|
||||
"import warnings\n",
|
||||
"\n",
|
||||
"from pina import Trainer\n",
|
||||
"from pina.problem.zoo import SupervisedProblem\n",
|
||||
"from pina.solver import SupervisedSolver\n",
|
||||
"from pina.trainer import Trainer\n",
|
||||
"from pina.model.block import ContinuousConvBlock \n",
|
||||
"from pina.model import FeedForward # for building AE and MNIST classification\n",
|
||||
"from pina.model.block import ContinuousConvBlock\n",
|
||||
"from pina.model import FeedForward # for building AE and MNIST classification\n",
|
||||
"\n",
|
||||
"warnings.filterwarnings('ignore')"
|
||||
"warnings.filterwarnings(\"ignore\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -517,7 +518,7 @@
|
||||
"source": [
|
||||
"# setting the problem\n",
|
||||
"problem = SupervisedProblem(\n",
|
||||
" input_=train_data.train_data.unsqueeze(1), # adding channel dimension\n",
|
||||
" input_=train_data.train_data.unsqueeze(1), # adding channel dimension\n",
|
||||
" output_=train_data.train_labels,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
@@ -568,7 +569,7 @@
|
||||
"source": [
|
||||
"correct = 0\n",
|
||||
"total = 0\n",
|
||||
"trainer.data_module.setup('test')\n",
|
||||
"trainer.data_module.setup(\"test\")\n",
|
||||
"with torch.no_grad():\n",
|
||||
" for data in trainer.data_module.test_dataloader():\n",
|
||||
" test_data = data[\"data\"]\n",
|
||||
@@ -580,9 +581,7 @@
|
||||
" total += labels.size(0)\n",
|
||||
" correct += (predicted == labels).sum().item()\n",
|
||||
"\n",
|
||||
"print(\n",
|
||||
" f\"Accuracy of the network on the test images: {(correct / total):.3%}\"\n",
|
||||
")"
|
||||
"print(f\"Accuracy of the network on the test images: {(correct / total):.3%}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user