yuxuanw8 commited on
Commit
35d3f85
·
verified ·
1 Parent(s): ea62193

Update BigEarthNet.py

Browse files
Files changed (1) hide show
  1. BigEarthNet.py +7 -4
BigEarthNet.py CHANGED
@@ -2,6 +2,7 @@ import os
2
  import json
3
  import shutil
4
  import string
 
5
  import tifffile
6
  import datasets
7
 
@@ -185,8 +186,7 @@ class BigEarthNetDataset(datasets.GeneratorBasedBuilder):
185
  try:
186
  downloaded_files = dl_manager.download(self.DATA_URL)
187
  print(f"downloaded files: {downloaded_files}")
188
- # combined_file = os.path.join(dl_manager.download_config.cache_dir, "combined.tar.gz")
189
- combined_file = os.path.join(dl_manager.downloaded_dir, "combined.tar.gz")
190
  print(f"copying files to {combined_file}")
191
  target_dir = os.path.dirname(combined_file)
192
  os.makedirs(target_dir, exist_ok=True) # Create only the directory
@@ -198,8 +198,11 @@ class BigEarthNetDataset(datasets.GeneratorBasedBuilder):
198
  shutil.copyfileobj(infile, outfile)
199
  counter += 1
200
  print(f"extacting from {combined_file}")
201
- data_dir = dl_manager.extract(combined_file)
202
- # data_dir = extract(combined_file)
 
 
 
203
  os.remove(combined_file)
204
  print(f"data_dir: {data_dir}")
205
  except Exception as e:
 
2
  import json
3
  import shutil
4
  import string
5
+ import tarfile
6
  import tifffile
7
  import datasets
8
 
 
186
  try:
187
  downloaded_files = dl_manager.download(self.DATA_URL)
188
  print(f"downloaded files: {downloaded_files}")
189
+ combined_file = os.path.join(dl_manager.download_config.cache_dir, "combined.tar.gz")
 
190
  print(f"copying files to {combined_file}")
191
  target_dir = os.path.dirname(combined_file)
192
  os.makedirs(target_dir, exist_ok=True) # Create only the directory
 
198
  shutil.copyfileobj(infile, outfile)
199
  counter += 1
200
  print(f"extacting from {combined_file}")
201
+ # data_dir = dl_manager.extract(combined_file)
202
+ data_dir = os.path.join(dl_manager.download_config.cache_dir, "extracted")
203
+ os.makedirs(extracted_dir, exist_ok=True)
204
+ with tarfile.open(combined_file, "r:gz") as tar:
205
+ tar.extractall(path=data_dir)
206
  os.remove(combined_file)
207
  print(f"data_dir: {data_dir}")
208
  except Exception as e: