mrdbourke commited on
Commit
2a92119
1 Parent(s): c960079

add dataset loading scripts

Browse files
Files changed (2) hide show
  1. class_names.txt +199 -0
  2. food_vision_199_classes.py +71 -0
class_names.txt ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ almond_butter
2
+ almonds
3
+ apple
4
+ apricot
5
+ asparagus
6
+ avocado
7
+ bacon
8
+ bacon_and_egg_burger
9
+ bagel
10
+ baklava
11
+ banana
12
+ banana_bread
13
+ barbecue_sauce
14
+ beans
15
+ beef
16
+ beef_curry
17
+ beef_mince
18
+ beef_stir_fry
19
+ beer
20
+ beetroot
21
+ biltong
22
+ blackberries
23
+ blueberries
24
+ bok_choy
25
+ bread
26
+ broccoli
27
+ broccolini
28
+ brownie
29
+ brussel_sprouts
30
+ burrito
31
+ butter
32
+ cabbage
33
+ calamari
34
+ candy
35
+ capsicum
36
+ carrot
37
+ cashews
38
+ cauliflower
39
+ celery
40
+ cheese
41
+ cheeseburger
42
+ cherries
43
+ chicken_breast
44
+ chicken_thighs
45
+ chicken_wings
46
+ chilli
47
+ chimichurri
48
+ chocolate
49
+ chocolate_cake
50
+ coconut
51
+ coffee
52
+ coleslaw
53
+ cookies
54
+ coriander
55
+ corn
56
+ corn_chips
57
+ cream
58
+ croissant
59
+ crumbed_chicken
60
+ cucumber
61
+ cupcake
62
+ daikon_radish
63
+ dates
64
+ donuts
65
+ dragonfruit
66
+ eggplant
67
+ eggs
68
+ enoki_mushroom
69
+ fennel
70
+ figs
71
+ french_toast
72
+ fried_rice
73
+ fries
74
+ fruit_juice
75
+ garlic
76
+ garlic_bread
77
+ ginger
78
+ goji_berries
79
+ granola
80
+ grapefruit
81
+ grapes
82
+ green_beans
83
+ green_onion
84
+ guacamole
85
+ guava
86
+ gyoza
87
+ ham
88
+ honey
89
+ hot_chocolate
90
+ ice_coffee
91
+ ice_cream
92
+ iceberg_lettuce
93
+ jerusalem_artichoke
94
+ kale
95
+ karaage_chicken
96
+ kimchi
97
+ kiwi_fruit
98
+ lamb_chops
99
+ leek
100
+ lemon
101
+ lentils
102
+ lettuce
103
+ lime
104
+ mandarin
105
+ mango
106
+ maple_syrup
107
+ mashed_potato
108
+ mayonnaise
109
+ milk
110
+ miso_soup
111
+ mushrooms
112
+ nectarines
113
+ noodles
114
+ nuts
115
+ olive_oil
116
+ olives
117
+ omelette
118
+ onion
119
+ orange
120
+ orange_juice
121
+ oysters
122
+ pain_au_chocolat
123
+ pancakes
124
+ papaya
125
+ parsley
126
+ parsnips
127
+ passionfruit
128
+ pasta
129
+ pawpaw
130
+ peach
131
+ pear
132
+ peas
133
+ pickles
134
+ pineapple
135
+ pizza
136
+ plum
137
+ pomegranate
138
+ popcorn
139
+ pork_belly
140
+ pork_chop
141
+ pork_loins
142
+ porridge
143
+ potato_bake
144
+ potato_chips
145
+ potato_scallop
146
+ potatoes
147
+ prawns
148
+ pumpkin
149
+ radish
150
+ ramen
151
+ raspberries
152
+ red_onion
153
+ red_wine
154
+ rhubarb
155
+ rice
156
+ roast_beef
157
+ roast_pork
158
+ roast_potatoes
159
+ rockmelon
160
+ rosemary
161
+ salad
162
+ salami
163
+ salmon
164
+ salsa
165
+ salt
166
+ sandwich
167
+ sardines
168
+ sausage_roll
169
+ sausages
170
+ scrambled_eggs
171
+ seaweed
172
+ shallots
173
+ snow_peas
174
+ soda
175
+ soy_sauce
176
+ spaghetti_bolognese
177
+ spinach
178
+ sports_drink
179
+ squash
180
+ starfruit
181
+ steak
182
+ strawberries
183
+ sushi
184
+ sweet_potato
185
+ tacos
186
+ tamarillo
187
+ taro
188
+ tea
189
+ toast
190
+ tofu
191
+ tomato
192
+ tomato_chutney
193
+ tomato_sauce
194
+ turnip
195
+ watermelon
196
+ white_onion
197
+ white_wine
198
+ yoghurt
199
+ zucchini
food_vision_199_classes.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Loading script for the Food Vision 199 classes dataset.
3
+
4
+ See the template: https://github.com/huggingface/datasets/blob/main/templates/new_dataset_script.py
5
+ See the example for Food101: https://huggingface.co/datasets/food101/blob/main/food101.py
6
+ See another example: https://huggingface.co/datasets/davanstrien/encyclopedia_britannica/blob/main/encyclopedia_britannica.py
7
+ """
8
+
9
+ import datasets
10
+ import os
11
+ import pandas as pd
12
+
13
+ from datasets.tasks import ImageClassification
14
+
15
+ _HOMEPAGE = "https://www.nutrify.app"
16
+ _LICENSE = "TODO"
17
+ _CITATION = "TODO"
18
+ _DESCRIPTION = "Images of 199 food classes from the Nutrify app."
19
+
20
+ # Read lines of class_names.txt
21
+ with open("class_names.txt", "r") as f:
22
+ _NAMES = f.read().splitlines()
23
+
24
+ class Food199(datasets.GeneratorBasedBuilder):
25
+ """Food199 Images dataset"""
26
+
27
+ def _info(self):
28
+ return datasets.DatasetInfo(
29
+ description=_DESCRIPTION,
30
+ features=datasets.Features(
31
+ {
32
+ "image": datasets.Image(),
33
+ "label": datasets.ClassLabel(names=_NAMES)
34
+ }
35
+ ),
36
+ supervised_keys=("image", "label"),
37
+ homepage=_HOMEPAGE,
38
+ citation=_CITATION,
39
+ license=_LICENSE,
40
+ task_templates=[ImageClassification(image_column="image", label_column="label")],
41
+ )
42
+
43
+ def _split_generators(self, dl_manager):
44
+ """
45
+ This function returns the logic to split the dataset into different splits as well as labels.
46
+ """
47
+ csv = dl_manager.download("annotations.csv")
48
+ df = pd.read_csv(csv)
49
+ df_train_annotations = df[df["split"] == "train"].to_dict(orient="records")
50
+ df_test_annotations = df[df["split"] == "test"].to_dict(orient="records")
51
+
52
+ return [
53
+ datasets.SplitGenerator(name=datasets.Split.TRAIN,
54
+ gen_kwargs={
55
+ "annotations": df_train_annotations,
56
+ }),
57
+ datasets.SplitGenerator(name=datasets.Split.TEST,
58
+ gen_kwargs={
59
+ "annotations": df_test_annotations,
60
+ })]
61
+
62
+
63
+ def _generate_examples(self, annotations):
64
+ """
65
+ This function takes in the kwargs from the _split_generators method and can then yield information from them.
66
+ """
67
+ for id_, row in enumerate(annotations):
68
+ row["image"] = row.pop("filename")
69
+ row["label"] = row.pop("label")
70
+ yield id_, row
71
+