Ziyuan111 commited on
Commit
8ccdc83
1 Parent(s): eb4d631

Update durhamtrees.py

Browse files
Files changed (1) hide show
  1. durhamtrees.py +1 -43
durhamtrees.py CHANGED
@@ -34,7 +34,7 @@ _URLS = {
34
  "first_domain1": {
35
  "csv_file": "https://drive.google.com/uc?export=download&id=18HmgMbtbntWsvAySoZr4nV1KNu-i7GCy",
36
  "geojson_file": "https://drive.google.com/uc?export=download&id=1cbn7EY7RofXN7c6Ph0eIGFIZowPZ5lKE",
37
- "parquet_file": "https://drive.google.com/uc?export=download&id=1RNDLJLoSSV9RJptVyfWFhPra0nh-i_CN",
38
  },
39
  "first_domain2": {
40
  "csv_file2": "https://drive.google.com/uc?export=download&id=1RVdaI5dSTPStjhOHO40ypDv2cAQZpi_Y",
@@ -63,8 +63,6 @@ class DurhamTrees(GeneratorBasedBuilder):
63
  "OBJECTID": Value("int64"),
64
  "X": Value("float64"),
65
  "Y": Value("float64"),
66
- "image": Value("binary"),
67
- "label": Value("int64"),
68
  "feature1_from_class2": Value("string"),
69
  "streetaddress": Value("string"),
70
  "city": Value("string"),
@@ -139,7 +137,6 @@ class DurhamTrees(GeneratorBasedBuilder):
139
  "class1_data_file": downloaded_files["first_domain1"]["csv_file"],
140
  "class1_geojson_file": downloaded_files["first_domain1"]["geojson_file"],
141
  "class2_data_file": downloaded_files["first_domain2"]["csv_file2"],
142
- "parquet_file": downloaded_files["first_domain1"]["parquet_file"],
143
  "split": Split.TRAIN,
144
  },
145
  ),
@@ -152,9 +149,6 @@ class DurhamTrees(GeneratorBasedBuilder):
152
  class1_examples = list(self._generate_examples_from_class1(class1_data_file, class1_geojson_file))
153
  class2_examples = list(self._generate_examples_from_class2(class2_data_file))
154
 
155
- # Load Parquet file
156
- parquet_data = pq.read_table(parquet_file).to_pandas()
157
- class1_examples += list(self._generate_examples_from_parquet(parquet_data))
158
 
159
  examples = class1_examples + class2_examples
160
  df = pd.DataFrame(examples)
@@ -209,25 +203,6 @@ class DurhamTrees(GeneratorBasedBuilder):
209
  yield id_, example
210
 
211
 
212
- def _generate_examples_from_parquet(self, parquet_data):
213
- for id_, row in parquet_data.iterrows():
214
- # Check if the "image" column is present and not empty
215
- if "image" in row and "bytes" in row["image"]:
216
- # Decode the base64-encoded image bytes
217
- image_data = base64.b64decode(row["image"]["bytes"])
218
- example = {"image": image_data, "label": row["label"]}
219
-
220
- # Display the image
221
- image_bytes = example.get('image', None)
222
- if image_bytes:
223
- img = mpimg.imread(io.BytesIO(image_bytes), format='PNG') # Use 'PNG' instead of 'JPG'
224
- plt.imshow(img)
225
- plt.show()
226
-
227
- yield id_, example
228
- else:
229
- print(f"Skipping example {id_} as it has missing or invalid image data")
230
-
231
 
232
 
233
  def _correlation_analysis(self, df):
@@ -250,14 +225,6 @@ durham_trees_dataset.download_and_prepare()
250
  # Access the dataset
251
  dataset = durham_trees_dataset.as_dataset()
252
 
253
- # Iterate through the dataset and display images
254
- for example in dataset['train']:
255
- if "image" in example and example["image"] is not None and "bytes" in example["image"]:
256
- # Display the image
257
- image_data = base64.b64decode(example["image"]["bytes"])
258
- img = mpimg.imread(io.BytesIO(image_data), format='PNG')
259
- plt.imshow(img)
260
- plt.show()
261
 
262
  # Create an instance of the DurhamTrees class for another configuration
263
  durham_trees_dataset_another = DurhamTrees(name='class2_domain1')
@@ -267,12 +234,3 @@ durham_trees_dataset_another.download_and_prepare()
267
 
268
  # Access the dataset for the new instance
269
  dataset_another = durham_trees_dataset_another.as_dataset()
270
-
271
- # Iterate through the dataset for the new instance and display images
272
- for example in dataset_another['train']:
273
- if "image" in example and example["image"] is not None and "bytes" in example["image"]:
274
- # Display the image
275
- image_data = base64.b64decode(example["image"]["bytes"])
276
- img = mpimg.imread(io.BytesIO(image_data), format='PNG')
277
- plt.imshow(img)
278
- plt.show()
 
34
  "first_domain1": {
35
  "csv_file": "https://drive.google.com/uc?export=download&id=18HmgMbtbntWsvAySoZr4nV1KNu-i7GCy",
36
  "geojson_file": "https://drive.google.com/uc?export=download&id=1cbn7EY7RofXN7c6Ph0eIGFIZowPZ5lKE",
37
+
38
  },
39
  "first_domain2": {
40
  "csv_file2": "https://drive.google.com/uc?export=download&id=1RVdaI5dSTPStjhOHO40ypDv2cAQZpi_Y",
 
63
  "OBJECTID": Value("int64"),
64
  "X": Value("float64"),
65
  "Y": Value("float64"),
 
 
66
  "feature1_from_class2": Value("string"),
67
  "streetaddress": Value("string"),
68
  "city": Value("string"),
 
137
  "class1_data_file": downloaded_files["first_domain1"]["csv_file"],
138
  "class1_geojson_file": downloaded_files["first_domain1"]["geojson_file"],
139
  "class2_data_file": downloaded_files["first_domain2"]["csv_file2"],
 
140
  "split": Split.TRAIN,
141
  },
142
  ),
 
149
  class1_examples = list(self._generate_examples_from_class1(class1_data_file, class1_geojson_file))
150
  class2_examples = list(self._generate_examples_from_class2(class2_data_file))
151
 
 
 
 
152
 
153
  examples = class1_examples + class2_examples
154
  df = pd.DataFrame(examples)
 
203
  yield id_, example
204
 
205
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206
 
207
 
208
  def _correlation_analysis(self, df):
 
225
  # Access the dataset
226
  dataset = durham_trees_dataset.as_dataset()
227
 
 
 
 
 
 
 
 
 
228
 
229
  # Create an instance of the DurhamTrees class for another configuration
230
  durham_trees_dataset_another = DurhamTrees(name='class2_domain1')
 
234
 
235
  # Access the dataset for the new instance
236
  dataset_another = durham_trees_dataset_another.as_dataset()