Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -350,4 +350,7 @@ MigrationBackup/
.ionide/
dist/
.DS_Store
._*
._*

venv/
root_path/
26 changes: 23 additions & 3 deletions examples/esc50_dataset.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from torch.utils.data import Dataset
from torchvision.datasets.utils import download_url
from tqdm import tqdm
from pathlib import Path
import pandas as pd
import os
import torch.nn as nn
Expand Down Expand Up @@ -74,9 +74,29 @@ def __len__(self):
return len(self.audio_paths)

def download(self):
download_url(self.url, self.root, self.filename)
# Download file using requests
import requests
file = Path(self.root) / self.filename
if file.is_file():
return

r = requests.get(self.url, stream=True)

# extract file
# To prevent partial downloads, download to a temp file first
tmp = file.with_suffix('.tmp')
tmp.parent.mkdir(parents=True, exist_ok=True)
with open(tmp, 'wb') as f:
pbar = tqdm(unit=" MB", bar_format=f'{file.name}: {{rate_noinv_fmt}}')

for chunk in r.iter_content(chunk_size=1024):
if chunk:
pbar.update(len(chunk) / 1024 / 1024)
f.write(chunk)

# move temp file to correct location
tmp.rename(file)

# # extract file
from zipfile import ZipFile
with ZipFile(os.path.join(self.root, self.filename), 'r') as zip:
zip.extractall(path=self.root)
Loading