Class: TorchAudio::Datasets::YESNO

Inherits:
Torch::Utils::Data::Dataset
  • Object
show all
Defined in:
lib/torchaudio/datasets/yesno.rb

Constant Summary collapse

URL =
"http://www.openslr.org/resources/1/waves_yesno.tar.gz"
FOLDER_IN_ARCHIVE =
"waves_yesno"
CHECKSUMS =
{
  "http://www.openslr.org/resources/1/waves_yesno.tar.gz" => "962ff6e904d2df1126132ecec6978786"
}

Instance Method Summary collapse

Constructor Details

#initialize(root, url: URL, folder_in_archive: FOLDER_IN_ARCHIVE, download: false) ⇒ YESNO

Returns a new instance of YESNO.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/torchaudio/datasets/yesno.rb', line 10

def initialize(root, url: URL, folder_in_archive: FOLDER_IN_ARCHIVE, download: false)
  archive = File.basename(url)
  archive = File.join(root, archive)
  @path = File.join(root, folder_in_archive)

  if download
    unless Dir.exist?(@path)
      unless File.exist?(archive)
        checksum = CHECKSUMS.fetch(url)
        Utils.download_url(url, root, hash_value: checksum, hash_type: "md5")
      end
      Utils.extract_archive(archive)
    end
  end

  unless Dir.exist?(@path)
    raise "Dataset not found. Please use `download: true` to download it."
  end

  walker = Utils.walk_files(@path, ext_audio, prefix: false, remove_suffix: true)
  @walker = walker.to_a
end

Instance Method Details

#[](n) ⇒ Object



33
34
35
36
# File 'lib/torchaudio/datasets/yesno.rb', line 33

def [](n)
  fileid = @walker[n]
  load_yesno_item(fileid, @path, ext_audio)
end

#lengthObject Also known as: size



38
39
40
# File 'lib/torchaudio/datasets/yesno.rb', line 38

def length
  @walker.length
end