mrdbourke commited on
Commit
0670536
1 Parent(s): 80df377

add food vision script

Browse files
Files changed (1) hide show
  1. food_vision_199_classes.py +28 -17
food_vision_199_classes.py CHANGED
@@ -14,6 +14,10 @@ import pandas as pd
14
 
15
  from datasets.tasks import ImageClassification
16
 
 
 
 
 
17
  _HOMEPAGE = "https://www.nutrify.app"
18
  _LICENSE = "TODO"
19
  _CITATION = "TODO"
@@ -250,34 +254,41 @@ class Food199(datasets.GeneratorBasedBuilder):
250
  """
251
  This function returns the logic to split the dataset into different splits as well as labels.
252
  """
253
- csv = dl_manager.download("annotations_with_links.csv")
254
- df = pd.read_csv(csv, low_memory=False)
255
- # print("Downloaded annotations.csv")
256
- df_train_annotations = df[["image", "label"]][df["split"] == "train"].to_dict(orient="records")
257
- # print(df_train_annotations[:5])
258
- df_test_annotations = df[["image", "label"]][df["split"] == "test"].to_dict(orient="records")
259
 
260
  return [
261
  datasets.SplitGenerator(
262
  name=datasets.Split.TRAIN,
263
  gen_kwargs={
264
- "annotations": df_train_annotations,
265
- }),
266
- # datasets.SplitGenerator(
267
- # name=datasets.Split.TEST,
268
- # gen_kwargs={
269
- # "annotations": df_test_annotations,
270
- # })
271
- ]
272
-
 
 
 
273
 
274
- def _generate_examples(self, annotations):
275
  """
276
  This function takes in the kwargs from the _split_generators method and can then yield information from them.
277
  """
 
 
 
 
 
 
 
278
  for id_, row in enumerate(annotations):
 
279
  row["image"] = str(row.pop("image"))
280
  row["label"] = row.pop("label")
281
- print(id_, row)
282
  yield id_, row
283
 
 
14
 
15
  from datasets.tasks import ImageClassification
16
 
17
+ # Set verbosity to 10
18
+ datasets.logging.set_verbosity(10)
19
+ print(f"Verbosity level: {datasets.logging.get_verbosity()}")
20
+
21
  _HOMEPAGE = "https://www.nutrify.app"
22
  _LICENSE = "TODO"
23
  _CITATION = "TODO"
 
254
  """
255
  This function returns the logic to split the dataset into different splits as well as labels.
256
  """
257
+ annotations_csv = dl_manager.download("annotations_with_links.csv")
258
+ print(annotations_csv)
 
 
 
 
259
 
260
  return [
261
  datasets.SplitGenerator(
262
  name=datasets.Split.TRAIN,
263
  gen_kwargs={
264
+ "annotations": annotations_csv,
265
+ "split": "train"
266
+ }
267
+ ),
268
+ # datasets.SplitGenerator(
269
+ # name=datasets.Split.TEST,
270
+ # gen_kwargs={
271
+ # "annotations": annotations_csv,
272
+ # "split": "test"
273
+ # }
274
+ # )
275
+ ]
276
 
277
+ def _generate_examples(self, annotations, split):
278
  """
279
  This function takes in the kwargs from the _split_generators method and can then yield information from them.
280
  """
281
+ annotations_df = pd.read_csv(annotations, low_memory=False)
282
+
283
+ if split == "train":
284
+ annotations = annotations_df[["image", "label"]][annotations_df["split"] == "train"].to_dict(orient="records")
285
+ elif split == "test":
286
+ annotations = annotations_df[["image", "label"]][annotations_df["split"] == "test"].to_dict(orient="records")
287
+
288
  for id_, row in enumerate(annotations):
289
+ # print(row["image"])
290
  row["image"] = str(row.pop("image"))
291
  row["label"] = row.pop("label")
292
+ # print(id_, row)
293
  yield id_, row
294