{"id":223,"date":"2023-10-20T17:40:44","date_gmt":"2023-10-20T17:40:44","guid":{"rendered":"https:\/\/aiopentext.itd.cnr.it\/aiforteacher\/chapter\/hands-on-machine-learning\/"},"modified":"2024-01-31T08:12:17","modified_gmt":"2024-01-31T08:12:17","slug":"hands-on-machine-learning","status":"publish","type":"chapter","link":"https:\/\/aiopentext.itd.cnr.it\/aiforteacher\/chapter\/hands-on-machine-learning\/","title":{"raw":"Hands-on Machine Learning","rendered":"Hands-on Machine Learning"},"content":{"raw":"<p class=\"indent no-indent\">This activity is adapted from activities created by Codeweek and licenced under <a href=\"https:\/\/creativecommons.org\/licenses\/by-nc-sa\/4.0\/deed.en\" target=\"_blank\" rel=\"noopener\" data-cke-saved-href=\"https:\/\/creativecommons.org\/licenses\/by-nc-sa\/4.0\/deed.en\">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) licence<\/a>. You could find the <a href=\"https:\/\/codeweek.eu\/training\/introduction-to-artificial-intelligence-in-the-classroom\" target=\"_blank\" rel=\"noopener\" data-cke-saved-href=\"https:\/\/codeweek.eu\/training\/introduction-to-artificial-intelligence-in-the-classroom\">original list of activities in their website.<\/a> The two datasets used, initial training dataset and test dataset, are also created by them.<\/p>\n<p class=\"indent\">We will use <a href=\"https:\/\/teachablemachine.withgoogle.com\/train\" target=\"_blank\" rel=\"noopener\" data-cke-saved-href=\"https:\/\/teachablemachine.withgoogle.com\/train\">Google's teachable machine<\/a> to train a machine to classify an image as a bicycle or a motorcycle. To recapitulate, a machine-learning application has to be trained and tested before it can be used. We will gather and group sample pictures of the categories the machine will classify, train the model and test if it classifies correctly a set of example pictures.<img class=\"aligncenter wp-image-59 \" src=\"http:\/\/aiopentext.itd.cnr.it\/wp-content\/uploads\/sites\/10\/2024\/01\/ch2-page3-traintestuse-e1697823763965.png\" alt=\"\" width=\"543\" height=\"258\"><\/p>\n\n<h3 style=\"text-align: left\">Step 1: Gather and group example pictures<\/h3>\n<ol>\n \t<li>Download the pictures of bicycles <a href=\"https:\/\/drive.google.com\/drive\/folders\/1cqDQHXn4SiYsHNOjV3aZpIFf7fArAvwc\" target=\"_blank\" rel=\"noopener\" data-cke-saved-href=\"https:\/\/drive.google.com\/drive\/folders\/1cqDQHXn4SiYsHNOjV3aZpIFf7fArAvwc\">found here.<\/a><\/li>\n \t<li style=\"text-align: justify\">If necessary, extract the zip folder contents into a local folder on your computer. This will be used as training set for the Machine Learning application.<\/li>\n \t<li>Download the pictures of motorcycles <a href=\"https:\/\/drive.google.com\/drive\/folders\/1cqDQHXn4SiYsHNOjV3aZpIFf7fArAvwc\" target=\"_blank\" rel=\"noopener\" data-cke-saved-href=\"https:\/\/drive.google.com\/drive\/folders\/1cqDQHXn4SiYsHNOjV3aZpIFf7fArAvwc\">found here.<\/a><\/li>\n \t<li style=\"text-align: justify\">If necessary, extract the zip-folder contents into a local folder on your computer. This will also be used as training set for the Machine Learning application.<\/li>\n \t<li>Download all the pictures <a href=\"https:\/\/drive.google.com\/drive\/folders\/10VQn2N9P997aUJMhyBWwnvs0KRVpw3Hs\" target=\"_blank\" rel=\"noopener\" data-cke-saved-href=\"https:\/\/drive.google.com\/drive\/folders\/10VQn2N9P997aUJMhyBWwnvs0KRVpw3Hs\">found here.<\/a><\/li>\n \t<li style=\"text-align: justify\">If necessary, extract the zip-folder contents into a local folder on your computer. This will be used as test dataset.<\/li>\n \t<li style=\"text-align: justify\">Click <a href=\"https:\/\/teachablemachine.withgoogle.com\/train\" target=\"_blank\" rel=\"noopener\" data-cke-saved-href=\"https:\/\/teachablemachine.withgoogle.com\/train\">Google's Teachable Machine<\/a> and select <strong>Image Project <\/strong>&gt; <strong>Standard Image Model.<\/strong><\/li>\n \t<li style=\"text-align: justify\">Under Class 1, click <strong>upload &gt; Choose images from your files &gt; <\/strong>Open the folder of bicycle images you created during steps 1 and 2 and import all the images stored here.<\/li>\n \t<li style=\"text-align: justify\">Under Class 2, click <strong>upload &gt; Choose images from your files &gt; <\/strong>Open the folder of motorcycle images you created during steps 3 and 4 and import all the images stored here.<\/li>\n<\/ol>\n<h3 style=\"text-align: left\">Step 2: Train the model<\/h3>\n<p class=\"no-indent\">Under Training, click <strong>Train Model<\/strong>. The model learns how to classify bicycles and motorcycles. Wait till it says <strong>Model Trained.<\/strong><\/p>\n<p class=\"indent\">Note that we do not have to manually select and input features of bicycles and motorcycles. The algorithms knows how to find its own features from the images!<a class=\"inline\" href=\"https:\/\/www.ai4t.eu\/book\/ai-for-teachers-an-open-textbook\/media\/teachable%20machine.PNG\" name=\"scalar-inline-media\" data-align=\"center\" data-annotations=\"\" data-size=\"large\" data-caption=\"description\" data-cke-saved-name=\"scalar-inline-media\" data-cke-saved-href=\"https:\/\/www.ai4t.eu\/book\/ai-for-teachers-an-open-textbook\/media\/teachable%20machine.PNG\"><\/a><\/p>\n\n\n[caption id=\"attachment_222\" align=\"aligncenter\" width=\"1024\"]<img class=\"wp-image-222 size-large\" src=\"http:\/\/aiopentext.itd.cnr.it\/wp-content\/uploads\/sites\/10\/2023\/11\/chadd-teachable-machine-1024x415.png\" alt=\"\" width=\"1024\" height=\"415\"> Source : Google's Teachable machine[\/caption]\n<h3 style=\"text-align: left\">Step 3: Test the model<\/h3>\n<ol>\n \t<li style=\"text-align: justify\">Under <strong>Preview<\/strong>, click the arrow near <strong>webcam<\/strong> and change input to <strong>File.<\/strong><\/li>\n \t<li style=\"text-align: justify\">Click <strong>choose images from your files <\/strong>and choose a test image you stored in steps 5 and 6.<\/li>\n \t<li style=\"text-align: justify\">Scroll down and check output.<\/li>\n \t<li style=\"text-align: justify\">You can repeat with other images to compare performance.<\/li>\n<\/ol>\n<p class=\"no-indent\">If an image is used to train a classifier, the machine will have already recorded the corresponding label for the particular image. Showing this image to the machine during the testing phase will not measure how well the model generalises. That is why your test and train datasets should be different from each other.<\/p>\n<p class=\"no-indent\"><strong>Note<\/strong>: You can also upload your own images to train and test. <a href=\"https:\/\/wordpress.org\/openverse\/?referrer=creativecommons.org\" target=\"_blank\" rel=\"noopener\" data-cke-saved-href=\"https:\/\/wordpress.org\/openverse\/?referrer=creativecommons.org\">Here<\/a> is a good source of free images.<\/p>","rendered":"<p class=\"indent no-indent\">This activity is adapted from activities created by Codeweek and licenced under <a href=\"https:\/\/creativecommons.org\/licenses\/by-nc-sa\/4.0\/deed.en\" target=\"_blank\" rel=\"noopener\" data-cke-saved-href=\"https:\/\/creativecommons.org\/licenses\/by-nc-sa\/4.0\/deed.en\">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) licence<\/a>. You could find the <a href=\"https:\/\/codeweek.eu\/training\/introduction-to-artificial-intelligence-in-the-classroom\" target=\"_blank\" rel=\"noopener\" data-cke-saved-href=\"https:\/\/codeweek.eu\/training\/introduction-to-artificial-intelligence-in-the-classroom\">original list of activities in their website.<\/a> The two datasets used, initial training dataset and test dataset, are also created by them.<\/p>\n<p class=\"indent\">We will use <a href=\"https:\/\/teachablemachine.withgoogle.com\/train\" target=\"_blank\" rel=\"noopener\" data-cke-saved-href=\"https:\/\/teachablemachine.withgoogle.com\/train\">Google&#8217;s teachable machine<\/a> to train a machine to classify an image as a bicycle or a motorcycle. To recapitulate, a machine-learning application has to be trained and tested before it can be used. We will gather and group sample pictures of the categories the machine will classify, train the model and test if it classifies correctly a set of example pictures.<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-59\" src=\"http:\/\/aiopentext.itd.cnr.it\/wp-content\/uploads\/sites\/10\/2024\/01\/ch2-page3-traintestuse-e1697823763965.png\" alt=\"\" width=\"543\" height=\"258\" srcset=\"https:\/\/aiopentext.itd.cnr.it\/aiforteacher\/wp-content\/uploads\/sites\/10\/2024\/01\/ch2-page3-traintestuse-e1697823763965.png 940w, https:\/\/aiopentext.itd.cnr.it\/aiforteacher\/wp-content\/uploads\/sites\/10\/2024\/01\/ch2-page3-traintestuse-e1697823763965-300x142.png 300w, https:\/\/aiopentext.itd.cnr.it\/aiforteacher\/wp-content\/uploads\/sites\/10\/2024\/01\/ch2-page3-traintestuse-e1697823763965-768x364.png 768w, https:\/\/aiopentext.itd.cnr.it\/aiforteacher\/wp-content\/uploads\/sites\/10\/2024\/01\/ch2-page3-traintestuse-e1697823763965-65x31.png 65w, https:\/\/aiopentext.itd.cnr.it\/aiforteacher\/wp-content\/uploads\/sites\/10\/2024\/01\/ch2-page3-traintestuse-e1697823763965-225x107.png 225w, https:\/\/aiopentext.itd.cnr.it\/aiforteacher\/wp-content\/uploads\/sites\/10\/2024\/01\/ch2-page3-traintestuse-e1697823763965-350x166.png 350w\" sizes=\"(max-width: 543px) 100vw, 543px\" \/><\/p>\n<h3 style=\"text-align: left\">Step 1: Gather and group example pictures<\/h3>\n<ol>\n<li>Download the pictures of bicycles <a href=\"https:\/\/drive.google.com\/drive\/folders\/1cqDQHXn4SiYsHNOjV3aZpIFf7fArAvwc\" target=\"_blank\" rel=\"noopener\" data-cke-saved-href=\"https:\/\/drive.google.com\/drive\/folders\/1cqDQHXn4SiYsHNOjV3aZpIFf7fArAvwc\">found here.<\/a><\/li>\n<li style=\"text-align: justify\">If necessary, extract the zip folder contents into a local folder on your computer. This will be used as training set for the Machine Learning application.<\/li>\n<li>Download the pictures of motorcycles <a href=\"https:\/\/drive.google.com\/drive\/folders\/1cqDQHXn4SiYsHNOjV3aZpIFf7fArAvwc\" target=\"_blank\" rel=\"noopener\" data-cke-saved-href=\"https:\/\/drive.google.com\/drive\/folders\/1cqDQHXn4SiYsHNOjV3aZpIFf7fArAvwc\">found here.<\/a><\/li>\n<li style=\"text-align: justify\">If necessary, extract the zip-folder contents into a local folder on your computer. This will also be used as training set for the Machine Learning application.<\/li>\n<li>Download all the pictures <a href=\"https:\/\/drive.google.com\/drive\/folders\/10VQn2N9P997aUJMhyBWwnvs0KRVpw3Hs\" target=\"_blank\" rel=\"noopener\" data-cke-saved-href=\"https:\/\/drive.google.com\/drive\/folders\/10VQn2N9P997aUJMhyBWwnvs0KRVpw3Hs\">found here.<\/a><\/li>\n<li style=\"text-align: justify\">If necessary, extract the zip-folder contents into a local folder on your computer. This will be used as test dataset.<\/li>\n<li style=\"text-align: justify\">Click <a href=\"https:\/\/teachablemachine.withgoogle.com\/train\" target=\"_blank\" rel=\"noopener\" data-cke-saved-href=\"https:\/\/teachablemachine.withgoogle.com\/train\">Google&#8217;s Teachable Machine<\/a> and select <strong>Image Project <\/strong>&gt; <strong>Standard Image Model.<\/strong><\/li>\n<li style=\"text-align: justify\">Under Class 1, click <strong>upload &gt; Choose images from your files &gt; <\/strong>Open the folder of bicycle images you created during steps 1 and 2 and import all the images stored here.<\/li>\n<li style=\"text-align: justify\">Under Class 2, click <strong>upload &gt; Choose images from your files &gt; <\/strong>Open the folder of motorcycle images you created during steps 3 and 4 and import all the images stored here.<\/li>\n<\/ol>\n<h3 style=\"text-align: left\">Step 2: Train the model<\/h3>\n<p class=\"no-indent\">Under Training, click <strong>Train Model<\/strong>. The model learns how to classify bicycles and motorcycles. Wait till it says <strong>Model Trained.<\/strong><\/p>\n<p class=\"indent\">Note that we do not have to manually select and input features of bicycles and motorcycles. The algorithms knows how to find its own features from the images!<a class=\"inline\" href=\"https:\/\/www.ai4t.eu\/book\/ai-for-teachers-an-open-textbook\/media\/teachable%20machine.PNG\" name=\"scalar-inline-media\" data-align=\"center\" data-annotations=\"\" data-size=\"large\" data-caption=\"description\" data-cke-saved-name=\"scalar-inline-media\" data-cke-saved-href=\"https:\/\/www.ai4t.eu\/book\/ai-for-teachers-an-open-textbook\/media\/teachable%20machine.PNG\"><\/a><\/p>\n<figure id=\"attachment_222\" aria-describedby=\"caption-attachment-222\" style=\"width: 1024px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-222 size-large\" src=\"http:\/\/aiopentext.itd.cnr.it\/wp-content\/uploads\/sites\/10\/2023\/11\/chadd-teachable-machine-1024x415.png\" alt=\"\" width=\"1024\" height=\"415\" srcset=\"https:\/\/aiopentext.itd.cnr.it\/aiforteacher\/wp-content\/uploads\/sites\/10\/2023\/11\/chadd-teachable-machine-1024x415.png 1024w, https:\/\/aiopentext.itd.cnr.it\/aiforteacher\/wp-content\/uploads\/sites\/10\/2023\/11\/chadd-teachable-machine-300x122.png 300w, https:\/\/aiopentext.itd.cnr.it\/aiforteacher\/wp-content\/uploads\/sites\/10\/2023\/11\/chadd-teachable-machine-768x311.png 768w, https:\/\/aiopentext.itd.cnr.it\/aiforteacher\/wp-content\/uploads\/sites\/10\/2023\/11\/chadd-teachable-machine-1536x623.png 1536w, https:\/\/aiopentext.itd.cnr.it\/aiforteacher\/wp-content\/uploads\/sites\/10\/2023\/11\/chadd-teachable-machine-65x26.png 65w, https:\/\/aiopentext.itd.cnr.it\/aiforteacher\/wp-content\/uploads\/sites\/10\/2023\/11\/chadd-teachable-machine-225x91.png 225w, https:\/\/aiopentext.itd.cnr.it\/aiforteacher\/wp-content\/uploads\/sites\/10\/2023\/11\/chadd-teachable-machine-350x142.png 350w, https:\/\/aiopentext.itd.cnr.it\/aiforteacher\/wp-content\/uploads\/sites\/10\/2023\/11\/chadd-teachable-machine.png 1892w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption id=\"caption-attachment-222\" class=\"wp-caption-text\">Source : Google&#8217;s Teachable machine<\/figcaption><\/figure>\n<h3 style=\"text-align: left\">Step 3: Test the model<\/h3>\n<ol>\n<li style=\"text-align: justify\">Under <strong>Preview<\/strong>, click the arrow near <strong>webcam<\/strong> and change input to <strong>File.<\/strong><\/li>\n<li style=\"text-align: justify\">Click <strong>choose images from your files <\/strong>and choose a test image you stored in steps 5 and 6.<\/li>\n<li style=\"text-align: justify\">Scroll down and check output.<\/li>\n<li style=\"text-align: justify\">You can repeat with other images to compare performance.<\/li>\n<\/ol>\n<p class=\"no-indent\">If an image is used to train a classifier, the machine will have already recorded the corresponding label for the particular image. Showing this image to the machine during the testing phase will not measure how well the model generalises. That is why your test and train datasets should be different from each other.<\/p>\n<p class=\"no-indent\"><strong>Note<\/strong>: You can also upload your own images to train and test. <a href=\"https:\/\/wordpress.org\/openverse\/?referrer=creativecommons.org\" target=\"_blank\" rel=\"noopener\" data-cke-saved-href=\"https:\/\/wordpress.org\/openverse\/?referrer=creativecommons.org\">Here<\/a> is a good source of free images.<\/p>\n","protected":false},"author":1,"menu_order":8,"template":"","meta":{"pb_show_title":"","pb_short_title":"","pb_subtitle":"","pb_authors":[],"pb_section_license":""},"chapter-type":[49],"contributor":[],"license":[],"part":204,"_links":{"self":[{"href":"https:\/\/aiopentext.itd.cnr.it\/aiforteacher\/wp-json\/pressbooks\/v2\/chapters\/223"}],"collection":[{"href":"https:\/\/aiopentext.itd.cnr.it\/aiforteacher\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/aiopentext.itd.cnr.it\/aiforteacher\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/aiopentext.itd.cnr.it\/aiforteacher\/wp-json\/wp\/v2\/users\/1"}],"version-history":[{"count":1,"href":"https:\/\/aiopentext.itd.cnr.it\/aiforteacher\/wp-json\/pressbooks\/v2\/chapters\/223\/revisions"}],"predecessor-version":[{"id":224,"href":"https:\/\/aiopentext.itd.cnr.it\/aiforteacher\/wp-json\/pressbooks\/v2\/chapters\/223\/revisions\/224"}],"part":[{"href":"https:\/\/aiopentext.itd.cnr.it\/aiforteacher\/wp-json\/pressbooks\/v2\/parts\/204"}],"metadata":[{"href":"https:\/\/aiopentext.itd.cnr.it\/aiforteacher\/wp-json\/pressbooks\/v2\/chapters\/223\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/aiopentext.itd.cnr.it\/aiforteacher\/wp-json\/wp\/v2\/media?parent=223"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/aiopentext.itd.cnr.it\/aiforteacher\/wp-json\/pressbooks\/v2\/chapter-type?post=223"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/aiopentext.itd.cnr.it\/aiforteacher\/wp-json\/wp\/v2\/contributor?post=223"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/aiopentext.itd.cnr.it\/aiforteacher\/wp-json\/wp\/v2\/license?post=223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}