Skip to content

Commit

Permalink
Merge pull request #41 from hykilpikonna/main
Browse files Browse the repository at this point in the history
Remove torchvision dependency and solve pytorch vulnerability
  • Loading branch information
bmartin1 authored Sep 18, 2024
2 parents 59bc844 + 2614a64 commit e8a6467
Show file tree
Hide file tree
Showing 4 changed files with 1,174 additions and 1,008 deletions.
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

0 comments on commit e8a6467

Please sign in to comment.