From 5f92f14ee628a9231ad4070d98a429ecf12ea6df Mon Sep 17 00:00:00 2001 From: Jean-Luc Parouty <Jean-Luc.Parouty@simap.grenoble-inp.fr> Date: Wed, 2 Feb 2022 17:50:04 +0100 Subject: [PATCH] Update scratchbook with upsampling example --- Misc/Scratchbook.ipynb | 63 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/Misc/Scratchbook.ipynb b/Misc/Scratchbook.ipynb index f39fc5b..765b64e 100644 --- a/Misc/Scratchbook.ipynb +++ b/Misc/Scratchbook.ipynb @@ -233,10 +233,71 @@ " print(f'#{i} : {x} => {y}')" ] }, + { + "cell_type": "markdown", + "id": "67e3c888-aaa4-4166-90a1-cdb63920fd7d", + "metadata": {}, + "source": [ + "## 3 - Upsampling" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "id": "20f12cf0-1fdb-4b53-92c6-d03b140e42d1", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Initial : (2, 2)\n", + "[[1 2]\n", + " [3 4]]\n", + "\n", + "Reshape as a batch of (2,2) vectors : (1, 2, 2, 1)\n", + "[[[[1]\n", + " [2]]\n", + "\n", + " [[3]\n", + " [4]]]]\n", + "\n", + "y shape : (1, 4, 4, 1)\n", + "\n", + " After a (4,4) reshape :\n", + "[[1 1 2 2]\n", + " [1 1 2 2]\n", + " [3 3 4 4]\n", + " [3 3 4 4]]\n" + ] + } + ], + "source": [ + "x = np.array([1,2,3,4])\n", + "x = x.reshape(2,2)\n", + "print('\\nInitial : ', x.shape)\n", + "print(x)\n", + "\n", + "x = x.reshape((1,2,2,1))\n", + "print('\\nReshape as a batch of (2,2) vectors : ', x.shape)\n", + "print(x)\n", + "\n", + "y = tf.keras.layers.UpSampling2D( size=(2, 2), interpolation=\"nearest\" )(x)\n", + "\n", + "y = np.array(y)\n", + "print('\\ny shape : ',y.shape)\n", + "\n", + "y = y.reshape(4,4)\n", + "print('\\n After a (4,4) reshape :')\n", + "print(y)\n", + "\n" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "4d94892b-d3a5-448d-aa2b-28c3a01a4b72", + "id": "09ac4e52-8953-41d9-b712-e6a83a9ae860", "metadata": {}, "outputs": [], "source": [] -- GitLab