diff --git a/README.ipynb b/README.ipynb index cc63344824ee816c9a56311051d13e68e0fdf43c..4ca6affcd6b1cea0c8f5c5d18811aa104a3ffb88 100644 --- a/README.ipynb +++ b/README.ipynb @@ -3,13 +3,13 @@ { "cell_type": "code", "execution_count": 1, - "id": "1d05699b", + "id": "26e42746", "metadata": { "execution": { - "iopub.execute_input": "2022-10-12T13:31:47.500867Z", - "iopub.status.busy": "2022-10-12T13:31:47.500064Z", - "iopub.status.idle": "2022-10-12T13:31:47.512502Z", - "shell.execute_reply": "2022-10-12T13:31:47.511595Z" + "iopub.execute_input": "2022-10-12T14:41:38.853343Z", + "iopub.status.busy": "2022-10-12T14:41:38.852566Z", + "iopub.status.idle": "2022-10-12T14:41:38.864329Z", + "shell.execute_reply": "2022-10-12T14:41:38.863589Z" }, "jupyter": { "source_hidden": true @@ -52,7 +52,7 @@ "For more information, you can contact us at : \n", "[<img width=\"200px\" style=\"vertical-align:middle\" src=\"fidle/img/00-Mail_contact.svg\"></img>](#top)\n", "\n", - "Current Version : <!-- VERSION_BEGIN -->2.1b3<!-- VERSION_END -->\n", + "Current Version : <!-- VERSION_BEGIN -->2.1b4<!-- VERSION_END -->\n", "\n", "\n", "## Course materials\n", @@ -67,7 +67,7 @@ "## Jupyter notebooks\n", "\n", "<!-- TOC_BEGIN -->\n", - "<!-- Automatically generated on : 12/10/22 15:31:46 -->\n", + "<!-- Automatically generated on : 12/10/22 16:41:37 -->\n", "\n", "### Linear and logistic regression\n", "- **[LINR1](LinearReg/01-Linear-Regression.ipynb)** - [Linear regression with direct resolution](LinearReg/01-Linear-Regression.ipynb) \n", @@ -229,7 +229,7 @@ "from IPython.display import display,Markdown\n", "display(Markdown(open('README.md', 'r').read()))\n", "#\n", - "# This README is visible under Jupiter Lab ;-)# Automatically generated on : 12/10/22 15:31:46" + "# This README is visible under Jupiter Lab ;-)# Automatically generated on : 12/10/22 16:41:37" ] } ], diff --git a/README.md b/README.md index 2bbd6913cdcf9208ca442f67bdc94fc5f14751f9..bb5a0c2f2e5223f23566bbac307a9c446aab3b6f 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ For more information, see **https://fidle.cnrs.fr** : For more information, you can contact us at : [<img width="200px" style="vertical-align:middle" src="fidle/img/00-Mail_contact.svg"></img>](#top) -Current Version : <!-- VERSION_BEGIN -->2.1b3<!-- VERSION_END --> +Current Version : <!-- VERSION_BEGIN -->2.1b4<!-- VERSION_END --> ## Course materials @@ -46,7 +46,7 @@ Have a look about **[How to get and install](https://fidle.cnrs.fr/installation) ## Jupyter notebooks <!-- TOC_BEGIN --> -<!-- Automatically generated on : 12/10/22 15:31:46 --> +<!-- Automatically generated on : 12/10/22 16:41:37 --> ### Linear and logistic regression - **[LINR1](LinearReg/01-Linear-Regression.ipynb)** - [Linear regression with direct resolution](LinearReg/01-Linear-Regression.ipynb) diff --git a/VAE/02-VAE-with-MNIST.ipynb b/VAE/02-VAE-with-MNIST.ipynb index 9242044b2e5ee5b792d4fa604a60c0aaf938a877..813d4082c76093e036efc2032389134ce9d5a257 100644 --- a/VAE/02-VAE-with-MNIST.ipynb +++ b/VAE/02-VAE-with-MNIST.ipynb @@ -89,7 +89,7 @@ "metadata": {}, "outputs": [], "source": [ - "latent_dim = 2\n", + "latent_dim = 6\n", "loss_weights = [1,.001] # [1, .001] give good results\n", "\n", "scale = .2\n", diff --git a/VAE/03-VAE-with-MNIST-post.ipynb b/VAE/03-VAE-with-MNIST-post.ipynb index 621ce30f33c58f0eb06bfe5bec658cdd47c5704d..cca90efe40889c04ae0bc67ee939d84f54109c24 100644 --- a/VAE/03-VAE-with-MNIST-post.ipynb +++ b/VAE/03-VAE-with-MNIST-post.ipynb @@ -55,6 +55,8 @@ "import scipy.stats\n", "import matplotlib\n", "import matplotlib.pyplot as plt\n", + "from barviz import Simplex\n", + "from barviz import Collection\n", "\n", "import sys\n", "import fidle\n", @@ -149,14 +151,18 @@ "\n", "# ---- Get latent points and reconstructed images\n", "\n", - "z_mean, z_var, z = vae.encoder.predict(x_show)\n", - "x_reconst = vae.decoder.predict(z)\n", + "z_mean, z_var, z = vae.encoder.predict(x_show, verbose=0)\n", + "x_reconst = vae.decoder.predict(z, verbose=0)\n", + "\n", + "latent_dim = z.shape[1]\n", "\n", "# ---- Show it\n", "\n", "labels=[ str(np.round(z[i],1)) for i in range(10) ]\n", - "fidle.scrawler.images(x_show, labels, indices='all', columns=10, x_size=2,y_size=2, save_as='01-original')\n", - "fidle.scrawler.images(x_reconst, None , indices='all', columns=10, x_size=2,y_size=2, save_as='02-reconstruct')\n" + "fidle.utils.subtitle('Originals :')\n", + "fidle.scrawler.images(x_show, None, indices='all', columns=10, x_size=2,y_size=2, save_as='01-original')\n", + "fidle.utils.subtitle('Reconstructed :')\n", + "fidle.scrawler.images(x_reconst, None, indices='all', columns=10, x_size=2,y_size=2, save_as='02-reconstruct')\n" ] }, { @@ -180,10 +186,22 @@ "\n", "# ---- Get latent points\n", "\n", - "z_mean, z_var, z = vae.encoder.predict(x_show)\n", - "\n", - "# ---- Show them\n", - "\n", + "z_mean, z_var, z = vae.encoder.predict(x_show, verbose=0)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 5.1 - Classic 2d visualisaton" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ "fig = plt.figure(figsize=(14, 10))\n", "plt.scatter(z[:, 0] , z[:, 1], c=y_show, cmap= 'tab10', alpha=0.5, s=30)\n", "plt.colorbar()\n", @@ -195,7 +213,39 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Step 6 - Generate from latent space" + "### 5.2 - Simplex visualisaton" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# ---- Softmax rescale\n", + "#\n", + "zs = np.exp(z)/np.sum(np.exp(z),axis=1,keepdims=True)\n", + "# zc = zs * 1/np.max(zs)\n", + "\n", + "# ---- Create collection\n", + "#\n", + "c = Collection(zs, colors=y_show, labels=y_show)\n", + "c.attrs.markers_colormap = {'colorscale':'Rainbow','cmin':0,'cmax':latent_dim}\n", + "c.attrs.markers_size = 4\n", + "c.attrs.markers_border_width = 0\n", + "c.attrs.markers_opacity = 0.7\n", + "\n", + "s = Simplex.build(latent_dim)\n", + "s.attrs.width = 1000\n", + "s.attrs.height = 1000\n", + "s.plot(c)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Step 6 - Generate from latent space (latent_dim==2)" ] }, { @@ -204,29 +254,35 @@ "metadata": {}, "outputs": [], "source": [ - "grid_size = 14\n", - "grid_scale = 1.\n", + "if latent_dim>2:\n", + "\n", + " print('Sorry, This part can only work if the latent space is of dimension 2')\n", + "\n", + "else:\n", + "\n", + " grid_size = 14\n", + " grid_scale = 1.\n", "\n", - "# ---- Draw a ppf grid\n", + " # ---- Draw a ppf grid\n", "\n", - "grid=[]\n", - "for y in scipy.stats.norm.ppf(np.linspace(0.99, 0.01, grid_size),scale=grid_scale):\n", - " for x in scipy.stats.norm.ppf(np.linspace(0.01, 0.99, grid_size),scale=grid_scale):\n", - " grid.append( (x,y) )\n", - "grid=np.array(grid)\n", + " grid=[]\n", + " for y in scipy.stats.norm.ppf(np.linspace(0.99, 0.01, grid_size),scale=grid_scale):\n", + " for x in scipy.stats.norm.ppf(np.linspace(0.01, 0.99, grid_size),scale=grid_scale):\n", + " grid.append( (x,y) )\n", + " grid=np.array(grid)\n", "\n", - "# ---- Draw latentspoints and grid\n", + " # ---- Draw latentspoints and grid\n", "\n", - "fig = plt.figure(figsize=(12, 10))\n", - "plt.scatter(z[:, 0] , z[:, 1], c=y_show, cmap= 'tab10', alpha=0.5, s=20)\n", - "plt.scatter(grid[:, 0] , grid[:, 1], c = 'black', s=60, linewidth=2, marker='+', alpha=1)\n", - "fidle.scrawler.save_fig('04-Latent-grid')\n", - "plt.show()\n", + " fig = plt.figure(figsize=(12, 10))\n", + " plt.scatter(z[:, 0] , z[:, 1], c=y_show, cmap= 'tab10', alpha=0.5, s=20)\n", + " plt.scatter(grid[:, 0] , grid[:, 1], c = 'black', s=60, linewidth=2, marker='+', alpha=1)\n", + " fidle.scrawler.save_fig('04-Latent-grid')\n", + " plt.show()\n", "\n", - "# ---- Plot grid corresponding images\n", + " # ---- Plot grid corresponding images\n", "\n", - "x_reconst = vae.decoder.predict([grid])\n", - "fidle.scrawler.images(x_reconst, indices='all', columns=grid_size, x_size=0.5,y_size=0.5, y_padding=0,spines_alpha=0.1, save_as='05-Latent-morphing')\n", + " x_reconst = vae.decoder.predict([grid])\n", + " fidle.scrawler.images(x_reconst, indices='all', columns=grid_size, x_size=0.5,y_size=0.5, y_padding=0,spines_alpha=0.1, save_as='05-Latent-morphing')\n", "\n" ] }, diff --git a/fidle/about.yml b/fidle/about.yml index b2e247278985823f0931162a492d6e044448d325..00946f5929ce8cec053c50578474884ae239859c 100644 --- a/fidle/about.yml +++ b/fidle/about.yml @@ -13,7 +13,7 @@ # # This file describes the notebooks used by the Fidle training. -version: 2.1b3 +version: 2.1b4 content: notebooks name: Notebooks Fidle description: All notebooks used by the Fidle training diff --git a/fidle/ci/default.yml b/fidle/ci/default.yml index e005b6bb1e96219f45c5028d2e7c1c606a7b9736..2f23ed0d8311f8fab43be46f42806a18e577853f 100644 --- a/fidle/ci/default.yml +++ b/fidle/ci/default.yml @@ -1,6 +1,6 @@ campain: version: '1.0' - description: Automatically generated ci profile (12/10/22 15:31:46) + description: Automatically generated ci profile (12/10/22 16:41:37) directory: ./campains/default existing_notebook: 'remove # remove|skip' report_template: 'fidle # fidle|default'