Automatize Tutorials html, py files creation (#496)

* workflow to export tutorials

---------
This commit is contained in:
Dario Coscia
2025-03-15 11:01:19 +01:00
committed by Nicola Demo
parent aea24d0bee
commit 0146155c9b
51 changed files with 140529 additions and 440 deletions

View File

@@ -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%}\")"
]
},
{