{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.7.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n for filename in filenames:\n print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-03-25T09:19:52.795659Z","iopub.execute_input":"2023-03-25T09:19:52.796151Z","iopub.status.idle":"2023-03-25T09:19:52.808798Z","shell.execute_reply.started":"2023-03-25T09:19:52.796108Z","shell.execute_reply":"2023-03-25T09:19:52.807537Z"},"trusted":true},"execution_count":43,"outputs":[]},{"cell_type":"code","source":"#https://www.analyticsvidhya.com/blog/2022/06/building-a-food-image-classifier-using-fastai/\n","metadata":{"execution":{"iopub.status.busy":"2023-03-25T09:19:52.814318Z","iopub.execute_input":"2023-03-25T09:19:52.815228Z","iopub.status.idle":"2023-03-25T09:19:52.820178Z","shell.execute_reply.started":"2023-03-25T09:19:52.815181Z","shell.execute_reply":"2023-03-25T09:19:52.819104Z"},"trusted":true},"execution_count":44,"outputs":[]},{"cell_type":"code","source":"#!pip install -Uqq fastai","metadata":{"execution":{"iopub.status.busy":"2023-03-25T09:19:52.829410Z","iopub.execute_input":"2023-03-25T09:19:52.829743Z","iopub.status.idle":"2023-03-25T09:19:52.834222Z","shell.execute_reply.started":"2023-03-25T09:19:52.829710Z","shell.execute_reply":"2023-03-25T09:19:52.833071Z"},"trusted":true},"execution_count":45,"outputs":[]},{"cell_type":"code","source":"#https://www.analyticsvidhya.com/blog/2022/06/building-a-food-image-classifier-using-fastai/","metadata":{"execution":{"iopub.status.busy":"2023-03-25T09:19:52.841721Z","iopub.execute_input":"2023-03-25T09:19:52.842214Z","iopub.status.idle":"2023-03-25T09:19:52.846989Z","shell.execute_reply.started":"2023-03-25T09:19:52.842178Z","shell.execute_reply":"2023-03-25T09:19:52.845762Z"},"trusted":true},"execution_count":46,"outputs":[]},{"cell_type":"code","source":"from fastai.vision.all import *\nfrom fastai import *\nfrom fastai.learner import load_learner\n","metadata":{"execution":{"iopub.status.busy":"2023-03-25T09:19:52.858270Z","iopub.execute_input":"2023-03-25T09:19:52.858598Z","iopub.status.idle":"2023-03-25T09:19:52.864491Z","shell.execute_reply.started":"2023-03-25T09:19:52.858564Z","shell.execute_reply":"2023-03-25T09:19:52.863250Z"},"trusted":true},"execution_count":47,"outputs":[]},{"cell_type":"code","source":"foodPath = untar_data(URLs.FOOD) #untar_data(URLs.FOOD)","metadata":{"execution":{"iopub.status.busy":"2023-03-25T09:19:52.879187Z","iopub.execute_input":"2023-03-25T09:19:52.879547Z","iopub.status.idle":"2023-03-25T09:19:52.885181Z","shell.execute_reply.started":"2023-03-25T09:19:52.879512Z","shell.execute_reply":"2023-03-25T09:19:52.884101Z"},"trusted":true},"execution_count":48,"outputs":[]},{"cell_type":"code","source":"len(get_image_files(foodPath))","metadata":{"execution":{"iopub.status.busy":"2023-03-25T09:19:52.917105Z","iopub.execute_input":"2023-03-25T09:19:52.917437Z","iopub.status.idle":"2023-03-25T09:19:52.968098Z","shell.execute_reply.started":"2023-03-25T09:19:52.917404Z","shell.execute_reply":"2023-03-25T09:19:52.967087Z"},"trusted":true},"execution_count":49,"outputs":[{"execution_count":49,"output_type":"execute_result","data":{"text/plain":"3000"},"metadata":{}}]},{"cell_type":"code","source":"print(os.listdir(foodPath))","metadata":{"execution":{"iopub.status.busy":"2023-03-25T09:19:52.979628Z","iopub.execute_input":"2023-03-25T09:19:52.982167Z","iopub.status.idle":"2023-03-25T09:19:52.992267Z","shell.execute_reply.started":"2023-03-25T09:19:52.982126Z","shell.execute_reply":"2023-03-25T09:19:52.990991Z"},"trusted":true},"execution_count":50,"outputs":[{"name":"stdout","text":"['h5', 'labels.txt', 'test.json', 'images', 'test.txt', 'train.txt', 'classes.txt', 'train.json']\n","output_type":"stream"}]},{"cell_type":"code","source":"image_dir_path = foodPath/'images'\nimage_categories = os.listdir(image_dir_path)\nprint(image_categories)","metadata":{"execution":{"iopub.status.busy":"2023-03-25T09:19:53.004782Z","iopub.execute_input":"2023-03-25T09:19:53.005507Z","iopub.status.idle":"2023-03-25T09:19:53.015108Z","shell.execute_reply.started":"2023-03-25T09:19:53.005470Z","shell.execute_reply":"2023-03-25T09:19:53.014099Z"},"trusted":true},"execution_count":51,"outputs":[{"name":"stdout","text":"['fish_and_chips', 'caprese_salad', 'strawberry_shortcake', 'pork_chop', 'edamame', 'macaroni_and_cheese', 'gnocchi', 'lobster_roll_sandwich', 'takoyaki', 'baklava', 'sushi', 'beef_tartare', 'miso_soup', 'steak', 'hot_dog', 'grilled_cheese_sandwich', 'greek_salad', 'crab_cakes', 'falafel', 'beet_salad', 'apple_pie', 'onion_rings', 'chocolate_mousse', 'risotto', 'chicken_wings', 'french_fries', 'pancakes', 'paella', 'chicken_quesadilla', 'gyoza', 'bread_pudding', 'beignets', 'carrot_cake', 'waffles', 'ceviche', 'huevos_rancheros', 'ravioli', 'sashimi', 'bibimbap', 'creme_brulee', 'spaghetti_bolognese', 'cheese_plate', 'oysters', 'filet_mignon', 'baby_back_ribs', 'fried_rice', 'ice_cream', 'tacos', 'cheesecake', 'foie_gras', 'shrimp_and_grits', 'macarons', 'poutine', 'french_onion_soup', 'deviled_eggs', 'grilled_salmon', 'eggs_benedict', 'croque_madame', 'seaweed_salad', 'churros', 'hummus', 'bruschetta', 'club_sandwich', 'ramen', 'clam_chowder', 'cup_cakes', 'hot_and_sour_soup', 'garlic_bread', 'breakfast_burrito', 'guacamole', 'lobster_bisque', 'spring_rolls', 'samosa', 'red_velvet_cake', 'pulled_pork_sandwich', 'escargots', 'chocolate_cake', 'spaghetti_carbonara', 'caesar_salad', 'hamburger', 'tuna_tartare', 'donuts', 'fried_calamari', 'mussels', 'omelette', 'panna_cotta', 'pad_thai', 'beef_carpaccio', 'pizza', 'nachos', 'chicken_curry', 'pho', 'tiramisu', 'frozen_yogurt', 'peking_duck', 'prime_rib', 'cannoli', 'dumplings', 'french_toast', 'lasagna', 'scallops']\n","output_type":"stream"}]},{"cell_type":"code","source":"df_train = pd.read_json('/root/.fastai/data/food-101/train.json')\ndf_test = pd.read_json('/root/.fastai/data/food-101/test.json')\ndf_train.head()\n","metadata":{"execution":{"iopub.status.busy":"2023-03-25T09:19:53.054152Z","iopub.execute_input":"2023-03-25T09:19:53.054494Z","iopub.status.idle":"2023-03-25T09:19:53.214998Z","shell.execute_reply.started":"2023-03-25T09:19:53.054462Z","shell.execute_reply":"2023-03-25T09:19:53.213925Z"},"trusted":true},"execution_count":52,"outputs":[{"execution_count":52,"output_type":"execute_result","data":{"text/plain":" churros hot_and_sour_soup samosa \\\n0 churros/1004234 hot_and_sour_soup/1002782 samosa/1008131 \n1 churros/1013460 hot_and_sour_soup/1003688 samosa/1011601 \n2 churros/1016791 hot_and_sour_soup/1008185 samosa/101365 \n3 churros/102100 hot_and_sour_soup/1008701 samosa/1015943 \n4 churros/1025494 hot_and_sour_soup/1008924 samosa/1016296 \n\n sashimi pork_chop spring_rolls \\\n0 sashimi/1001239 pork_chop/1000802 spring_rolls/1002160 \n1 sashimi/1001363 pork_chop/1006233 spring_rolls/1003056 \n2 sashimi/1002556 pork_chop/1019530 spring_rolls/1003507 \n3 sashimi/1007253 pork_chop/1019569 spring_rolls/1008736 \n4 sashimi/1010510 pork_chop/1025391 spring_rolls/1012525 \n\n panna_cotta beef_tartare greek_salad \\\n0 panna_cotta/1001332 beef_tartare/1000431 greek_salad/1007149 \n1 panna_cotta/1003460 beef_tartare/1005746 greek_salad/1009138 \n2 panna_cotta/1011097 beef_tartare/1009672 greek_salad/1010520 \n3 panna_cotta/1013000 beef_tartare/1012128 greek_salad/1011665 \n4 panna_cotta/1020036 beef_tartare/1027680 greek_salad/1012989 \n\n foie_gras ... chicken_quesadilla pho \\\n0 foie_gras/1004944 ... chicken_quesadilla/1004279 pho/1005681 \n1 foie_gras/1008577 ... chicken_quesadilla/1009225 pho/1011443 \n2 foie_gras/1011711 ... chicken_quesadilla/1011413 pho/1012513 \n3 foie_gras/1017233 ... chicken_quesadilla/1023828 pho/1019401 \n4 foie_gras/1023512 ... chicken_quesadilla/1024740 pho/1021371 \n\n prime_rib cheesecake ice_cream omelette \\\n0 prime_rib/1001089 cheesecake/1001446 ice_cream/1012277 omelette/1001719 \n1 prime_rib/1006320 cheesecake/1004515 ice_cream/101858 omelette/1007843 \n2 prime_rib/100945 cheesecake/1004807 ice_cream/102595 omelette/1015300 \n3 prime_rib/10120 cheesecake/1017408 ice_cream/1044117 omelette/1029915 \n4 prime_rib/1016126 cheesecake/1021942 ice_cream/104465 omelette/1038109 \n\n grilled_cheese_sandwich lobster_roll_sandwich \\\n0 grilled_cheese_sandwich/1003153 lobster_roll_sandwich/100009 \n1 grilled_cheese_sandwich/10060 lobster_roll_sandwich/1001432 \n2 grilled_cheese_sandwich/1007544 lobster_roll_sandwich/100646 \n3 grilled_cheese_sandwich/1013343 lobster_roll_sandwich/100655 \n4 grilled_cheese_sandwich/1016030 lobster_roll_sandwich/100702 \n\n nachos oysters \n0 nachos/100284 oysters/1008124 \n1 nachos/1009513 oysters/1016229 \n2 nachos/1011394 oysters/1023832 \n3 nachos/1013641 oysters/103236 \n4 nachos/1014846 oysters/1038150 \n\n[5 rows x 101 columns]","text/html":"
\n | churros | \nhot_and_sour_soup | \nsamosa | \nsashimi | \npork_chop | \nspring_rolls | \npanna_cotta | \nbeef_tartare | \ngreek_salad | \nfoie_gras | \n... | \nchicken_quesadilla | \npho | \nprime_rib | \ncheesecake | \nice_cream | \nomelette | \ngrilled_cheese_sandwich | \nlobster_roll_sandwich | \nnachos | \noysters | \n
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \nchurros/1004234 | \nhot_and_sour_soup/1002782 | \nsamosa/1008131 | \nsashimi/1001239 | \npork_chop/1000802 | \nspring_rolls/1002160 | \npanna_cotta/1001332 | \nbeef_tartare/1000431 | \ngreek_salad/1007149 | \nfoie_gras/1004944 | \n... | \nchicken_quesadilla/1004279 | \npho/1005681 | \nprime_rib/1001089 | \ncheesecake/1001446 | \nice_cream/1012277 | \nomelette/1001719 | \ngrilled_cheese_sandwich/1003153 | \nlobster_roll_sandwich/100009 | \nnachos/100284 | \noysters/1008124 | \n
1 | \nchurros/1013460 | \nhot_and_sour_soup/1003688 | \nsamosa/1011601 | \nsashimi/1001363 | \npork_chop/1006233 | \nspring_rolls/1003056 | \npanna_cotta/1003460 | \nbeef_tartare/1005746 | \ngreek_salad/1009138 | \nfoie_gras/1008577 | \n... | \nchicken_quesadilla/1009225 | \npho/1011443 | \nprime_rib/1006320 | \ncheesecake/1004515 | \nice_cream/101858 | \nomelette/1007843 | \ngrilled_cheese_sandwich/10060 | \nlobster_roll_sandwich/1001432 | \nnachos/1009513 | \noysters/1016229 | \n
2 | \nchurros/1016791 | \nhot_and_sour_soup/1008185 | \nsamosa/101365 | \nsashimi/1002556 | \npork_chop/1019530 | \nspring_rolls/1003507 | \npanna_cotta/1011097 | \nbeef_tartare/1009672 | \ngreek_salad/1010520 | \nfoie_gras/1011711 | \n... | \nchicken_quesadilla/1011413 | \npho/1012513 | \nprime_rib/100945 | \ncheesecake/1004807 | \nice_cream/102595 | \nomelette/1015300 | \ngrilled_cheese_sandwich/1007544 | \nlobster_roll_sandwich/100646 | \nnachos/1011394 | \noysters/1023832 | \n
3 | \nchurros/102100 | \nhot_and_sour_soup/1008701 | \nsamosa/1015943 | \nsashimi/1007253 | \npork_chop/1019569 | \nspring_rolls/1008736 | \npanna_cotta/1013000 | \nbeef_tartare/1012128 | \ngreek_salad/1011665 | \nfoie_gras/1017233 | \n... | \nchicken_quesadilla/1023828 | \npho/1019401 | \nprime_rib/10120 | \ncheesecake/1017408 | \nice_cream/1044117 | \nomelette/1029915 | \ngrilled_cheese_sandwich/1013343 | \nlobster_roll_sandwich/100655 | \nnachos/1013641 | \noysters/103236 | \n
4 | \nchurros/1025494 | \nhot_and_sour_soup/1008924 | \nsamosa/1016296 | \nsashimi/1010510 | \npork_chop/1025391 | \nspring_rolls/1012525 | \npanna_cotta/1020036 | \nbeef_tartare/1027680 | \ngreek_salad/1012989 | \nfoie_gras/1023512 | \n... | \nchicken_quesadilla/1024740 | \npho/1021371 | \nprime_rib/1016126 | \ncheesecake/1021942 | \nice_cream/104465 | \nomelette/1038109 | \ngrilled_cheese_sandwich/1016030 | \nlobster_roll_sandwich/100702 | \nnachos/1014846 | \noysters/1038150 | \n
5 rows × 101 columns
\n