Tensor update

This commit is contained in:
John 2023-06-13 22:19:21 +02:00
parent e8a08a8a93
commit 94c60dedc5
1 changed files with 39 additions and 31 deletions

View File

@ -152,6 +152,44 @@
" )"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"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])"
]
},
{
"cell_type": "code",
"execution_count": 57,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"tensor([[ 1.5961e-05, -8.4611e-07],\n",
" [ 1.5961e-05, -8.4611e-07],\n",
" [ 1.5961e-05, -8.4611e-07]], grad_fn=<NativeBatchNormBackward0>)"
]
},
"execution_count": 57,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"b1 = torch.tensor([[5.,6.,8.],[5.,6.,8.],[5.,6.,8.]]) \n",
"l1 = nn.Linear(3,2)\n",
"p = l1(b1)\n",
"p\n",
"bn = nn.BatchNorm1d(2)\n",
"bn(p)"
]
},
{
"cell_type": "code",
"execution_count": 37,
@ -175,9 +213,7 @@
"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",
"\n",
"print(x1(a1))\n",
"print(x2(a2))\n",
"print(x3(a3))"
@ -275,34 +311,6 @@
"</details>\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"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": [
"z_dim = 10\n",
"im_dim = 784\n",
"hidden_dim = 128\n",
"nn.Sequential(\n",
" get_generator_block(z_dim, hidden_dim),\n",
" get_generator_block(hidden_dim, hidden_dim * 2),\n",
" get_generator_block(hidden_dim * 2, hidden_dim * 4),\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 49,