From 55f44f72b667909e5d9e8ed0cd94d05c96a6eb62 Mon Sep 17 00:00:00 2001 From: lawrence <245315189+lkliu7@users.noreply.github.com> Date: Sat, 4 Apr 2026 17:38:51 -0700 Subject: [PATCH] Use list comprehension to create distinct ResBlock instances n_blocks * [ResBlock(...)] creates shared reference to single object; used comprehension to create blocks with independent params. --- p1ch8/1_convolution.ipynb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/p1ch8/1_convolution.ipynb b/p1ch8/1_convolution.ipynb index ff443a9..2225ec5 100644 --- a/p1ch8/1_convolution.ipynb +++ b/p1ch8/1_convolution.ipynb @@ -1499,7 +1499,7 @@ " self.n_chans1 = n_chans1\n", " self.conv1 = nn.Conv2d(3, n_chans1, kernel_size=3, padding=1)\n", " self.resblocks = nn.Sequential(\n", - " *(n_blocks * [ResBlock(n_chans=n_chans1)]))\n", + " *[ResBlock(n_chans=n_chans1) for _ in range(n_blocks)])\n", " self.fc1 = nn.Linear(8 * 8 * n_chans1, 32)\n", " self.fc2 = nn.Linear(32, 2)\n", " \n", @@ -1590,7 +1590,7 @@ "metadata": { "celltoolbar": "Tags", "kernelspec": { - "display_name": ".venv", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -1604,9 +1604,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.9" + "version": "3.13.3" } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 }