Syoy commited on
Commit
435bb2e
1 Parent(s): 6d0378c

streaming embeddings

Browse files
Files changed (1) hide show
  1. dcase23-task2-enriched.py +9 -2
dcase23-task2-enriched.py CHANGED
@@ -5,6 +5,8 @@ import datasets.info
5
  import pandas as pd
6
  import numpy as np
7
  import tempfile
 
 
8
  from pathlib import Path
9
  from datasets import load_dataset
10
  from typing import Iterable, Dict, Optional, Union, List
@@ -395,10 +397,15 @@ class DCASE2023Task2Dataset(datasets.GeneratorBasedBuilder):
395
  audio_path[split] = dl_manager.download(self.config.data_urls[split])
396
  local_extracted_archive[split] = dl_manager.extract(
397
  audio_path[split]) if not dl_manager.is_streaming else None
398
- if self.config.embeddings_urls is not None and not dl_manager.is_streaming:
399
  for emb_name, emb_data in self.config.embeddings_urls.items():
400
  downloaded_embeddings = dl_manager.download(emb_data[split])
401
- embeddings[split][emb_name] = np.load(downloaded_embeddings, allow_pickle=True)["arr_0"].item()
 
 
 
 
 
402
 
403
  return [
404
  datasets.SplitGenerator(
 
5
  import pandas as pd
6
  import numpy as np
7
  import tempfile
8
+ import requests
9
+ import io
10
  from pathlib import Path
11
  from datasets import load_dataset
12
  from typing import Iterable, Dict, Optional, Union, List
 
397
  audio_path[split] = dl_manager.download(self.config.data_urls[split])
398
  local_extracted_archive[split] = dl_manager.extract(
399
  audio_path[split]) if not dl_manager.is_streaming else None
400
+ if self.config.embeddings_urls is not None:
401
  for emb_name, emb_data in self.config.embeddings_urls.items():
402
  downloaded_embeddings = dl_manager.download(emb_data[split])
403
+ if dl_manager.is_streaming:
404
+ response = requests.get(downloaded_embeddings)
405
+ response.raise_for_status()
406
+ downloaded_embeddings = io.BytesIO(response.content)
407
+ npz_file = np.load(downloaded_embeddings, allow_pickle=True)
408
+ embeddings[split][emb_name] = npz_file["arr_0"].item()
409
 
410
  return [
411
  datasets.SplitGenerator(