{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"Deep Learning con Keras - Lezione 1","provenance":[],"collapsed_sections":["PaTwzBNg_ehy","Mt8hlgCKAlQP","yUMIUEOq_Odr","wPbNvmAZGHj_","DCcTH7De7Dva"],"toc_visible":true,"authorship_tag":"ABX9TyOfG25I+OULfk/YAbuaXc8C"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["# Introduzione\n","\n","**Deep Learning con Keras** è un breve ciclo di lezioni sull'utilizzo della libreria Keras per il deep learning.\n","\n","Le lezioni sono basate sul libro\n","\n","> FRANÇOIS CHOLLET \n","> Deep Learning with Python \n","> Manning\n","\n","e saranno tenute da\n","\n","> prof. [Gianluca Amato](https://www.sci.unich.it/~amato) \n","> Dipartimento di Economia \n","> Università \"G. d'Annunzio\" di Chieti-Pescara\n"],"metadata":{"id":"PaTwzBNg_ehy"}},{"cell_type":"markdown","source":["## Cosa è il deep learning ?\n","\n","Il deep learning (apprendimento profondo) è un settore del machine learning (apprendimento automatica), che è a sua volta una branca dell'intelligenza artificiale.\n","\n"," \n","\n","Le reti neurali artificiali (artificial neural networks) sono una tecnica di machine learning ispirata dal funzionamento del cervello umano."],"metadata":{"id":"Mt8hlgCKAlQP"}},{"cell_type":"markdown","source":["## Caso di studio: riconoscimento del contenuto di una immagine\n","\n","Riconoscimento di cifre (da 0 a 9) scritte a mano. Abbiamo a disposizione 70.000 immagini prese dal database MNIST (Modified National Institute of Standards and Technology) , e vogliamo un programma che, presa una immagine, ci restituisca un intero tra 0 e 9 che è la cifra rappresentata in essa. \n","\n","Questo è un campione delle immagini che abbiamo a disposizione:\n","\n"," \n","\n","È un compito banale per gli esseri umani, ma se provassimo a scrivere noi stessi un algoritmo per il riconoscimento di queste immagini, ci accorgeremmo subito che non è per niente banale. La semplice intuizione di come riconoscere le varie forme (come \"un 9 ha un cappio in cima e un tratto verticale in basso a destra\") non è facile da esprimere algoritmicamente. Se si prova a rendere questa regole intuitive più precise, ci si ritrova persi in una miriade di eccezioni e casi particolari."],"metadata":{"id":"yUMIUEOq_Odr"}},{"cell_type":"markdown","source":["## Come ci aiuta il machine learning\n","\n","Con il machine learning noi non scriviamo un algoritmo specifico di riconoscimento delle immagini, ma utilizziamo degli algoritmi generici che \"imparano\" dai dati.\n","\n"," \n","\n","Un algoritmo di *apprendimento* prende in input le immagini dell'insieme di addestramento, ognuna accompagnata dalla etichetta che indica di quale cifra si tratta, e genera un modello di classificazione (nel nostro caso una rete neurale, ma esistono altre possibilità).\n","\n","Un algoritmo di *inferenza* prende in input la rete neurale generale dalla fase di apprendimento e nuove immagini, assegnando ad ognuna di queste una etichetta da a 0 a 9. Ovviamente, a seconda di quanto è buono il modello ottenuto durante l'addestramento, i risultati dell'infernza possono essere più o meno corretti."],"metadata":{"id":"wPbNvmAZGHj_"}},{"cell_type":"markdown","source":["# Ambiente di lavoro\n","\n","**Python**: è il linguaggio per eccellenza nelle applicazioni di machine learning. Sebbene concettualmente sia un linguaggio imperativo ad oggetti come Java, la sintassi è abbastanza diversa. \n","\n","**Notebook**: molto spesso nell'ambito di deep learning non si scrivono programmi completi ma degli spezzoni di codice che vengono eseguiti in maniera interattiva. Il notebook è uno degli ambienti più comodi per l'uso interattivo.\n","\n","Un notebook è costituito da un insieme di celle. Le celle di testo, come questa che state leggendo, contiene del testo qualunque destinato ad esseree letto da un essere umano. Le celle di codice contengono invece del codice Python da eseguire.\n","\n","Ad esempio, in una cella di codice posso scrivere una espressione arimetica. Il risultato viene visualizzato immediatamente sotto."],"metadata":{"id":"MwyQ2M6_OCm5"}},{"cell_type":"code","source":["4+5*9"],"metadata":{"id":"UlNvxD-o_DAP","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1647947728610,"user_tz":-60,"elapsed":6,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"548fb813-a79a-4f58-f097-3052963bdd9d"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["49"]},"metadata":{},"execution_count":1}]},{"cell_type":"markdown","source":["Se voglio usare delle funzioni predefinite di Python, può essere necessario importarle. Ad esempio, la funzione radice quadrata (`sqrt`) sta nel modulo `math`, ma non si può usare immediatamente."],"metadata":{"id":"DIGfrDpl_UmI"}},{"cell_type":"code","source":["math.sqrt(2)"],"metadata":{"id":"h5zR7c0_AUCB","colab":{"base_uri":"https://localhost:8080/","height":167},"executionInfo":{"status":"error","timestamp":1647947730586,"user_tz":-60,"elapsed":7,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"59f33c5f-709f-4051-f4e4-ba43ad7c3123"},"execution_count":null,"outputs":[{"output_type":"error","ename":"NameError","evalue":"ignored","traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)","\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mmath\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msqrt\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m","\u001b[0;31mNameError\u001b[0m: name 'math' is not defined"]}]},{"cell_type":"markdown","source":["Prima bisogna importare il modulo `math` con il comando `import`.\n","\n"],"metadata":{"id":"Is8VONT3Alkb"}},{"cell_type":"code","source":["import math\n","\n","math.sqrt(2)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"ZQw3ilpD_dfp","executionInfo":{"status":"ok","timestamp":1647947733432,"user_tz":-60,"elapsed":5,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"c83966eb-6d9b-41f4-fb79-831c6724d80b"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["1.4142135623730951"]},"metadata":{},"execution_count":3}]},{"cell_type":"markdown","source":["E a quel punto lo si può usare in tutte le celle, sia se vengono prima sia se vengono dopo il punto di importazione."],"metadata":{"id":"OghypmvRDpZR"}},{"cell_type":"code","source":["math.sqrt(2)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"QQeDwuiID3kZ","executionInfo":{"status":"ok","timestamp":1647947736891,"user_tz":-60,"elapsed":333,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"4d92705f-ad48-4d56-df40-37c3c9d2d51c"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["1.4142135623730951"]},"metadata":{},"execution_count":4}]},{"cell_type":"markdown","source":["In una cella è possibile inserire un codice Python più lungo."],"metadata":{"id":"RO4Zqbk_D7L3"}},{"cell_type":"code","source":["# Esempio di codice Python che esegue la somma dei numeri da 0 fino ad n.\n","n = 10\n","sum = 0\n","for y in range(n+1):\n"," sum = sum + y\n"," print(y)\n","print(f\"La somma dei primi {n} numeri è {sum}\")"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"P19xEiOzVb4R","executionInfo":{"status":"ok","timestamp":1647947738768,"user_tz":-60,"elapsed":3,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"f2adcf98-d6f0-40c6-d755-d84abddce19f"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["0\n","1\n","2\n","3\n","4\n","5\n","6\n","7\n","8\n","9\n","10\n","La somma dei primi 10 numeri è 55\n"]}]},{"cell_type":"markdown","source":["La cella del notebook qui sopra **due delle caratteristiche di Python** che lo distinguono in maniera più evidente da Java:\n","\n","* le variabili non devono essere dichiarate prima di essere utilizzate\n","* l'indentazione sostituisce le parentesi graffe nello specificare blocchi di codice\n","\n","Una volta che un cella di codice è stata eseguita, le variabili create sono accessibili anche dalle altre celle\n"],"metadata":{"id":"wokRRYRlWPeB"}},{"cell_type":"code","source":["sum"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"d5ljnXbYXHbb","executionInfo":{"status":"ok","timestamp":1647947741867,"user_tz":-60,"elapsed":264,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"246173be-7055-443b-be03-837b2823375b"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["55"]},"metadata":{},"execution_count":6}]},{"cell_type":"markdown","source":["Il notebook può anche contenere output di tipo grafico"],"metadata":{"id":"Hrs2Bc-CXkMQ"}},{"cell_type":"code","source":["import matplotlib.pyplot as plt\n","\n","plt.plot([1, 2, 3, 4], [1, 4, 9, 16], 'ro')\n","plt.axis([0, 6, 0, 20])\n","plt.show()"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":269},"id":"Vpio5R_RVem7","executionInfo":{"status":"ok","timestamp":1647947744182,"user_tz":-60,"elapsed":882,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"bb0dcfe7-c018-4059-fd1c-a6674ea86206"},"execution_count":null,"outputs":[{"output_type":"display_data","data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dGfqS1BBDX5IaYuhLUkMMfUlqiKEvSQ0x9CWpIf8PIZset+X/pHkAAAAASUVORK5CYII=\n"},"metadata":{"needs_background":"light"}}]},{"cell_type":"markdown","source":["È possibile ovviamente lavorare interamente nel proprio computer installando Python e Jupyter Notebook, ma per queste lezioni ho preferito utilizzare Google Colab."],"metadata":{"id":"b1oczSVRYFI4"}},{"cell_type":"markdown","source":["# Primi passi"],"metadata":{"id":"ndHn_zYHUrYW"}},{"cell_type":"code","source":["# Importiamo le librerie Numpy, TensorFlow e Matplotlib (quest'ultima per la visualizzazione grafica)\n","# Notare l'uso della clausola \"as\" per poter usare quel modulo con un nome più corto.\n","# Le abbreviazioni np, tf e plt sono una specie di standard.\n","\n","import numpy as np\n","import tensorflow as tf\n","import matplotlib.pyplot as plt"],"metadata":{"id":"0pMc7ij4Y4q4"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## Caricamento dei dati di addestramento"],"metadata":{"id":"Y1ZZvgWsmCvh"}},{"cell_type":"code","source":["# Carichiamo il dataset MNIST\n","# - train_images sono le immagini per la fase di addestramento\n","# - train_labels sono le etichette associate a queste immagini (numeri da 0 a 9) \n","\n","# test_images e test_labels sono simili a train_images e train_labels ma costituiscono \n","# i dati per la fase di test (ne parleremo dopo)\n","\n","(train_images, train_labels), (test_images, test_labels) = tf.keras.datasets.mnist.load_data()"],"metadata":{"id":"R_8lwtovTtrE","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1647947775151,"user_tz":-60,"elapsed":625,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"fc742598-d45c-4e4c-dd6f-b95cfb867b14"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz\n","11493376/11490434 [==============================] - 0s 0us/step\n","11501568/11490434 [==============================] - 0s 0us/step\n"]}]},{"cell_type":"code","source":["# Proviamo a vedere il contenuto di train_images... non si capisce molto.\n","# Quello che si capisce è che si tratta di un array contenente numeri interi a \n","# 8 bit senza segno (vedi dtype=uint8 alla fine dell'output)\n","\n","train_images"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"u05hqo8wojAe","executionInfo":{"status":"ok","timestamp":1647947777581,"user_tz":-60,"elapsed":6,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"27bbe951-fb34-4217-e801-581694e4505a"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["array([[[0, 0, 0, ..., 0, 0, 0],\n"," [0, 0, 0, ..., 0, 0, 0],\n"," [0, 0, 0, ..., 0, 0, 0],\n"," ...,\n"," [0, 0, 0, ..., 0, 0, 0],\n"," [0, 0, 0, ..., 0, 0, 0],\n"," [0, 0, 0, ..., 0, 0, 0]],\n","\n"," [[0, 0, 0, ..., 0, 0, 0],\n"," [0, 0, 0, ..., 0, 0, 0],\n"," [0, 0, 0, ..., 0, 0, 0],\n"," ...,\n"," [0, 0, 0, ..., 0, 0, 0],\n"," [0, 0, 0, ..., 0, 0, 0],\n"," [0, 0, 0, ..., 0, 0, 0]],\n","\n"," [[0, 0, 0, ..., 0, 0, 0],\n"," [0, 0, 0, ..., 0, 0, 0],\n"," [0, 0, 0, ..., 0, 0, 0],\n"," ...,\n"," [0, 0, 0, ..., 0, 0, 0],\n"," [0, 0, 0, ..., 0, 0, 0],\n"," [0, 0, 0, ..., 0, 0, 0]],\n","\n"," ...,\n","\n"," [[0, 0, 0, ..., 0, 0, 0],\n"," [0, 0, 0, ..., 0, 0, 0],\n"," [0, 0, 0, ..., 0, 0, 0],\n"," ...,\n"," [0, 0, 0, ..., 0, 0, 0],\n"," [0, 0, 0, ..., 0, 0, 0],\n"," [0, 0, 0, ..., 0, 0, 0]],\n","\n"," [[0, 0, 0, ..., 0, 0, 0],\n"," [0, 0, 0, ..., 0, 0, 0],\n"," [0, 0, 0, ..., 0, 0, 0],\n"," ...,\n"," [0, 0, 0, ..., 0, 0, 0],\n"," [0, 0, 0, ..., 0, 0, 0],\n"," [0, 0, 0, ..., 0, 0, 0]],\n","\n"," [[0, 0, 0, ..., 0, 0, 0],\n"," [0, 0, 0, ..., 0, 0, 0],\n"," [0, 0, 0, ..., 0, 0, 0],\n"," ...,\n"," [0, 0, 0, ..., 0, 0, 0],\n"," [0, 0, 0, ..., 0, 0, 0],\n"," [0, 0, 0, ..., 0, 0, 0]]], dtype=uint8)"]},"metadata":{},"execution_count":10}]},{"cell_type":"code","source":["# La funzione len ci restituisce il numero di elementi di un vettore.\n","# Nel nostro caso è 60.000 (il numero di immagini di addestramento).\n","\n","len(train_images)"],"metadata":{"id":"F-z30WfeUFch","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1647947792030,"user_tz":-60,"elapsed":424,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"b7507fb1-3e77-4a8a-ab84-7a7e3ea98fe7"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["60000"]},"metadata":{},"execution_count":11}]},{"cell_type":"code","source":["# Ogni immagine è una matrice di 28 x 28 elementi. Ogni elemento corrisponde ad un pixel dell'immagine.\n","# Il valore numerico è la gradazione di grigio di quel punto da 0 (bianco) a 255 (nero)\n","\n","train_images[2]"],"metadata":{"id":"7v4ROJ9FUHoe","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1647947869905,"user_tz":-60,"elapsed":240,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"1e0bb593-3b3c-47c4-f2b3-e4776bd04636"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["array([[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0],\n"," [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0],\n"," [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0],\n"," [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0],\n"," [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0],\n"," [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0, 0, 0, 0, 0, 0, 67, 232, 39, 0, 0, 0,\n"," 0, 0],\n"," [ 0, 0, 0, 0, 62, 81, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0, 0, 0, 0, 0, 0, 120, 180, 39, 0, 0, 0,\n"," 0, 0],\n"," [ 0, 0, 0, 0, 126, 163, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0, 0, 0, 0, 0, 2, 153, 210, 40, 0, 0, 0,\n"," 0, 0],\n"," [ 0, 0, 0, 0, 220, 163, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0, 0, 0, 0, 0, 27, 254, 162, 0, 0, 0, 0,\n"," 0, 0],\n"," [ 0, 0, 0, 0, 222, 163, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0, 0, 0, 0, 0, 183, 254, 125, 0, 0, 0, 0,\n"," 0, 0],\n"," [ 0, 0, 0, 46, 245, 163, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0, 0, 0, 0, 0, 198, 254, 56, 0, 0, 0, 0,\n"," 0, 0],\n"," [ 0, 0, 0, 120, 254, 163, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0, 0, 0, 0, 23, 231, 254, 29, 0, 0, 0, 0,\n"," 0, 0],\n"," [ 0, 0, 0, 159, 254, 120, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0, 0, 0, 0, 163, 254, 216, 16, 0, 0, 0, 0,\n"," 0, 0],\n"," [ 0, 0, 0, 159, 254, 67, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0, 14, 86, 178, 248, 254, 91, 0, 0, 0, 0, 0,\n"," 0, 0],\n"," [ 0, 0, 0, 159, 254, 85, 0, 0, 0, 47, 49, 116, 144,\n"," 150, 241, 243, 234, 179, 241, 252, 40, 0, 0, 0, 0, 0,\n"," 0, 0],\n"," [ 0, 0, 0, 150, 253, 237, 207, 207, 207, 253, 254, 250, 240,\n"," 198, 143, 91, 28, 5, 233, 250, 0, 0, 0, 0, 0, 0,\n"," 0, 0],\n"," [ 0, 0, 0, 0, 119, 177, 177, 177, 177, 177, 98, 56, 0,\n"," 0, 0, 0, 0, 102, 254, 220, 0, 0, 0, 0, 0, 0,\n"," 0, 0],\n"," [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0, 0, 0, 169, 254, 137, 0, 0, 0, 0, 0, 0,\n"," 0, 0],\n"," [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0, 0, 0, 169, 254, 57, 0, 0, 0, 0, 0, 0,\n"," 0, 0],\n"," [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0, 0, 0, 169, 254, 57, 0, 0, 0, 0, 0, 0,\n"," 0, 0],\n"," [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0, 0, 0, 169, 255, 94, 0, 0, 0, 0, 0, 0,\n"," 0, 0],\n"," [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0, 0, 0, 169, 254, 96, 0, 0, 0, 0, 0, 0,\n"," 0, 0],\n"," [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0, 0, 0, 169, 254, 153, 0, 0, 0, 0, 0, 0,\n"," 0, 0],\n"," [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0, 0, 0, 169, 255, 153, 0, 0, 0, 0, 0, 0,\n"," 0, 0],\n"," [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0, 0, 0, 96, 254, 153, 0, 0, 0, 0, 0, 0,\n"," 0, 0],\n"," [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0],\n"," [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0],\n"," [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n"," 0, 0]], dtype=uint8)"]},"metadata":{},"execution_count":12}]},{"cell_type":"code","source":["# complessivamente siamo di fronte ad un array di 60.000 x 28 x 28 interi.\n","# Le dimensioni complessive dell'array si possono esaminare con la proprietà\n","# shape. Questi vettori a 3-dimensioni (o anch più) si chiamano tensori\n","# nella terminologia di TensorFlow.\n","\n","train_images.shape"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"SwbCJCKBoEO0","executionInfo":{"status":"ok","timestamp":1647947873300,"user_tz":-60,"elapsed":261,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"fd5ed4e5-b5ee-4744-ab0d-80fe624ce766"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["(60000, 28, 28)"]},"metadata":{},"execution_count":13}]},{"cell_type":"code","source":["# Ovviamente, se chiedo lo shape di una singola immagine, quella sarà\n","# solo 28 x 28.\n","\n","train_images[2].shape"],"metadata":{"id":"ufpetO-xIqKQ","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1647947915743,"user_tz":-60,"elapsed":240,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"7945334d-49bf-4533-9a7d-355bed135fa4"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["(28, 28)"]},"metadata":{},"execution_count":15}]},{"cell_type":"code","source":["# Possiamo vedere il contenuto di una immagine in forma grafica col il comando plt.imshow\n","\n","plt.imshow(train_images[2], cmap = plt.cm.binary)"],"metadata":{"id":"C30mjMwWXy0w","colab":{"base_uri":"https://localhost:8080/","height":282},"executionInfo":{"status":"ok","timestamp":1647947918110,"user_tz":-60,"elapsed":241,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"0d01a4ea-f006-4eb4-be42-3663b4ab86c1"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":[""]},"metadata":{},"execution_count":16},{"output_type":"display_data","data":{"text/plain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UCIiKPF/aSkZzV4U1EfPzODbnE/WXM/fzNI03jPNs24BuDY1Tn9eR1h3y9ppe1v2v6apB9K2l1DH19h+5LiwolsXyLpBxq8qah3S9paPN4q6bkae/mSQZnGu9U046r52NU+/XlE9P0m6VZNX5H/P0n/UkcPLfq6UtLrxe3NunuT9IymX9Z9pulrG/dI+oakUUmHJf2PpMsGqLf/lPSGpIOaDtaSmnq7SdMv0Q9KOlDcbq372JX01ZfjxsdlgSS4QAckQdiBJAg7kARhB5Ig7EAShB1IgrADSfw/VdkAV4stm1cAAAAASUVORK5CYII=\n"},"metadata":{"needs_background":"light"}}]},{"cell_type":"code","source":["# train_labels è un elenco di 60.000 valori da 0 a 9. Ogni valore è la cifra\n","# rappresentata nella corrispondente immagine. Si, noti, ad esempio, che\n","# train_labels[2] è 4, che è il numero rappresentato in train_imges[2].\n","\n","train_labels"],"metadata":{"id":"nkfWoooyapTK","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1647947927423,"user_tz":-60,"elapsed":225,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"fabfba94-cd6f-4c13-c770-6023b050d965"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["array([5, 0, 4, ..., 5, 6, 8], dtype=uint8)"]},"metadata":{},"execution_count":17}]},{"cell_type":"code","source":["train_labels[2]"],"metadata":{"id":"cB_S4tYoP-pP","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1647947947841,"user_tz":-60,"elapsed":239,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"ff627bbc-b401-487d-e056-b3617fd916c0"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["4"]},"metadata":{},"execution_count":18}]},{"cell_type":"code","source":["# train_labels è un classico array ad una singola dimensione, lungo 60.000\n","\n","train_labels.shape"],"metadata":{"id":"mhTkSJypcg-l","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1647948051809,"user_tz":-60,"elapsed":241,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"dd9cbdf0-0b67-43e9-a024-3c0c14ed2989"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["(60000,)"]},"metadata":{},"execution_count":19}]},{"cell_type":"markdown","source":["## Preparazione dei dati"],"metadata":{"id":"yzzKtrUih-b1"}},{"cell_type":"code","source":["# Occorre trasformare le etichette dal formato numerico originale ad un formato\n","# confrontabile con l'output del percettrone. Usiamo il metodo predefinito di\n","# tf.keras.utils.to_categorical.\n","\n","train_labels_ok = tf.keras.utils.to_categorical(train_labels)\n","test_labels_ok = tf.keras.utils.to_categorical(test_labels)"],"metadata":{"id":"UGt-pP9DgCyY"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# Adesso al posto di ogni etichetta troviamo un vetore di 0 ed 1. Se l'etichetta\n","# è n, il corrispondente vettore è omposto da tutti 0 tranne un 1 in posizione n.\n","# Questa codifica prende il nome di One Hot Encoding.\n","\n","train_labels_ok"],"metadata":{"id":"2D8CID4dge56","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1647948112278,"user_tz":-60,"elapsed":242,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"40087d41-05a5-4759-a22f-178050bd21ba"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["array([[0., 0., 0., ..., 0., 0., 0.],\n"," [1., 0., 0., ..., 0., 0., 0.],\n"," [0., 0., 0., ..., 0., 0., 0.],\n"," ...,\n"," [0., 0., 0., ..., 0., 0., 0.],\n"," [0., 0., 0., ..., 0., 0., 0.],\n"," [0., 0., 0., ..., 0., 1., 0.]], dtype=float32)"]},"metadata":{},"execution_count":21}]},{"cell_type":"code","source":["train_labels_ok[2]"],"metadata":{"id":"tiz39S3tJD2T","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1647948114855,"user_tz":-60,"elapsed":221,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"e054171b-8184-4435-a957-ef57d88382dc"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["array([0., 0., 0., 0., 1., 0., 0., 0., 0., 0.], dtype=float32)"]},"metadata":{},"execution_count":22}]},{"cell_type":"code","source":["# È prassi fornire i dati in input in maniera normalizzata, come numeri compresi\n","# tra 0 ed 1. Pertanto, anche se non strettamente necessario, dividiamo tutti i\n","# numeri che compongono una immagine per 255.\n","\n","train_images_ok = train_images / 255.0\n","test_images_ok = test_images / 255.0"],"metadata":{"id":"PU7lzXaZgxzI"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["train_images_ok[2]"],"metadata":{"id":"8gyltB2upvrT","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1647183378834,"user_tz":-60,"elapsed":12,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"1e4b8ab8-5dab-4369-c5c5-f68eca0c59c3"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["array([[0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. ],\n"," [0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. ],\n"," [0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. ],\n"," [0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. ],\n"," [0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. ],\n"," [0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0.2627451 , 0.90980392, 0.15294118, 0. , 0. ,\n"," 0. , 0. , 0. ],\n"," [0. , 0. , 0. , 0. , 0.24313725,\n"," 0.31764706, 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0.47058824, 0.70588235, 0.15294118, 0. , 0. ,\n"," 0. , 0. , 0. ],\n"," [0. , 0. , 0. , 0. , 0.49411765,\n"," 0.63921569, 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0.00784314,\n"," 0.6 , 0.82352941, 0.15686275, 0. , 0. ,\n"," 0. , 0. , 0. ],\n"," [0. , 0. , 0. , 0. , 0.8627451 ,\n"," 0.63921569, 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0.10588235,\n"," 0.99607843, 0.63529412, 0. , 0. , 0. ,\n"," 0. , 0. , 0. ],\n"," [0. , 0. , 0. , 0. , 0.87058824,\n"," 0.63921569, 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0.71764706,\n"," 0.99607843, 0.49019608, 0. , 0. , 0. ,\n"," 0. , 0. , 0. ],\n"," [0. , 0. , 0. , 0.18039216, 0.96078431,\n"," 0.63921569, 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0.77647059,\n"," 0.99607843, 0.21960784, 0. , 0. , 0. ,\n"," 0. , 0. , 0. ],\n"," [0. , 0. , 0. , 0.47058824, 0.99607843,\n"," 0.63921569, 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0.09019608, 0.90588235,\n"," 0.99607843, 0.11372549, 0. , 0. , 0. ,\n"," 0. , 0. , 0. ],\n"," [0. , 0. , 0. , 0.62352941, 0.99607843,\n"," 0.47058824, 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0.63921569, 0.99607843,\n"," 0.84705882, 0.0627451 , 0. , 0. , 0. ,\n"," 0. , 0. , 0. ],\n"," [0. , 0. , 0. , 0.62352941, 0.99607843,\n"," 0.2627451 , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0.05490196, 0.3372549 , 0.69803922, 0.97254902, 0.99607843,\n"," 0.35686275, 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. ],\n"," [0. , 0. , 0. , 0.62352941, 0.99607843,\n"," 0.33333333, 0. , 0. , 0. , 0.18431373,\n"," 0.19215686, 0.45490196, 0.56470588, 0.58823529, 0.94509804,\n"," 0.95294118, 0.91764706, 0.70196078, 0.94509804, 0.98823529,\n"," 0.15686275, 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. ],\n"," [0. , 0. , 0. , 0.58823529, 0.99215686,\n"," 0.92941176, 0.81176471, 0.81176471, 0.81176471, 0.99215686,\n"," 0.99607843, 0.98039216, 0.94117647, 0.77647059, 0.56078431,\n"," 0.35686275, 0.10980392, 0.01960784, 0.91372549, 0.98039216,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. ],\n"," [0. , 0. , 0. , 0. , 0.46666667,\n"," 0.69411765, 0.69411765, 0.69411765, 0.69411765, 0.69411765,\n"," 0.38431373, 0.21960784, 0. , 0. , 0. ,\n"," 0. , 0. , 0.4 , 0.99607843, 0.8627451 ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. ],\n"," [0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0.6627451 , 0.99607843, 0.5372549 ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. ],\n"," [0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0.6627451 , 0.99607843, 0.22352941,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. ],\n"," [0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0.6627451 , 0.99607843, 0.22352941,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. ],\n"," [0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0.6627451 , 1. , 0.36862745,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. ],\n"," [0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0.6627451 , 0.99607843, 0.37647059,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. ],\n"," [0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0.6627451 , 0.99607843, 0.6 ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. ],\n"," [0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0.6627451 , 1. , 0.6 ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. ],\n"," [0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0.37647059, 0.99607843, 0.6 ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. ],\n"," [0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. ],\n"," [0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. ],\n"," [0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. , 0. , 0. ,\n"," 0. , 0. , 0. ]])"]},"metadata":{},"execution_count":47}]},{"cell_type":"code","source":["plt.imshow(train_images_ok[2], cmap= plt.cm.binary)"],"metadata":{"id":"l0XXFtNJpqNp","colab":{"base_uri":"https://localhost:8080/","height":282},"executionInfo":{"status":"ok","timestamp":1647948198901,"user_tz":-60,"elapsed":299,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"22206939-31fa-43e2-8958-73fbc7655ce2"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":[""]},"metadata":{},"execution_count":24},{"output_type":"display_data","data":{"text/plain":[""],"image/png":"iVBORw0KGgoAAAANSUhEUgAAAPsAAAD4CAYAAAAq5pAIAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAANAUlEQVR4nO3db6hc9Z3H8c9n3VTUBozN5RKSaGoJiXFh0zrGP5WSpViMTxJBpEFCRN34QKGFCoor1Eciy7alD9bC7RqarllLoBXzILhxL9VQlJKrxBgVN65ebcJN7sQgsSBEvd99cE/KNd45czNzZs7cfN8vGGbmfM+558shn5yZ85uZnyNCAM5/f1d3AwD6g7ADSRB2IAnCDiRB2IEk/r6fO1u8eHGsWLGin7sEUhkfH9eJEyc8W62rsNu+RdIvJV0g6T8i4omy9VesWKGxsbFudgm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0kQdiAJwg4k4Yjo387spqQPZixaLOlE3xo4N4Pa26D2JdFbp6rs7YqImPX33/oa9q/s3B6LiEZtDZQY1N4GtS+J3jrVr954GQ8kQdiBJOoO+0jN+y8zqL0Nal8SvXWqL73V+p4dQP/UfWYH0CeEHUiilrDbvsX2O7bftf1wHT20Ynvc9hu2D9geq7mX7bYnbR+asewy2y/YPlzczzrHXk29PWb7aHHsDti+tabeltv+o+23bL9p+0fF8lqPXUlffTlufX/PbvsCSf8r6WZJRyTtl7Q5It7qayMt2B6X1IiI2j+AYft7kv4q6bcR8Q/Fsn+VdDIinij+o1wUEQ8NSG+PSfpr3dN4F7MVLZk5zbikTZLuUo3HrqSvO9SH41bHmX2dpHcj4r2IOC3pd5I21tDHwIuIfZJOnrV4o6QdxeMdmv7H0nctehsIETEREa8Vjz+RdGaa8VqPXUlffVFH2JdK+suM50c0WPO9h6S9tl+1va3uZmYxHBETxeNjkobrbGYWbafx7qezphkfmGPXyfTn3eIC3VfdFBHfkbRB0v3Fy9WBFNPvwQZp7HRO03j3yyzTjP9Nnceu0+nPu1VH2I9KWj7j+bJi2UCIiKPF/aSkZzV4U1EfPzODbnE/WXM/fzNI03jPNs24BuDY1Tn9eR1h3y9ppe1v2v6apB9K2l1DH19h+5LiwolsXyLpBxq8qah3S9paPN4q6bkae/mSQZnGu9U046r52NU+/XlE9P0m6VZNX5H/P0n/UkcPLfq6UtLrxe3NunuT9IymX9Z9pulrG/dI+oakUUmHJf2PpMsGqLf/lPSGpIOaDtaSmnq7SdMv0Q9KOlDcbq372JX01ZfjxsdlgSS4QAckQdiBJAg7kARhB5Ig7EAShB1IgrADSfw/VdkAV4stm1cAAAAASUVORK5CYII=\n"},"metadata":{"needs_background":"light"}}]},{"cell_type":"markdown","source":["## Creazione della rete neurale"],"metadata":{"id":"QR_cty6BmHl-"}},{"cell_type":"code","source":["# Costruiamo una rete neurale simile al percettrone. Non è esattamente uguale perché la funzione\n","# di attivazione hard_sigmoid è simile ma non identica alla step function usata nel percettrone.\n","# Il primo strato (Flatten) ha lo copo di trasformare una immagine di 28 x 28 pixel in un unico vettore\n","# di 784 elementi, il secondo (Dense) è lo strato di neuroni. Ci sono 10 neuroni, ognuno connesso\n","# a tutti i 784 pixel dell'immagine.\n","\n","network = tf.keras.models.Sequential([\n"," tf.keras.layers.Flatten(input_shape=(28, 28)),\n"," tf.keras.layers.Dense(10, activation='hard_sigmoid')\n","])"],"metadata":{"id":"ijqRtHB-dbLc"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# Visualizziamo la struttura della rete. Notate che la rete ha 7850 parametri. Ognuno dei 10 neuroni\n","# di output ha infatti 784 pesi (uno per ogni pixel) ed un valore di bias. In totale quindi sono\n","# (784 + 1) * 10 = 7850 pesi. Notare che lo strato Flatten eseguo un compito fisso e non ha\n","# nessun peso associato.\n","\n","network.summary()"],"metadata":{"id":"LJQ31oMQbUl2","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1647948227598,"user_tz":-60,"elapsed":269,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"cb0e611a-3c5b-45a9-87d4-d620b5399230"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["Model: \"sequential\"\n","_________________________________________________________________\n"," Layer (type) Output Shape Param # \n","=================================================================\n"," flatten (Flatten) (None, 784) 0 \n"," \n"," dense (Dense) (None, 10) 7850 \n"," \n","=================================================================\n","Total params: 7,850\n","Trainable params: 7,850\n","Non-trainable params: 0\n","_________________________________________________________________\n"]}]},{"cell_type":"code","source":["# Prima di poter usare una rete, bisogna indicare dei parametri addizionali:\n","# - una funzione di loss, che specifica come valutare le differenze tra il vero valore degli\n","# output e quello predetto (mse = scarto quadrarico medio)\n","# - l'algoritmo di ottimizzazione che viene usato per aggiornare i pesi della rete \n","# nel tentativodi ridurre la funzione di loss (sgd = stochastic gradient descend)\n","# - metriche da visualizzare durante l'addestramento (in questo caso visualizziamo l'accuratezza, la\n","# percentuale di istanze classificate correttamente nell'insieme di addestramento)\n","\n","network.compile(optimizer='sgd', loss='mse', metrics=['accuracy'])"],"metadata":{"id":"ldsTGQkmef5M"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## Addestramento rete e valutazione dei risultati"],"metadata":{"id":"eAUCCnwhpysw"}},{"cell_type":"code","source":["# Lanciamo l'addestramento della rete:\n","# - batch_size è il numero di istanze su cui addestrare i pesi as ogni passo\n","# - epochs è il numero di volte per cui ripetere l'addestramento sull'intero\n","# insieme di training (ogni volta usando come punto di partenza i pesi trovati\n","# nell'epoca precedente)\n","# Restituisce la storia dell'addestramento\n","\n","history = network.fit(train_images_ok, train_labels_ok, epochs=15, batch_size=128)"],"metadata":{"id":"Bf9mOwmyfc39","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1647948352201,"user_tz":-60,"elapsed":21409,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"777daef6-e91f-4074-84d4-cb20bee21552"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["Epoch 1/15\n","469/469 [==============================] - 2s 2ms/step - loss: 0.1497 - accuracy: 0.0925\n","Epoch 2/15\n","469/469 [==============================] - 1s 2ms/step - loss: 0.1000 - accuracy: 0.2175\n","Epoch 3/15\n","469/469 [==============================] - 1s 2ms/step - loss: 0.0902 - accuracy: 0.3668\n","Epoch 4/15\n","469/469 [==============================] - 1s 2ms/step - loss: 0.0846 - accuracy: 0.4729\n","Epoch 5/15\n","469/469 [==============================] - 1s 2ms/step - loss: 0.0801 - accuracy: 0.5420\n","Epoch 6/15\n","469/469 [==============================] - 1s 2ms/step - loss: 0.0764 - accuracy: 0.5885\n","Epoch 7/15\n","469/469 [==============================] - 1s 2ms/step - loss: 0.0732 - accuracy: 0.6234\n","Epoch 8/15\n","469/469 [==============================] - 1s 3ms/step - loss: 0.0703 - accuracy: 0.6522\n","Epoch 9/15\n","469/469 [==============================] - 2s 4ms/step - loss: 0.0678 - accuracy: 0.6752\n","Epoch 10/15\n","469/469 [==============================] - 2s 4ms/step - loss: 0.0655 - accuracy: 0.6971\n","Epoch 11/15\n","469/469 [==============================] - 2s 4ms/step - loss: 0.0635 - accuracy: 0.7163\n","Epoch 12/15\n","469/469 [==============================] - 2s 3ms/step - loss: 0.0617 - accuracy: 0.7329\n","Epoch 13/15\n","469/469 [==============================] - 1s 2ms/step - loss: 0.0600 - accuracy: 0.7469\n","Epoch 14/15\n","469/469 [==============================] - 1s 3ms/step - loss: 0.0585 - accuracy: 0.7585\n","Epoch 15/15\n","469/469 [==============================] - 1s 2ms/step - loss: 0.0571 - accuracy: 0.7666\n"]}]},{"cell_type":"code","source":["# Calcoliamo le predizioni della rete neurale sull'insieme di addestramento\n","\n","train_predictions = network.predict(train_images_ok)"],"metadata":{"id":"6p-SJ2j3lHaB"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# Vediamo ad esempio cosa produce la per l'immagine numero 2. Il valore di\n","# probabilità maggiore è il quinto (corrispondente alla cifra 4), per cui la\n","# nostra rete ha indovinato che l'immagine numero 2 è effettivamente un 4.\n","\n","train_predictions[2]"],"metadata":{"id":"uuYEbKHJPnAI","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1647948384088,"user_tz":-60,"elapsed":257,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"383f22ba-99b0-4505-b238-a6ae6ae44ce6"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["array([0.19969535, 0. , 0.3530274 , 0.27846837, 0.43973866,\n"," 0.23310304, 0.3095976 , 0.2790324 , 0.32828578, 0.3380107 ],\n"," dtype=float32)"]},"metadata":{},"execution_count":31}]},{"cell_type":"code","source":["# Per calcolare qual è l'indice col valore maggiore, possiamo usare la funzione np.argmax\n","\n","np.argmax(train_predictions[2])"],"metadata":{"id":"bwYBgEW-P-bW","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1647948387868,"user_tz":-60,"elapsed":273,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"8627b7df-b746-4640-c305-fbb718bd2c51"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["4"]},"metadata":{},"execution_count":32}]},{"cell_type":"code","source":["# Deteminiamo quali sono le immagini dove la nostra rete sbaglia\n","\n","errors = np.where([ np.argmax(x) for x in train_predictions] != train_labels)\n","errors"],"metadata":{"id":"KpZh8c27tFZ6","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1647948434645,"user_tz":-60,"elapsed":359,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"420b0514-a592-4fc6-bbeb-e922d1aac13b"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["(array([ 11, 17, 19, ..., 59982, 59992, 59993]),)"]},"metadata":{},"execution_count":33}]},{"cell_type":"code","source":["# Controlliamo ad esempio l'immagine 19\n","\n","print(\"Predizione: \", np.argmax(train_predictions[19]))\n","print(\"Valore effettivo: \", train_labels[19])\n","\n","plt.imshow(train_images_ok[19], cmap= plt.cm.binary)"],"metadata":{"id":"7jk0s5Smw479","colab":{"base_uri":"https://localhost:8080/","height":317},"executionInfo":{"status":"ok","timestamp":1647948452054,"user_tz":-60,"elapsed":263,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"5f0d48ea-3311-473e-ee09-186999643b3a"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["Predizione: 1\n","Valore effettivo: 9\n"]},{"output_type":"execute_result","data":{"text/plain":[""]},"metadata":{},"execution_count":35},{"output_type":"display_data","data":{"text/plain":[""],"image/png":"iVBORw0KGgoAAAANSUhEUgAAAPsAAAD4CAYAAAAq5pAIAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAANOklEQVR4nO3db4hV953H8c9nszUY6wNdRyNWdrpNnshCbBkkpKG4lG1MHmSsGKkPioUQC0mgJUI2uEjzIEgIiaUPNgW7asfQpAptiA9kt1EKoRCN1+BG47DVhgkdMToixBQS3KTffTDHMDVzf3e8/53v+wXDvfd877nny8GP597zO/f+HBECMPv9Xa8bANAdhB1IgrADSRB2IAnCDiTx993c2KJFi2JwcLCbmwRSGRsb06VLlzxdraWw214j6WeSbpH0nxHxbOn5g4ODqtVqrWwSQMHQ0FDdWtNv423fIuk/JN0vaYWkjbZXNPt6ADqrlc/sqySdjYj3IuKqpF9LGm5PWwDarZWwL5P05ymPx6tlf8P2Zts127WJiYkWNgegFR0/Gx8ROyNiKCKGBgYGOr05AHW0EvZzkpZPefyVahmAPtRK2I9JutP2V23PkfQ9SQfa0xaAdmt66C0iPrX9uKT/1uTQ2+6IeLdtnQFoq5bG2SPioKSDbeoFQAdxuSyQBGEHkiDsQBKEHUiCsANJEHYgCcIOJEHYgSQIO5AEYQeSIOxAEoQdSIKwA0kQdiAJwg4kQdiBJAg7kARhB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Peltv+ve3Ttt+1/aNqeU/3XaGvruy3rn9mt32LpD9K+ldJ45KOSdoYEae72kgdtsckDUVEzy/AsP0tSX+RtDci/rla9pykyxHxbPUf5YKI+Lc+6e1pSX/p9TTe1WxFS6dOMy5praQfqIf7rtDXBnVhv/XiyL5K0tmIeC8irkr6taThHvTR9yLiDUmXr1s8LGmkuj+iyX8sXVent74QEecj4u3q/keSrk0z3tN9V+irK3oR9mWS/jzl8bj6a773kPQ728dtb+51M9NYEhHnq/sfSFrSy2am0XAa7266bprxvtl3zUx/3ipO0H3RvRHxDUn3S3qserval2LyM1g/jZ3OaBrvbplmmvHP9XLfNTv9eat6EfZzkpZPefyVallfiIhz1e1FSa+q/6aivnBtBt3q9mKP+/lcP03jPd004+qDfdfL6c97EfZjku60/VXbcyR9T9KBHvTxBbbnVSdOZHuepO+o/6aiPiBpU3V/k6TXetjL3+iXabzrTTOuHu+7nk9/HhFd/5P0gCbPyP9J0r/3ooc6ff2TpP+p/t7tdW+SXtHk27r/0+S5jYcl/YOkw5LOSDokaWEf9faSpJOS3tFksJb2qLd7NfkW/R1JJ6q/B3q97wp9dWW/cbkskAQn6IAkCDuQBGEHkiDsQBKEHUiCsANJEHYgif8HyQ3/tmY4CHAAAAAASUVORK5CYII=\n"},"metadata":{"needs_background":"light"}}]},{"cell_type":"code","source":["train_predictions[19]"],"metadata":{"id":"jUMY8OB7T26Q","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1647948456327,"user_tz":-60,"elapsed":293,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"92769eeb-7b10-4bd9-a616-7dbaad3a1c35"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["array([0.2219345 , 0.36409962, 0.3848489 , 0.21659535, 0.22457659,\n"," 0.31142017, 0.23089674, 0.19564283, 0.3023529 , 0.16161236],\n"," dtype=float32)"]},"metadata":{},"execution_count":36}]},{"cell_type":"code","source":["# Valutiamo adesso il funzionamento della rete su immagini nuove, che non fanno\n","# parte dell'insieme di addestramento. Usiamo a tale scopo il metodo evaluate\n","# e l'insieme di test. Notiamo che l'accuratezza è simile a quella sull'insieme\n","# di addestramento, ma non sarà sempre così.\n","\n","network.evaluate(test_images_ok, test_labels_ok)"],"metadata":{"id":"aNpBfBmwk3Ee","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1647948489323,"user_tz":-60,"elapsed":840,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"c3ae7ef4-9876-45ac-db20-26e0a20b1b67"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["313/313 [==============================] - 1s 1ms/step - loss: 0.0558 - accuracy: 0.7791\n"]},{"output_type":"execute_result","data":{"text/plain":["[0.05584060028195381, 0.7791000008583069]"]},"metadata":{},"execution_count":37}]},{"cell_type":"code","source":["# Visualizziamo l'andamento dell'errore di addestramento\n","\n","history_dict = history.history\n","loss_values = history_dict['loss']\n","accuracy_values = history_dict['accuracy']\n","epochs = range(1, len(loss_values) + 1)\n","\n","plt.plot(epochs, loss_values, 'bo', label='Training loss')\n","plt.title('Training loss w.r.t epochs')\n","plt.xlabel('Epochs')\n","plt.ylabel('Loss')\n","plt.legend()\n","plt.show()\n","\n","plt.plot(epochs, accuracy_values, 'bo', label='Accuracy')\n","plt.title('Accuracy w.r.t. epochs')\n","plt.xlabel('Epochs')\n","plt.ylabel('Accuracy')\n","plt.legend()\n","plt.show()"],"metadata":{"id":"7ubrN-ehSgAt","colab":{"base_uri":"https://localhost:8080/","height":573},"executionInfo":{"status":"ok","timestamp":1647948493694,"user_tz":-60,"elapsed":776,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"1b4bb309-4bd9-4a32-9546-0e141d7ba947"},"execution_count":null,"outputs":[{"output_type":"display_data","data":{"text/plain":[""],"image/png":"iVBORw0KGgoAAAANSUhEUgAAAYgAAAEWCAYAAAB8LwAVAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAesUlEQVR4nO3deZgddZ3v8fcnnZCQhcUQWdJJOmgEA4SOdNiiGYSrBEHCKCiZvkJEDDgiiDgQyDggIzMuqFxGuEMjqzaCDyg3KsoiS0AQ6cSIBMIQMR0aWUICWQxLlu/9o6rDoVPdfTrp6uqT/ryep5+u+lXVOd9z0jmfU79fLYoIzMzM2upXdAFmZtY7OSDMzCyTA8LMzDI5IMzMLJMDwszMMjkgzMwskwPCegVJv5Z0cnev28UaDpPU0t2P25dJukjSj4uuw7ZM/6ILsMolaU3J7GDgTWBDOn9aRDSW+1gRcVQe6/YlkpYAp0bEPUXXYtsGB4RtsYgY2jrd0YeTpP4Rsb4na+sL/L5a3tzFZN2utatG0nmSXgSuk7SzpF9KWibp1XS6umSb+yWdmk7PkPSQpEvTdf8q6agtXHespLmSVku6R9IV5XZ5SHp/+lyvSVoo6diSZR+T9GT6uM9L+mravkv62l6TtELSg5I2+38m6euS/iudHiDp75K+k85vL+kNSe9qs81Fkm6V9GNJq4AZJct+BIwGfiFpjaRz23lNx0hakNb3sKQJJcuWSDo/fV2vSrpO0qCS5Z+XtDh9XXMk7VGybB9Jd6fLXpJ0QcnTbifpxvS9WiiprmS789L3b7WkpyUd0ek/jPUYB4TlZTfgXcAYYCbJ39p16fxo4HXgBx1sfxDwNLAL8G3gGknagnVvAv4ADAcuA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zE73FFasWMFxxx3HhAkTOPjgg3n88ccBeOCBBzbtAU2cOJHVq1fzwgsvMGXKFGpra9l333158MEHt/o96tOD1K0D0bNnJ91Ko0cn4eABarPidDQ22N3/N1taWnj44Yepqqpi1apVPPjgg/Tv35977rmHCy64gNtuu22zbRYtWsR9993H6tWr2WuvvfjCF76w2bkFf/zjH1m4cCF77LEHkydP5ne/+x11dXWcdtppzJ07l7FjxzJ9+vRO67vwwguZOHEit99+O/feey8nnXQSCxYs4NJLL+WKK65g8uTJrFmzhkGDBtHQ0MCRRx7J7Nmz2bBhA2vbvolboE8HBCR/cA4Es96jJ8cGTzjhBKqqqgBYuXIlJ598Ms888wySWLduXeY2Rx99NAMHDmTgwIG8+93v5qWXXqK6uvod6xx44IGb2mpra1myZAlDhw5lzz333HQewvTp02loaOiwvoceemhTSB1++OEsX76cVatWMXnyZL7yla9QX1/PJz7xCaqrq5k0aRKnnHIK69at47jjjqO2tnar3hvo411MZtb79OTY4JAhQzZNf+1rX+PDH/4wTzzxBL/4xS/aPWdg4MCBm6arqqoyxy/KWWdrzJo1ix/+8Ie8/vrrTJ48mUWLFjFlyhTmzp3LyJEjmTFjBjfeeONWP48Dwsx6laLGBleuXMnIkSMBuP7667v98ffaay+effZZlixZAsAtt9zS6TYf+tCHaEwHX+6//3522WUXdthhB/7yl7+w3377cd555zFp0iQWLVpEc3Mzu+66K5///Oc59dRTmT9//lbX7IAws16lvh4aGmDMGJCS3w0N+XcFn3vuuZx//vlMnDix27/xA2y//fZceeWVTJ06lQMOOIBhw4ax4447drjNRRddxLx585gwYQKzZs3ihhtuAOCyyy5j3333ZcKECQwYMICjjjqK+++/n/3335+JEydyyy23cNZZZ211zdvMPanr6urCNwwy652eeuop3v/+9xddRuHWrFnD0KFDiQi++MUvMm7cOM4+++wee/6sfwdJ8yKiLmt970GYmfWQq6++mtraWvbZZx9WrlzJaaedVnRJHerzRzGZmfWUs88+u0f3GLaW9yDMrEdsK93ZlWpL3n8HhJnlbtCgQSxf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UA1NLAAAAAElFTkSuQmCC\n"},"metadata":{"needs_background":"light"}},{"output_type":"display_data","data":{"text/plain":[""],"image/png":"iVBORw0KGgoAAAANSUhEUgAAAYIAAAEWCAYAAABrDZDcAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nO3deZhcdZ3v8feHhExoCHtESKfTUcMSQ8LSRFlGHQFFQaITHcM0mwvRKwFUXHByH/RGM+PVO8qI6NADgpomASNixssmkMCoKGkWgQSQwGTpGC5NIBAICVm+949zOql0qrurl1PV1efzep566pzfOafqW72cb53fcn6KCMzMLL92q3QAZmZWWU4EZmY550RgZpZzTgRmZjnnRGBmlnNOBGZmOedEYGbdkhSS3lbpOCwbTgTWryQtkvSSpL+pdCzVQFJ9epIdWulYLL+cCKzfSKoH/hYI4Mwyv3dVnEiV8P+dDSj+g7T+dC7wR+B64LzCDZJGS7pZUpuktZJ+WLDtAklPSFovaamkY9LynaojJF0v6Vvp8nsktUr6qqTngOsk7SfpN+l7vJQu1xYcv7+k6yT9Nd1+S1r+uKQPFey3u6QXJB3d8QNKulfS1HT5xDTG09P1kyU9UuSYRZJmS/o9sAF4S8Hm+9LndZJelXR8dz9kSftIulbSGkmrJX1L0pB02/mSfi/ph5JelvSkpJMLjj1E0gJJL0paJumCgm1DJP2TpGfS38WDkkYXvPUpkp6WtE7SVZKUHve29Ofycvpzu7G7z2ADixOB9adzgeb08X5JB0FyggF+A6wA6oFRwLx028eAb6TH7k1yJbG2xPd7M7A/MAaYTvL3fF26Xge8DvywYP+fAzXA24E3Ad9Py38GnF2w3weBNRHxcJH3vBd4T7r8buBZ4F0F6/d2Eus5aYwjSH4O7dqP3Tci9oqI+zs5vtD1wBbgbcDRwPuATxdsfwfwDHAg8HXgZkn7p9vmAa3AIcBHgX+W9N502x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ZPnsz69eu5/vrrmTFjxvbXO+OMM1i0aBEAe+21F5deeimTJk3i/vvvZ9asWRx33HFMmDCB6dOn0z70YtmyZZxyyilMmjSJY445hmeeeYZzzz2XW27ZMbFXY2Mjv/71r/v2Yc1sF1lV4cyeDTU1O5fV1CTl/SYiqupx7LHHRkdLly7dpawzY8ZEJClg58eYMSW/RFFz5syJT37ykxERcfzxx0dLS0v86Ec/iqlTp8bmzZsjImLt2rWxadOmGDt2bDzwwAMREfHyyy/H5s2b47rrrosLL7xw++udfvrpsXDhwoiIAOLGG2/cvm3t2rXbl88+++xYsGBBRERMnjw5br755oiIeP311+O1116LRYsWxZQpUyIiYt26dVFfX789no568nM0q2Zz5iT/81LyPGdO319TKn5ukfr+2v0RL9ASnZxXc3dFkFV929y5c5k2bRoA06ZNY+7cudx111185jOfYejQpHPW/vvvz1NPPcXBBx/McccdB8Dee++9fXtnhgwZwtSpU7evL1y4kHe84x0ceeSR3HPPPSxZsoT169ezevVqPvKRjwDJALGamhre/e538/TTT9PW1sbcuXOZOnVqt+9nNphVYxVOYyMsXw7btiXP/dVbqF3uzgh1dckvvlh5b7344ovcc889PPbYY0hi69atSNp+si/F0KFD2bZtx01XC/v0Dx8+nCFDhmwv/9znPkdLSwujR4/mG9/4Rrf9/88991zmzJnDvHnzuO6663r46cwGl66qcPpygp09e+dunpBBFU5GcndFkEV92/z58znnnHNYsWIFy5cvZ9WqVYwdO5ZJkyZx9dVXs2XLFiBJGIcddhhr1qxh8eLFAKxfv54tW7ZQX1/PI488wrZt21i1ahUPPPBA0fdqP+kfeOCBvPrqq8yfPx+AESNGUFtbu709YNOmTWxI/yLPP/98rrjiCgDGjx/f+w9qNghkVSvQ2AhNTTBmDEjJc1NT/397z0LuEkEWv6y5c+dur5JpN3XqVNasWUNdXR0TJ05k0qRJ3HDDDQwbNowbb7yRiy66iEmTJnHqqaeyceNGTjzxRMaOHcv48eO5+OKLOeaYY4q+17777ssFF1zAhAkTeP/737/TVcfPf/5zfvCDHz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x7ImLAfmuNiOeAVZIOS4tOBpZWMKSurATeKakm/Zs4mQHasN3BAuC8dPk84NcVjKVLkk4jqdY8MyI2VDqerkTEYxHxpoioT//fWoFj0r/pAcmJoG9OBM4h+Xb9SPr4YKWDGkQuApolPQocBfxzheMpKr1qmQ88BDxG8n81oG4xIGkucD9wmKRWSZ8Cvg2cKulpkquab1cyxnadxPpDYATw2/T/7N8rGmSBTuKtKr7FhJlZzvmKwMws55wIzMxyzonAzCznnAjMzHLOicDMLOecCMxSkrYWdAN+RFK/jWSWVF/s7pRmA8HQSkMcVnAAAAGvSURBVAdgNoC8HhFHVToIs3LzFYFZNyQtl/QdSY9JekDS29Lyekn3pPfIv1tSXVp+UHrP/D+nj/bbTQyR9B/pvAV3Stoj3f/idE6LRyXNq9DHtBxzIjDbYY8OVUMfL9j2ckQcSTLC9Yq07Ergp+k98puBH6TlPwDujYhJJPdHWpKWjwOuioi3A+uAqWn5ZcDR6et8NqsPZ9YZjyw2S0l6NSL2KlK+HHhvRDyb3mTwuYg4QNILwMERsTktXxMRB0pqA2ojYlPBa9QDv00ngUHSV4HdI+Jbkm4HXgVuAW6JiFcz/qhmO/EVgVlpopPlnthUsLyVHW10pwNXkVw9LE4ntzErGycCs9J8vOD5/nT5D+yYkrIR+K90+W7gf8D2OaL36exFJe0GjI6IhcBXgX2AXa5KzLLkbx5mO+wh6ZGC9dsjor0L6X7pXVA3AWelZReRzKD2ZZLZ1D6Rll8CNKV3odxKkhTWUNwQYE6aLAT8YIBPyWmDkNsIzLqRthE0RMQLlY7FLAuuGjIzyzlfEZiZ5ZyvCMzMcs6JwMws55wIzMxyzonAzCznnAjMzHLu/wMNRFotI8zTAAAAAABJRU5ErkJggg==\n"},"metadata":{"needs_background":"light"}}]},{"cell_type":"markdown","source":["# Tensori"],"metadata":{"id":"DCcTH7De7Dva"}},{"cell_type":"code","source":["# Scalari (tensori a zero dimensioni)\n","\n","x = np.array(12)"],"metadata":{"id":"EsAWa_NF7KD4"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["x"],"metadata":{"id":"rEaq-bCy7SNv","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1647948501014,"user_tz":-60,"elapsed":6,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"d5bc1076-8f2f-475c-b5e7-fd0a0f3e9a6c"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["array(12)"]},"metadata":{},"execution_count":40}]},{"cell_type":"code","source":["x.shape"],"metadata":{"id":"iW4A2Mid7T0t","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1647948502835,"user_tz":-60,"elapsed":254,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"01ac9b80-7039-4991-ee7f-b24feb25d4f9"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["()"]},"metadata":{},"execution_count":41}]},{"cell_type":"code","source":["# Vettori (tensori ad una dimensione)\n","\n","x = np.array([12, 3, 6, 14])"],"metadata":{"id":"Q_djOScz7VIM"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["x"],"metadata":{"id":"Jw04eg6s7ed4","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1647948506107,"user_tz":-60,"elapsed":243,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"905803cd-085a-4828-e6b5-4369ef5b3f86"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["array([12, 3, 6, 14])"]},"metadata":{},"execution_count":43}]},{"cell_type":"code","source":["x.shape"],"metadata":{"id":"FRVuy9Wy7fFd","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1647948508433,"user_tz":-60,"elapsed":12,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"618504e3-2798-4740-99f8-37f07e1ea4ee"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["(4,)"]},"metadata":{},"execution_count":44}]},{"cell_type":"code","source":["# Matrici (tensori a due dimensioni)\n","\n","x = np.array([[5, 78, 2, 34, 0],\n"," [6, 79, 3, 35, 1],\n"," [7, 80, 4, 36, 2]])"],"metadata":{"id":"m7krI7_X7f2N"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["x"],"metadata":{"id":"iLwrkM6O7nnu","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1647948511367,"user_tz":-60,"elapsed":349,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"155baab0-e9f7-4dd9-ccc7-462b791b6f4e"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["array([[ 5, 78, 2, 34, 0],\n"," [ 6, 79, 3, 35, 1],\n"," [ 7, 80, 4, 36, 2]])"]},"metadata":{},"execution_count":46}]},{"cell_type":"code","source":["x.shape"],"metadata":{"id":"0Khr7rGk7n7d","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1647948513613,"user_tz":-60,"elapsed":262,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"73995714-442b-4753-9e58-244b668b3eb1"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["(3, 5)"]},"metadata":{},"execution_count":47}]},{"cell_type":"code","source":["# Tensori a tre dimensioni\n","\n","x = np.array(\n"," [\n"," [\n"," [ 5, 78, 2, 34, 0],\n"," [ 6, 79, 3, 35, 1],\n"," [ 7, 80, 4, 36, 2]\n"," ],\n"," [\n"," [ 1, 0, 0, 1, 0],\n"," [ 0, 1, 1, 0, 1],\n"," [ 1, 0, 0, 0, 0]\n"," ] \n","])"],"metadata":{"id":"OndeKcrr7ot3"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["x"],"metadata":{"id":"BFamLGLZ8RP4","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1647948516875,"user_tz":-60,"elapsed":4,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"f9150a50-9b0d-47c7-e579-79e6c2d1ad81"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["array([[[ 5, 78, 2, 34, 0],\n"," [ 6, 79, 3, 35, 1],\n"," [ 7, 80, 4, 36, 2]],\n","\n"," [[ 1, 0, 0, 1, 0],\n"," [ 0, 1, 1, 0, 1],\n"," [ 1, 0, 0, 0, 0]]])"]},"metadata":{},"execution_count":49}]},{"cell_type":"code","source":["x.shape"],"metadata":{"id":"Tc2Km2bE8SKl","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1647948518025,"user_tz":-60,"elapsed":4,"user":{"displayName":"Gianluca Amato","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhEmlMukD8qDnxG1PlDxK7Dzm1rjUKZSz0BhiJc9w=s64","userId":"18269286707108730791"}},"outputId":"b59e9968-44f0-4ab1-c4d0-34478c8e2fde"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["(2, 3, 5)"]},"metadata":{},"execution_count":50}]}]}