polinaeterna HF staff commited on
Commit
48069eb
1 Parent(s): afbf9c4

add script

Browse files
Files changed (1) hide show
  1. test_verifications.py +297 -0
test_verifications.py ADDED
@@ -0,0 +1,297 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 requests
12
+
13
+ import pandas as pd
14
+
15
+ from datasets.tasks import ImageClassification
16
+
17
+ # Print datasets version
18
+ print(f"Datasets version: {datasets.__version__}")
19
+
20
+ # Set verbosity to 10
21
+ datasets.logging.set_verbosity(10)
22
+ print(f"Verbosity level: {datasets.logging.get_verbosity()}")
23
+
24
+ _HOMEPAGE = "https://www.nutrify.app"
25
+ _LICENSE = "TODO"
26
+ _CITATION = "TODO"
27
+ _DESCRIPTION = "Images of 199 food classes from the Nutrify app."
28
+
29
+ # # Download class_names.txt and read it
30
+ # url = "https://huggingface.co/datasets/mrdbourke/food_vision_199_classes/blob/main/class_names.txt"
31
+ # r = requests.get(url, allow_redirects=True)
32
+ # open("class_names.txt", "wb").write(r.content)
33
+ # with open("class_names.txt", "r") as f:
34
+ # _NAMES = f.read().splitlines()
35
+
36
+ # Create list of class names
37
+ _NAMES = ['almond_butter',
38
+ 'almonds',
39
+ 'apple',
40
+ 'apricot',
41
+ 'asparagus',
42
+ 'avocado',
43
+ 'bacon',
44
+ 'bacon_and_egg_burger',
45
+ 'bagel',
46
+ 'baklava',
47
+ 'banana',
48
+ 'banana_bread',
49
+ 'barbecue_sauce',
50
+ 'beans',
51
+ 'beef',
52
+ 'beef_curry',
53
+ 'beef_mince',
54
+ 'beef_stir_fry',
55
+ 'beer',
56
+ 'beetroot',
57
+ 'biltong',
58
+ 'blackberries',
59
+ 'blueberries',
60
+ 'bok_choy',
61
+ 'bread',
62
+ 'broccoli',
63
+ 'broccolini',
64
+ 'brownie',
65
+ 'brussel_sprouts',
66
+ 'burrito',
67
+ 'butter',
68
+ 'cabbage',
69
+ 'calamari',
70
+ 'candy',
71
+ 'capsicum',
72
+ 'carrot',
73
+ 'cashews',
74
+ 'cauliflower',
75
+ 'celery',
76
+ 'cheese',
77
+ 'cheeseburger',
78
+ 'cherries',
79
+ 'chicken_breast',
80
+ 'chicken_thighs',
81
+ 'chicken_wings',
82
+ 'chilli',
83
+ 'chimichurri',
84
+ 'chocolate',
85
+ 'chocolate_cake',
86
+ 'coconut',
87
+ 'coffee',
88
+ 'coleslaw',
89
+ 'cookies',
90
+ 'coriander',
91
+ 'corn',
92
+ 'corn_chips',
93
+ 'cream',
94
+ 'croissant',
95
+ 'crumbed_chicken',
96
+ 'cucumber',
97
+ 'cupcake',
98
+ 'daikon_radish',
99
+ 'dates',
100
+ 'donuts',
101
+ 'dragonfruit',
102
+ 'eggplant',
103
+ 'eggs',
104
+ 'enoki_mushroom',
105
+ 'fennel',
106
+ 'figs',
107
+ 'french_toast',
108
+ 'fried_rice',
109
+ 'fries',
110
+ 'fruit_juice',
111
+ 'garlic',
112
+ 'garlic_bread',
113
+ 'ginger',
114
+ 'goji_berries',
115
+ 'granola',
116
+ 'grapefruit',
117
+ 'grapes',
118
+ 'green_beans',
119
+ 'green_onion',
120
+ 'guacamole',
121
+ 'guava',
122
+ 'gyoza',
123
+ 'ham',
124
+ 'honey',
125
+ 'hot_chocolate',
126
+ 'ice_coffee',
127
+ 'ice_cream',
128
+ 'iceberg_lettuce',
129
+ 'jerusalem_artichoke',
130
+ 'kale',
131
+ 'karaage_chicken',
132
+ 'kimchi',
133
+ 'kiwi_fruit',
134
+ 'lamb_chops',
135
+ 'leek',
136
+ 'lemon',
137
+ 'lentils',
138
+ 'lettuce',
139
+ 'lime',
140
+ 'mandarin',
141
+ 'mango',
142
+ 'maple_syrup',
143
+ 'mashed_potato',
144
+ 'mayonnaise',
145
+ 'milk',
146
+ 'miso_soup',
147
+ 'mushrooms',
148
+ 'nectarines',
149
+ 'noodles',
150
+ 'nuts',
151
+ 'olive_oil',
152
+ 'olives',
153
+ 'omelette',
154
+ 'onion',
155
+ 'orange',
156
+ 'orange_juice',
157
+ 'oysters',
158
+ 'pain_au_chocolat',
159
+ 'pancakes',
160
+ 'papaya',
161
+ 'parsley',
162
+ 'parsnips',
163
+ 'passionfruit',
164
+ 'pasta',
165
+ 'pawpaw',
166
+ 'peach',
167
+ 'pear',
168
+ 'peas',
169
+ 'pickles',
170
+ 'pineapple',
171
+ 'pizza',
172
+ 'plum',
173
+ 'pomegranate',
174
+ 'popcorn',
175
+ 'pork_belly',
176
+ 'pork_chop',
177
+ 'pork_loins',
178
+ 'porridge',
179
+ 'potato_bake',
180
+ 'potato_chips',
181
+ 'potato_scallop',
182
+ 'potatoes',
183
+ 'prawns',
184
+ 'pumpkin',
185
+ 'radish',
186
+ 'ramen',
187
+ 'raspberries',
188
+ 'red_onion',
189
+ 'red_wine',
190
+ 'rhubarb',
191
+ 'rice',
192
+ 'roast_beef',
193
+ 'roast_pork',
194
+ 'roast_potatoes',
195
+ 'rockmelon',
196
+ 'rosemary',
197
+ 'salad',
198
+ 'salami',
199
+ 'salmon',
200
+ 'salsa',
201
+ 'salt',
202
+ 'sandwich',
203
+ 'sardines',
204
+ 'sausage_roll',
205
+ 'sausages',
206
+ 'scrambled_eggs',
207
+ 'seaweed',
208
+ 'shallots',
209
+ 'snow_peas',
210
+ 'soda',
211
+ 'soy_sauce',
212
+ 'spaghetti_bolognese',
213
+ 'spinach',
214
+ 'sports_drink',
215
+ 'squash',
216
+ 'starfruit',
217
+ 'steak',
218
+ 'strawberries',
219
+ 'sushi',
220
+ 'sweet_potato',
221
+ 'tacos',
222
+ 'tamarillo',
223
+ 'taro',
224
+ 'tea',
225
+ 'toast',
226
+ 'tofu',
227
+ 'tomato',
228
+ 'tomato_chutney',
229
+ 'tomato_sauce',
230
+ 'turnip',
231
+ 'watermelon',
232
+ 'white_onion',
233
+ 'white_wine',
234
+ 'yoghurt',
235
+ 'zucchini']
236
+
237
+ # Create Food199 class
238
+ class Food199(datasets.GeneratorBasedBuilder):
239
+ """Food199 Images dataset"""
240
+
241
+ def _info(self):
242
+ return datasets.DatasetInfo(
243
+ description=_DESCRIPTION,
244
+ features=datasets.Features(
245
+ {
246
+ "image": datasets.Image(),
247
+ "label": datasets.ClassLabel(names=_NAMES)
248
+ }
249
+ ),
250
+ supervised_keys=("image", "label"),
251
+ homepage=_HOMEPAGE,
252
+ citation=_CITATION,
253
+ license=_LICENSE
254
+ )
255
+
256
+ def _split_generators(self, dl_manager):
257
+ """
258
+ This function returns the logic to split the dataset into different splits as well as labels.
259
+ """
260
+ annotations_csv = dl_manager.download("https://huggingface.co/datasets/mrdbourke/food_vision_199_classes/raw/main/annotations_with_links.csv")
261
+ print(annotations_csv)
262
+
263
+ return [
264
+ datasets.SplitGenerator(
265
+ name=datasets.Split.TRAIN,
266
+ gen_kwargs={
267
+ "annotations": annotations_csv,
268
+ "split": "train"
269
+ }
270
+ ),
271
+ # datasets.SplitGenerator(
272
+ # name=datasets.Split.TEST,
273
+ # gen_kwargs={
274
+ # "annotations": annotations_csv,
275
+ # "split": "test"
276
+ # }
277
+ # )
278
+ ]
279
+
280
+ def _generate_examples(self, annotations, split):
281
+ """
282
+ This function takes in the kwargs from the _split_generators method and can then yield information from them.
283
+ """
284
+ annotations_df = pd.read_csv(annotations, low_memory=False)
285
+
286
+ if split == "train":
287
+ annotations = annotations_df[["image", "label"]][annotations_df["split"] == "train"].to_dict(orient="records")
288
+ elif split == "test":
289
+ annotations = annotations_df[["image", "label"]][annotations_df["split"] == "test"].to_dict(orient="records")
290
+
291
+ for id_, row in enumerate(annotations):
292
+ # print(row["image"])
293
+ row["image"] = str(row.pop("image"))
294
+ row["label"] = row.pop("label")
295
+ # print(id_, row)
296
+ yield id_, row
297
+