data

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2023 License: Apache-2.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package data is a collection of tools that facilitate data loading and preprocessing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Download

func Download(url, path string) (size int64, err error)

Download file from url and save at given path.

func DownloadAndUntarIfMissing

func DownloadAndUntarIfMissing(url, baseDir, tarFile, dataDir, checkHash string) error

DownloadAndUntarIfMissing downloads tarFile from given url, if file not there yet, and then untar it if the target directory is missing.

If checkHash is provided, it checks that the file has the hash or fail.

func DownloadAndUnzipIfMissing

func DownloadAndUnzipIfMissing(url, zipFile, unzipBaseDir, targetUnzipDir, checkHash string) error

DownloadAndUnzipIfMissing downloads zipFile from given url, if file not there yet, and then unzip it under directory `unzipBaseDir`. If the target `targetUnzipDir` directory is missing.

If checkHash is provided, it checks that the file has the hash or fail.

func DownloadIfMissing

func DownloadIfMissing(url, path, checkHash string) error

DownloadIfMissing will check if the path exists already, and if not it will download the file from the given URL.

If checkHash is provided, it checks that the file has the hash or fail.

func FileExists

func FileExists(path string) bool

FileExists returns true if file or directory exists.

func ReplaceTildeInDir

func ReplaceTildeInDir(dir string) string

ReplaceTildeInDir by the user's home directory. Returns dir if it doesn't start with "~".

func Untar

func Untar(baseDir, tarFile string) error

Untar file, using decompression flags according to suffix: .gz for gzip, bz2 for bzip2.

func Unzip

func Unzip(zipFile, zipBaseDir string) error

Unzip file, from the given zipBaseDir.

func ValidateChecksum

func ValidateChecksum(path, checkHash string) error

ValidateChecksum verifies that the checksum of the file in the given path matches the checksum given. If it fails, it will remove the file (!) and return and error.

Types

type ParallelDataset

type ParallelDataset struct {
	Dataset train.Dataset

	// Parallelism is the number of goroutines started generating examples.
	Parallelism int

	// BufferSize is the size of the cache of pre-generated batches.
	BufferSize int
	// contains filtered or unexported fields
}

ParallelDataset is a wrapper around a `train.Dataset` that parallelize calls to Yield.

func NewParallelDataset

func NewParallelDataset(ds train.Dataset, parallelism, bufferSize int) *ParallelDataset

NewParallelDataset starts building a ParallelDataset that can be used to parallelize any train.Dataset, as long as the underlying dataset ds is thread-safe.

parallelism is the number of goroutines to start, each calling `ds.Yield()` in parallel to accelerate the generation of batches. Set to 0, and it will use the number of cores in the system plus 1.

bufferSize is the space reserved to keep pre-generated batches. This is on top of the batches being generated in each goroutine.

To avoid leaking goroutines, call ParallelDataset.Cancel when exiting.

func (*ParallelDataset) Name

func (pd *ParallelDataset) Name() string

Name implements train.Dataset.

func (*ParallelDataset) Reset

func (pd *ParallelDataset) Reset()

Reset implements train.Dataset.

func (*ParallelDataset) Yield

func (pd *ParallelDataset) Yield() (spec any, inputs []tensor.Tensor, labels []tensor.Tensor, err error)

Yield implements train.Dataset.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL