Ziyuan111 commited on
Commit
8342336
1 Parent(s): 94b0e22

Update plantsdataset.py

Browse files
Files changed (1) hide show
  1. plantsdataset.py +10 -5
plantsdataset.py CHANGED
@@ -6,7 +6,7 @@ Automatically generated by Colaboratory.
6
  Original file is located at
7
  https://colab.research.google.com/drive/1nkvgrtbJQaIBdnxYHl8WTpKVL_AzAzux
8
  """
9
-
10
  import datasets
11
  from datasets import load_dataset, DatasetInfo, Features, Value, ClassLabel, Split, SplitGenerator, GeneratorBasedBuilder, BuilderConfig, Array3D, Version
12
  import os
@@ -34,7 +34,7 @@ import numpy as np
34
  from datasets import DatasetInfo, Features, Value, ClassLabel, Split, SplitGenerator, GeneratorBasedBuilder, BuilderConfig
35
  from datasets import NamedSplit, Split, SplitGenerator
36
  import gdown
37
- _DRIVE_ID = "1fXgVwhdU5YGj0SPIcHxSpxkhvRh54oEH"
38
  _URL = f"https://drive.google.com/uc?export=download&id={_DRIVE_ID}"
39
 
40
  class PlantsDataset(GeneratorBasedBuilder):
@@ -78,19 +78,24 @@ class PlantsDataset(GeneratorBasedBuilder):
78
  label_names = self.info.features['label'].names
79
  for label_name in label_names:
80
  subfolder_path = os.path.join(data_folder, label_name)
 
 
 
81
  label = label_names.index(label_name)
82
  for root, _, files in os.walk(subfolder_path):
 
 
 
83
  for file_name in files:
84
  file_path = os.path.join(root, file_name)
85
  if os.path.isfile(file_path) and file_name.lower().endswith(('.png', '.jpg', '.jpeg')):
86
- # Image ID should be unique, use filename for simplicity
87
  image_id = os.path.splitext(file_name)[0]
88
  yield image_id, {
89
- "image": file_path, # Store file path as a string
90
  "label": label,
91
  }
92
  else:
93
- print(f"Skipped file {file_path}, since it is not an image."
94
  # Instantiate the dataset builder for PlantsDataset
95
  plants_dataset = PlantsDataset()
96
 
 
6
  Original file is located at
7
  https://colab.research.google.com/drive/1nkvgrtbJQaIBdnxYHl8WTpKVL_AzAzux
8
  """
9
+ #https://drive.google.com/file/d/1QOFLMFCQn_RAjWf2Hbc80NZtxS2lOq3h/view?usp=share_link
10
  import datasets
11
  from datasets import load_dataset, DatasetInfo, Features, Value, ClassLabel, Split, SplitGenerator, GeneratorBasedBuilder, BuilderConfig, Array3D, Version
12
  import os
 
34
  from datasets import DatasetInfo, Features, Value, ClassLabel, Split, SplitGenerator, GeneratorBasedBuilder, BuilderConfig
35
  from datasets import NamedSplit, Split, SplitGenerator
36
  import gdown
37
+ _DRIVE_ID = "1QOFLMFCQn_RAjWf2Hbc80NZtxS2lOq3h"
38
  _URL = f"https://drive.google.com/uc?export=download&id={_DRIVE_ID}"
39
 
40
  class PlantsDataset(GeneratorBasedBuilder):
 
78
  label_names = self.info.features['label'].names
79
  for label_name in label_names:
80
  subfolder_path = os.path.join(data_folder, label_name)
81
+ if not os.path.exists(subfolder_path):
82
+ print(f"Expected subfolder does not exist: {subfolder_path}")
83
+ continue
84
  label = label_names.index(label_name)
85
  for root, _, files in os.walk(subfolder_path):
86
+ if not files:
87
+ print(f"No image files found in: {root}")
88
+ continue
89
  for file_name in files:
90
  file_path = os.path.join(root, file_name)
91
  if os.path.isfile(file_path) and file_name.lower().endswith(('.png', '.jpg', '.jpeg')):
 
92
  image_id = os.path.splitext(file_name)[0]
93
  yield image_id, {
94
+ "image": file_path,
95
  "label": label,
96
  }
97
  else:
98
+ print(f"Skipped file {file_path}, since it is not an image.")
99
  # Instantiate the dataset builder for PlantsDataset
100
  plants_dataset = PlantsDataset()
101