test tensors
This commit is contained in:
parent
2e2f0e1b17
commit
e8a08a8a93
1 changed files with 65 additions and 27 deletions
|
@ -42,7 +42,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 52,
|
"execution_count": 2,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"colab": {},
|
"colab": {},
|
||||||
"colab_type": "code",
|
"colab_type": "code",
|
||||||
|
@ -61,6 +61,8 @@
|
||||||
"from torch.utils.data import DataLoader\n",
|
"from torch.utils.data import DataLoader\n",
|
||||||
"import matplotlib.pyplot as plt\n",
|
"import matplotlib.pyplot as plt\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
"from collections import OrderedDict\n",
|
||||||
|
"\n",
|
||||||
"torch.manual_seed(0) # Set for testing purposes, please do not change!\n",
|
"torch.manual_seed(0) # Set for testing purposes, please do not change!\n",
|
||||||
"\n",
|
"\n",
|
||||||
"def show_tensor_images(image_tensor, num_images=25, size=(1, 28, 28)):\n",
|
"def show_tensor_images(image_tensor, num_images=25, size=(1, 28, 28)):\n",
|
||||||
|
@ -116,7 +118,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 23,
|
"execution_count": 3,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"colab": {},
|
"colab": {},
|
||||||
"colab_type": "code",
|
"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=<NativeBatchNormBackward0>)\n",
|
||||||
|
"tensor([[-1.0000, -1.0000],\n",
|
||||||
|
" [ 1.0000, 1.0000]], grad_fn=<NativeBatchNormBackward0>)\n",
|
||||||
|
"tensor([[-1.0000, -1.0000, -1.0000],\n",
|
||||||
|
" [ 1.0000, 1.0000, 1.0000]], grad_fn=<NativeBatchNormBackward0>)\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",
|
"cell_type": "code",
|
||||||
"execution_count": 4,
|
"execution_count": 4,
|
||||||
|
@ -224,34 +277,19 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 42,
|
"execution_count": 1,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"data": {
|
"ename": "NameError",
|
||||||
"text/plain": [
|
"evalue": "name 'nn' is not defined",
|
||||||
"Sequential(\n",
|
"output_type": "error",
|
||||||
" (0): Sequential(\n",
|
"traceback": [
|
||||||
" (0): Linear(in_features=10, out_features=128, bias=True)\n",
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||||
" (1): BatchNorm1d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
|
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
|
||||||
" (2): ReLU(inplace=True)\n",
|
"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",
|
||||||
" )\n",
|
"\u001b[0;31mNameError\u001b[0m: name 'nn' is not defined"
|
||||||
" (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"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
|
|
Loading…
Reference in a new issue