From e8a08a8a930ae78dd6663473b174d4cfc319c752 Mon Sep 17 00:00:00 2001 From: John Date: Tue, 13 Jun 2023 22:12:02 +0200 Subject: [PATCH] test tensors --- .../C1W1_Your_First_GAN.ipynb | 92 +++++++++++++------ 1 file changed, 65 insertions(+), 27 deletions(-) diff --git a/Courses/GANs_Specialization/1_Build_Basic_GANs/Week_1:Intro_to_GANs/C1W1_Your_First_GAN.ipynb b/Courses/GANs_Specialization/1_Build_Basic_GANs/Week_1:Intro_to_GANs/C1W1_Your_First_GAN.ipynb index 70f7a5d..11cdba7 100644 --- a/Courses/GANs_Specialization/1_Build_Basic_GANs/Week_1:Intro_to_GANs/C1W1_Your_First_GAN.ipynb +++ b/Courses/GANs_Specialization/1_Build_Basic_GANs/Week_1:Intro_to_GANs/C1W1_Your_First_GAN.ipynb @@ -42,7 +42,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 2, "metadata": { "colab": {}, "colab_type": "code", @@ -61,6 +61,8 @@ "from torch.utils.data import DataLoader\n", "import matplotlib.pyplot as plt\n", "\n", + "from collections import OrderedDict\n", + "\n", "torch.manual_seed(0) # Set for testing purposes, please do not change!\n", "\n", "def show_tensor_images(image_tensor, num_images=25, size=(1, 28, 28)):\n", @@ -116,7 +118,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 3, "metadata": { "colab": {}, "colab_type": "code", @@ -150,6 +152,57 @@ " )" ] }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "tensor([[-1.0690],\n", + " [-0.2673],\n", + " [ 1.3363]], grad_fn=)\n", + "tensor([[-1.0000, -1.0000],\n", + " [ 1.0000, 1.0000]], grad_fn=)\n", + "tensor([[-1.0000, -1.0000, -1.0000],\n", + " [ 1.0000, 1.0000, 1.0000]], grad_fn=)\n" + ] + } + ], + "source": [ + "x1 = nn.BatchNorm1d(1)\n", + "x2 = nn.BatchNorm1d(2)\n", + "x3 = nn.BatchNorm1d(3)\n", + "a1 = torch.tensor([[5.],[6.],[8.]]) # torch.Size([3, 1])\n", + "a2 = torch.tensor([[2.,3.],[5.,4.]]) # torch.Size([2, 2])\n", + "a3 = torch.tensor([[2.,3.,6.],[5.,4.,9.]]) # torch.Size([2, 3])\n", + "print(x1(a1))\n", + "print(x2(a2))\n", + "print(x3(a3))" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "torch.Size([3, 1])" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a1.size()" + ] + }, { "cell_type": "code", "execution_count": 4, @@ -224,34 +277,19 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 1, "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "Sequential(\n", - " (0): Sequential(\n", - " (0): Linear(in_features=10, out_features=128, bias=True)\n", - " (1): BatchNorm1d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n", - " (2): ReLU(inplace=True)\n", - " )\n", - " (1): Sequential(\n", - " (0): Linear(in_features=128, out_features=256, bias=True)\n", - " (1): BatchNorm1d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n", - " (2): ReLU(inplace=True)\n", - " )\n", - " (2): Sequential(\n", - " (0): Linear(in_features=256, out_features=512, bias=True)\n", - " (1): BatchNorm1d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n", - " (2): ReLU(inplace=True)\n", - " )\n", - ")" - ] - }, - "execution_count": 42, - "metadata": {}, - "output_type": "execute_result" + "ename": "NameError", + "evalue": "name 'nn' 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[1], line 4\u001b[0m\n\u001b[1;32m 2\u001b[0m im_dim \u001b[39m=\u001b[39m \u001b[39m784\u001b[39m\n\u001b[1;32m 3\u001b[0m hidden_dim \u001b[39m=\u001b[39m \u001b[39m128\u001b[39m\n\u001b[0;32m----> 4\u001b[0m nn\u001b[39m.\u001b[39mSequential(\n\u001b[1;32m 5\u001b[0m get_generator_block(z_dim, hidden_dim),\n\u001b[1;32m 6\u001b[0m get_generator_block(hidden_dim, hidden_dim \u001b[39m*\u001b[39m \u001b[39m2\u001b[39m),\n\u001b[1;32m 7\u001b[0m get_generator_block(hidden_dim \u001b[39m*\u001b[39m \u001b[39m2\u001b[39m, hidden_dim \u001b[39m*\u001b[39m \u001b[39m4\u001b[39m),\n\u001b[1;32m 8\u001b[0m )\n", + "\u001b[0;31mNameError\u001b[0m: name 'nn' is not defined" + ] } ], "source": [