-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
12,728 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import json | ||
|
||
class Image_Encoder: | ||
def decoder(): | ||
with open("../../encodings.json", "r") as f: | ||
label_to_index = json.load(f) | ||
index_to_label = {v: k for k, v in label_to_index.items()} | ||
return index_to_label | ||
|
||
def encoder(): | ||
with open("../../encodings.json", "r") as f: | ||
label_to_index = json.load(f) | ||
return label_to_index |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# @dataset{Food Recognition 2022, | ||
# author={AIcrowd}, | ||
# title={Food Recognition 2022}, | ||
# year={2022}, | ||
# url={https://www.kaggle.com/datasets/awsaf49/food-recognition-2022-dataset} | ||
# } | ||
import numpy as np | ||
import os | ||
import tarfile | ||
import csv | ||
import json | ||
|
||
tar_directory = "/" | ||
tar_find = os.path.join(tar_directory, "food-recognition-DatasetNinja.tar") | ||
test = "./food-recognition-DatasetNinja.tar" | ||
|
||
|
||
testing_csv_path = "testing_files.csv" | ||
validation_csv_path = "validation_files.csv" | ||
training_csv_path = "training_files.csv" | ||
|
||
meta_dir = "./../meta.json" | ||
|
||
testing_data = [] | ||
validation_data = [] | ||
training_data = [] | ||
|
||
class DataInfo: | ||
""" | ||
This class just contains functions about the meta data | ||
""" | ||
|
||
def populate_meta_data(): | ||
""" | ||
Populates the meta data json into the meta data folder | ||
""" | ||
with tarfile.open(test, "r") as tar: | ||
tar_contents = tar.getnames() | ||
print("Contents of the tar file:") | ||
for name in tar_contents: | ||
print(name) | ||
json_file = next((name for name in tar_contents if name.endswith(".json")), None) | ||
if json_file: | ||
print(f"Extracting {json_file}...") | ||
tar.extract(json_file, path=meta_dir) | ||
extracted_path = os.path.join(meta_dir, json_file) | ||
print(f"File extracted to: {extracted_path}") | ||
else: | ||
print("No JSON file found in the tar archive.") | ||
|
||
def num_classes(): | ||
""" | ||
Returns the number of classes in the dataset | ||
""" | ||
path = "./../../meta.json" | ||
with open(path, "r") as file: | ||
data = json.load(file) | ||
|
||
if "classes" in data: | ||
classes = data["classes"] | ||
num_classes = len(classes) | ||
else: | ||
print("No 'classes' key found in the JSON file.") | ||
print(num_classes) | ||
return num_classes | ||
|
||
|
||
def return_classes(): | ||
""" | ||
Returns the a set of the unique classes in the dataset | ||
""" | ||
path = "../Image_Model/meta.json" | ||
unique_labels = [] | ||
with open(meta_dir, "r") as file: | ||
data = json.load(file) | ||
for i in data["classes"]: | ||
unique_labels.append(i["title"]) | ||
return list(set(unique_labels)) | ||
|
||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"alfa-sprouts": 0, "almonds": 1, "anchovies": 2, "aperitif-with-alcohol-aperol-spritz": 3, "apple": 4, "apple-crumble": 5, "apple-pie": 6, "applesauce-unsweetened-canned": 7, "apricot-dried": 8, "apricots": 9, "artichoke": 10, "avocado": 11, "bacon": 12, "bacon-cooking": 13, "bacon-frying": 14, "bacon-raw": 15, "bagel-without-filling": 16, "baked-potato": 17, "balsamic-salad-dressing": 18, "balsamic-vinegar": 19, "banana": 20, "banana-cake": 21, "basil": 22, "bean-seeds": 23, "beans-kidney": 24, "beans-white": 25, "beef": 26, "beef-cut-into-stripes-only-meat": 27, "beef-filet": 28, "beef-minced-only-meat": 29, "beef-roast": 30, "beef-sirloin-steak": 31, "beer": 32, "beetroot-raw": 33, "beetroot-steamed-without-addition-of-salt": 34, "bell-pepper-red-raw": 35, "bell-pepper-red-stewed-without-addition-of-fat-without-addition-of-salt": 36, "berries": 37, "birchermuesli-prepared-no-sugar-added": 38, "biscuit-with-butter": 39, "biscuits": 40, "black-forest-tart": 41, "black-olives": 42, "blackberry": 43, "blue-mould-cheese": 44, "blueberries": 45, "bolognaise-sauce": 46, "bouillon": 47, "bouillon-vegetable": 48, "bouquet-garni": 49, "braided-white-loaf": 50, "brazil-nut": 51, "bread": 52, "bread-5-grain": 53, "bread-black": 54, "bread-french-white-flour": 55, "bread-fruit": 56, "bread-grain": 57, "bread-half-white": 58, "bread-meat-substitute-lettuce-sauce": 59, "bread-nut": 60, "bread-olive": 61, "bread-pita": 62, "bread-rye": 63, "bread-sourdough": 64, "bread-spelt": 65, "bread-ticino": 66, "bread-toast": 67, "bread-white": 68, "bread-whole-wheat": 69, "bread-wholemeal": 70, "bread-wholemeal-toast": 71, "breadcrumbs-unspiced": 72, "brie": 73, "brioche": 74, "broccoli": 75, "brownie": 76, "brussel-sprouts": 77, "buckwheat-grain-peeled": 78, "buckwheat-pancake": 79, "bulgur": 80, "butter": 81, "butter-herb": 82, "butter-spread-puree-almond": 83, "cake-chocolate": 84, "cake-marble": 85, "cake-oblong": 86, "cake-salted": 87, "cantonese-fried-rice": 88, "capers": 89, "cappuccino": 90, "caprese-salad-tomato-mozzarella": 91, "carrot-cake": 92, "carrot-raw": 93, "carrot-steamed-without-addition-of-salt": 94, "cashew-nut": 95, "cauliflower": 96, "celeriac": 97, "celery": 98, "cenovis-yeast-spread": 99, "cervelat": 100, "champagne": 101, "cheddar": 102, "cheese": 103, "cheese-for-raclette": 104, "cheesecake": 105, "cherries": 106, "chestnuts": 107, "chia-grains": 108, "chicken": 109, "chicken-breast": 110, "chicken-curry-cream-coconut-milk-curry-spices-paste": 111, "chicken-cut-into-stripes-only-meat": 112, "chicken-leg": 113, "chicken-nuggets": 114, "chicken-wing": 115, "chickpeas": 116, "chili-con-carne-prepared": 117, "chinese-cabbage": 118, "chips-french-fries": 119, "chives": 120, "chocolate": 121, "chocolate-cookies": 122, "chocolate-egg-small": 123, "chocolate-filled": 124, "chocolate-milk-chocolate-drink": 125, "chocolate-mousse": 126, "chorizo": 127, "coca-cola": 128, "coca-cola-zero": 129, "cocktail": 130, "cocoa-powder": 131, "coconut": 132, "coconut-milk": 133, "cod": 134, "coffee-decaffeinated": 135, "coffee-with-caffeine": 136, "coleslaw-chopped-without-sauce": 137, "cooked-sausage": 138, "cookies": 139, "cordon-bleu-from-pork-schnitzel-fried": 140, "coriander": 141, "corn": 142, "corn-crisps": 143, "corn-flakes": 144, "cottage-cheese": 145, "country-fries": 146, "couscous": 147, "crackers": 148, "cream": 149, "cream-cheese": 150, "cream-spinach": 151, "crepe-plain": 152, "crisp-bread-wasa": 153, "crisps": 154, "croissant": 155, "croissant-wholegrain": 156, "croissant-with-chocolate-filling": 157, "croque-monsieur": 158, "croutons": 159, "crunch-muesli": 160, "cucumber": 161, "cucumber-pickled": 162, "curd": 163, "curds-natural-with-at-most-10-fidm": 164, "curry-vegetarian": 165, "dairy-ice-cream": 166, "damson-plum": 167, "dark-chocolate": 168, "dates": 169, "dips": 170, "dough-puff-pastry-shortcrust-bread-pizza-dough": 171, "dried-meat": 172, "dried-raisins": 173, "dumplings": 174, "ebly": 175, "egg": 176, "egg-scrambled-prepared": 177, "eggplant": 178, "eggplant-caviar": 179, "emmental-cheese": 180, "espresso-with-caffeine": 181, "fajita-bread-only": 182, "falafel-balls": 183, "faux-mage-cashew-vegan-chers": 184, "fennel": 185, "feta": 186, "fig-dried": 187, "figs": 188, "fish": 189, "fish-crunchies-battered": 190, "fish-fingers-breaded": 191, "flakes-oat": 192, "focaccia": 193, "fondue": 194, "french-beans": 195, "french-pizza-from-alsace-baked": 196, "french-salad-dressing": 197, "fresh-cheese": 198, "fruit-compotes": 199, "fruit-coulis": 200, "fruit-salad": 201, "fruit-tart": 202, "frying-sausage": 203, "garlic": 204, "glucose-drink-50g": 205, "gluten-free-bread": 206, "goat-average-raw": 207, "goat-cheese-soft": 208, "grapefruit-pomelo": 209, "grapes": 210, "greek-salad": 211, "greek-yaourt-yahourt-yogourt-ou-yoghourt": 212, "green-asparagus": 213, "green-bean-steamed-without-addition-of-salt": 214, "green-olives": 215, "grissini": 216, "grits-polenta-maize-flour": 217, "gruyere": 218, "guacamole": 219, "gummi-bears-fruit-jellies-jelly-babies-with-fruit-essence": 220, "halloumi": 221, "ham": 222, "ham-cooked": 223, "ham-croissant": 224, "ham-raw": 225, "ham-turkey": 226, "hamburger": 227, "hamburger-bread-meat-ketchup": 228, "hamburger-bun": 229, "hard-cheese": 230, "hazelnut": 231, "hazelnut-chocolate-spread-nutella-ovomaltine-caotina": 232, "herbal-tea": 233, "high-protein-pasta-made-of-lentils-peas": 234, "honey": 235, "hummus": 236, "ice-cubes": 237, "ice-tea": 238, "italian-salad-dressing": 239, "jam": 240, "juice-apple": 241, "juice-multifruit": 242, "juice-orange": 243, "kaki": 244, "kebab-in-pita-bread": 245, "kefir-drink": 246, "ketchup": 247, "kiwi": 248, "kolhrabi": 249, "lamb": 250, "lamb-chop": 251, "lasagne-meat-prepared": 252, "lasagne-vegetable-prepared": 253, "latte-macchiato-with-caffeine": 254, "leaf-spinach": 255, "leek": 256, "lemon": 257, "lemon-cake": 258, "lemon-pie": 259, "lentils": 260, "lentils-green-du-puy-du-berry": 261, "light-beer": 262, "linseeds": 263, "lye-pretzel-soft": 264, "m-m-s": 265, "macaroon": 266, "mandarine": 267, "mango": 268, "mango-dried": 269, "maple-syrup-concentrate": 270, "margarine": 271, "mashed-potatoes-prepared-with-full-fat-milk-with-butter": 272, "mayonnaise": 273, "meat": 274, "meat-balls": 275, "meat-terrine-pate": 276, "meatloaf": 277, "meringue": 278, "milk": 279, "milk-chocolate": 280, "milk-chocolate-with-hazelnuts": 281, "minced-meat": 282, "mix-of-dried-fruits-and-nuts": 283, "mixed-nuts": 284, "mixed-salad-chopped-without-sauce": 285, "mixed-seeds": 286, "mixed-vegetables": 287, "mousse": 288, "mozzarella": 289, "muesli": 290, "muffin": 291, "mungbean-sprouts": 292, "mushroom": 293, "mushroom-average-stewed-without-addition-of-fat-without-addition-of-salt": 294, "mushrooms": 295, "mustard": 296, "mustard-dijon": 297, "naan-indien-bread": 298, "nectarine": 299, "nuts": 300, "oat-milk": 301, "oil": 302, "oil-vinegar-salad-dressing": 303, "omelette-plain": 304, "onion": 305, "orange": 306, "pancakes": 307, "panna-cotta": 308, "paprika-chips": 309, "parmesan": 310, "parsley": 311, "pasta": 312, "pasta-hornli": 313, "pasta-in-butterfly-form-farfalle": 314, "pasta-in-conch-form": 315, "pasta-linguini-parpadelle-tagliatelle": 316, "pasta-noodles": 317, "pasta-penne": 318, "pasta-ravioli-stuffing": 319, "pasta-spaghetti": 320, "pasta-tortelloni-stuffing": 321, "pasta-twist": 322, "pasta-wholemeal": 323, "pastry-flaky": 324, "peach": 325, "peanut": 326, "peanut-butter": 327, "pear": 328, "pearl-onions": 329, "peas": 330, "pecan-nut": 331, "perch-fillets-lake": 332, "philadelphia": 333, "pie-apricot-baked-with-cake-dough": 334, "pie-plum-baked-with-cake-dough": 335, "pie-rhubarb-baked-with-cake-dough": 336, "pine-nuts": 337, "pineapple": 338, "pistachio": 339, "pizza-margherita-baked": 340, "pizza-with-ham-baked": 341, "pizza-with-ham-with-mushrooms-baked": 342, "pizza-with-vegetables-baked": 343, "plums": 344, "pomegranate": 345, "popcorn-salted": 346, "pork": 347, "pork-chop": 348, "pork-escalope": 349, "pork-roast": 350, "porridge-prepared-with-partially-skimmed-milk": 351, "potato-gnocchi": 352, "potato-salad-with-mayonnaise-yogurt-dressing": 353, "potatoes-au-gratin-dauphinois-prepared": 354, "potatoes-steamed": 355, "praline": 356, "processed-cheese": 357, "processed-meat-charcuterie": 358, "prosecco": 359, "pumpkin": 360, "pumpkin-seeds": 361, "quiche-with-cheese-baked-with-puff-pastry": 362, "quiche-with-spinach-baked-with-cake-dough": 363, "quinoa": 364, "raspberries": 365, "ratatouille": 366, "red-cabbage": 367, "red-radish": 368, "rice": 369, "rice-basmati": 370, "rice-jasmin": 371, "rice-noodles-vermicelli": 372, "rice-waffels": 373, "rice-whole-grain": 374, "rice-wild": 375, "risotto-with-mushrooms-cooked": 376, "risotto-without-cheese-cooked": 377, "ristretto-with-caffeine": 378, "roll-of-half-white-or-white-flour-with-large-void": 379, "roll-with-pieces-of-chocolate": 380, "romanesco": 381, "rosti": 382, "rusk-wholemeal": 383, "salad-dressing": 384, "salad-lambs-ear": 385, "salad-leaf-salad-green": 386, "salad-rocket": 387, "salami": 388, "salmon": 389, "salmon-smoked": 390, "salt-cake-vegetables-filled": 391, "sandwich-ham-cheese-and-butter": 392, "sauce-carbonara": 393, "sauce-cocktail": 394, "sauce-cream": 395, "sauce-curry": 396, "sauce-mushroom": 397, "sauce-pesto": 398, "sauce-roast": 399, "sauce-savoury": 400, "sauce-soya": 401, "sauce-sweet-salted-asian": 402, "sauce-sweet-sour": 403, "sauerkraut": 404, "sausage": 405, "savoury-puff-pastry": 406, "savoury-puff-pastry-stick": 407, "savoy-cabbage-steamed-without-addition-of-salt": 408, "seeds": 409, "sekt": 410, "semi-hard-cheese": 411, "sesame-seeds": 412, "shoots": 413, "shrimp-boiled": 414, "shrimp-prawn-large": 415, "shrimp-prawn-small": 416, "smoked-cooked-sausage-of-pork-and-beef-meat-sausag": 417, "smoothie": 418, "soft-cheese": 419, "sorbet": 420, "soup-cream-of-vegetables": 421, "soup-miso": 422, "soup-of-lentils-dahl-dhal": 423, "soup-potato": 424, "soup-pumpkin": 425, "soup-tomato": 426, "soup-vegetable": 427, "sour-cream": 428, "soya-drink-soy-milk": 429, "soya-yaourt-yahourt-yogourt-ou-yoghourt": 430, "spaetzle": 431, "spinach-raw": 432, "spinach-steamed-without-addition-of-salt": 433, "spring-onion-scallion": 434, "spring-roll-fried": 435, "strawberries": 436, "sugar-glazing": 437, "sugar-melon": 438, "sun-dried-tomatoe": 439, "sunflower-seeds": 440, "sushi": 441, "sweet-corn-canned": 442, "sweet-potato": 443, "sweets-candies": 444, "swiss-chard": 445, "syrup-diluted-ready-to-drink": 446, "taboule-prepared-with-couscous": 447, "tart": 448, "tartar-meat": 449, "tartar-sauce": 450, "tea": 451, "tea-black": 452, "tea-fruit": 453, "tea-ginger": 454, "tea-green": 455, "tea-peppermint": 456, "tea-rooibos": 457, "tea-spice": 458, "tea-verveine": 459, "tete-de-moine": 460, "thickened-cream-35": 461, "tiramisu": 462, "tofu": 463, "tomato-raw": 464, "tomato-sauce": 465, "tomato-stewed-without-addition-of-fat-without-addition-of-salt": 466, "tomme": 467, "tuna": 468, "tuna-in-oil-drained": 469, "turnover-with-meat-small-meat-pie-empanadas": 470, "tzatziki": 471, "vanille-cream-cooked-custard-creme-dessert": 472, "veal-sausage": 473, "vegetable-au-gratin-baked": 474, "vegetable-mix-peas-and-carrots": 475, "vegetables": 476, "veggie-burger": 477, "waffle": 478, "walnut": 479, "water": 480, "water-mineral": 481, "water-with-lemon-juice": 482, "watermelon-fresh": 483, "white-asparagus": 484, "white-bread-with-butter-eggs-and-milk": 485, "white-cabbage": 486, "white-chocolate": 487, "white-coffee-with-caffeine": 488, "white-radish": 489, "wienerli-swiss-sausage": 490, "wine-red": 491, "wine-rose": 492, "wine-white": 493, "witloof-chicory": 494, "yaourt-yahourt-yogourt-ou-yoghourt-natural": 495, "zucchini": 496, "zucchini-stewed-without-addition-of-fat-without-addition-of-salt": 497} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import torch | ||
import torchvision.models as models | ||
from torch import nn | ||
from data_images import num_classes | ||
|
||
model = models.resnet18(pretrained=True) | ||
|
||
|
||
num_features = model.fc.in_features | ||
model.fc = nn.Linear(num_features, num_classes) | ||
|
||
|
||
for param in model.parameters(): | ||
param.requires_grad = False | ||
for param in model.fc.parameters(): | ||
param.requires_grad = True | ||
|
||
print(model) | ||
|
||
|
||
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') | ||
model = model.to(device) |
Oops, something went wrong.