Skip to content

Commit

Permalink
u
Browse files Browse the repository at this point in the history
  • Loading branch information
giovannivolpe committed Apr 21, 2024
1 parent fd885e8 commit a3cf12c
Show file tree
Hide file tree
Showing 3 changed files with 374 additions and 273 deletions.
153 changes: 88 additions & 65 deletions tutorials/getting-started/GS101_core_objects.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,12 @@
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "module 'deeplay' has no attribute 'LinearBlock'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[6], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m linear_block \u001b[38;5;241m=\u001b[39m \u001b[43mdl\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mLinearBlock\u001b[49m(in_features\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m10\u001b[39m, out_features\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m5\u001b[39m)\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28mprint\u001b[39m(linear_block)\n",
"\u001b[0;31mAttributeError\u001b[0m: module 'deeplay' has no attribute 'LinearBlock'"
"name": "stdout",
"output_type": "stream",
"text": [
"LinearBlock(\n",
" (layer): Layer[Linear](in_features=10, out_features=5, bias=True)\n",
")\n"
]
}
],
Expand All @@ -173,9 +171,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"LinearBlock(\n",
" (layer): Layer[Linear](in_features=10, out_features=5, bias=True)\n",
" (activation): Layer[ReLU]()\n",
")\n"
]
}
],
"source": [
"linear_block.activated(nn.ReLU)\n",
"\n",
Expand All @@ -191,11 +200,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"LinearBlock(\n",
" (layer): Linear(in_features=10, out_features=5, bias=True)\n",
" (activation): ReLU()\n",
")\n"
]
}
],
"source": [
"linear_block_with_activation = dl.LinearBlock(in_features=10, out_features=5, activation=dl.Layer(nn.ReLU)).build()\n",
"linear_block_with_activation = dl.LinearBlock(\n",
" in_features=10, \n",
" out_features=5, \n",
" activation=dl.Layer(nn.ReLU),\n",
").build()\n",
"\n",
"print(linear_block_with_activation)"
]
Expand All @@ -218,7 +242,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 9,
"metadata": {},
"outputs": [
{
Expand All @@ -227,17 +251,13 @@
"text": [
"MultiLayerPerceptron(\n",
" (blocks): LayerList(\n",
" (0): LayerActivationNormalizationDropout(\n",
" (layer): Layer[Linear](in_features=10, out_features=32)\n",
" (0): LinearBlock(\n",
" (layer): Layer[Linear](in_features=10, out_features=32, bias=True)\n",
" (activation): Layer[ReLU]()\n",
" (normalization): Layer[Identity](num_features=32)\n",
" (dropout): Layer[Dropout](p=0)\n",
" )\n",
" (1): LayerActivationNormalizationDropout(\n",
" (layer): Layer[Linear](in_features=32, out_features=5)\n",
" (1): LinearBlock(\n",
" (layer): Layer[Linear](in_features=32, out_features=5, bias=True)\n",
" (activation): Layer[ReLU]()\n",
" (normalization): Layer[Identity](num_features=5)\n",
" (dropout): Layer[Identity]()\n",
" )\n",
" )\n",
")\n"
Expand All @@ -264,19 +284,25 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 10,
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "'LayerActivationNormalizationDropout' object has no attribute 'activated'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[8], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mmlp_component\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mblocks\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mactivated\u001b[49m(nn\u001b[38;5;241m.\u001b[39mSigmoid)\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28mprint\u001b[39m(mlp_component)\n",
"File \u001b[0;32m~/miniconda3/envs/py310/lib/python3.10/site-packages/torch/nn/modules/module.py:1695\u001b[0m, in \u001b[0;36mModule.__getattr__\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m 1693\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m name \u001b[38;5;129;01min\u001b[39;00m modules:\n\u001b[1;32m 1694\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m modules[name]\n\u001b[0;32m-> 1695\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mAttributeError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mtype\u001b[39m(\u001b[38;5;28mself\u001b[39m)\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m object has no attribute \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mname\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
"\u001b[0;31mAttributeError\u001b[0m: 'LayerActivationNormalizationDropout' object has no attribute 'activated'"
"name": "stdout",
"output_type": "stream",
"text": [
"MultiLayerPerceptron(\n",
" (blocks): LayerList(\n",
" (0): LinearBlock(\n",
" (layer): Layer[Linear](in_features=10, out_features=32, bias=True)\n",
" (activation): Layer[Sigmoid]()\n",
" )\n",
" (1): LinearBlock(\n",
" (layer): Layer[Linear](in_features=32, out_features=5, bias=True)\n",
" (activation): Layer[ReLU]()\n",
" )\n",
" )\n",
")\n"
]
}
],
Expand All @@ -295,7 +321,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 11,
"metadata": {},
"outputs": [
{
Expand All @@ -304,16 +330,12 @@
"text": [
"MultiLayerPerceptron(\n",
" (blocks): LayerList(\n",
" (0): LayerActivationNormalizationDropout(\n",
" (layer): Layer[Linear](in_features=10, out_features=32)\n",
" (normalization): Layer[Identity](num_features=32)\n",
" (dropout): Layer[Dropout](p=0)\n",
" (0): LinearBlock(\n",
" (layer): Layer[Linear](in_features=10, out_features=32, bias=True)\n",
" )\n",
" (1): LayerActivationNormalizationDropout(\n",
" (layer): Layer[Linear](in_features=32, out_features=5)\n",
" (1): LinearBlock(\n",
" (layer): Layer[Linear](in_features=32, out_features=5, bias=True)\n",
" (activation): Layer[ReLU]()\n",
" (normalization): Layer[Identity](num_features=5)\n",
" (dropout): Layer[Identity]()\n",
" )\n",
" )\n",
")\n"
Expand All @@ -337,18 +359,31 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 12,
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "module 'deeplay.models' has no attribute 'SmallMLP'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[10], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m small_mlp \u001b[38;5;241m=\u001b[39m \u001b[43mdl\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmodels\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mSmallMLP\u001b[49m(in_features\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m10\u001b[39m, out_features\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m5\u001b[39m)\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28mprint\u001b[39m(small_mlp)\n",
"\u001b[0;31mAttributeError\u001b[0m: module 'deeplay.models' has no attribute 'SmallMLP'"
"name": "stdout",
"output_type": "stream",
"text": [
"SmallMLP(\n",
" (blocks): LayerList(\n",
" (0): LinearBlock(\n",
" (layer): Layer[Linear](in_features=10, out_features=32, bias=True)\n",
" (activation): Layer[LeakyReLU](negative_slope=0.05)\n",
" (normalization): Layer[BatchNorm1d](num_features=32)\n",
" )\n",
" (1): LinearBlock(\n",
" (layer): Layer[Linear](in_features=32, out_features=32, bias=True)\n",
" (activation): Layer[LeakyReLU](negative_slope=0.05)\n",
" (normalization): Layer[BatchNorm1d](num_features=32)\n",
" )\n",
" (2): LinearBlock(\n",
" (layer): Layer[Linear](in_features=32, out_features=5, bias=True)\n",
" (activation): Layer[Identity]()\n",
" )\n",
" )\n",
")\n"
]
}
],
Expand All @@ -369,21 +404,9 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 13,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'small_mlp' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[11], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m classifier \u001b[38;5;241m=\u001b[39m dl\u001b[38;5;241m.\u001b[39mClassifier(\u001b[43msmall_mlp\u001b[49m, optimizer\u001b[38;5;241m=\u001b[39mdl\u001b[38;5;241m.\u001b[39mAdam(lr\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m0.001\u001b[39m))\n",
"\u001b[0;31mNameError\u001b[0m: name 'small_mlp' is not defined"
]
}
],
"outputs": [],
"source": [
"classifier = dl.Classifier(small_mlp, optimizer=dl.Adam(lr=0.001))"
]
Expand Down Expand Up @@ -412,7 +435,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
"version": "3.12.2"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit a3cf12c

Please sign in to comment.