util

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArgMax

func ArgMax(s []float32) (int, float32, error)

ArgMax find both index of max value in s and max value.

func CloseFile

func CloseFile(file io.Closer) error

func CopyFile added in v0.3.2

func CopyFile(from string, to string) error

func CreateFile added in v0.3.2

func CreateFile(fileName string, isDir bool) error

func DeleteFile added in v0.3.2

func DeleteFile(filename string) error

func FileExists added in v0.3.2

func FileExists(filename string) (bool, error)

func GetPathType

func GetPathType(path string) string

func LoadImagesFromPaths added in v0.5.0

func LoadImagesFromPaths(paths []string) ([]image.Image, error)

func Mean

func Mean(vector []float32) float32

Mean of a float32 vector.

func NewFileWriter added in v0.3.2

func NewFileWriter(filename string, contentType string) (io.WriteCloser, error)

func Norm

func Norm(v []float32, p int) float64

Norm of a vector.

func Normalize

func Normalize(embedding []float32, p int) []float32

Normalize single vector according to: https://pytorch.org/docs/stable/generated/torch.nn.functional.normalize.html

func OpenFile added in v0.3.0

func OpenFile(filename string) (io.ReadCloser, error)

func PathJoinSafe

func PathJoinSafe(elem ...string) string

PathJoinSafe wrapper around filepath.Join to ensure that paths are correctly constructed if the path is a normal OS path, just use filepath.Join if the path is S3, trim any trailing slashes and construct it manually from the components so that double slashes (e.g. s3://) are preserved.

func ReadFileBytes

func ReadFileBytes(filename string) ([]byte, error)

func ReadLine added in v0.3.0

func ReadLine(r *bufio.Reader) ([]byte, error)

ReadLine returns a single line (without the ending \n) from the input buffered reader. An error is returned if there is an error with the buffered reader. This function is needed to avoid the 65K char line limit

func Sigmoid

func Sigmoid(s []float32) []float32

func SoftMax

func SoftMax(vector []float32) []float32

SoftMax take a vector and calculate softmax scores of its values.

func SumSlice

func SumSlice(s []float64) float64

func WalkDir added in v0.3.2

func WalkDir() func(ctx context.Context, URL string, handler storage.OnVisit, options ...storage.Option) error

Types

type CenterCropPreprocessor added in v0.5.0

type CenterCropPreprocessor struct {
	// contains filtered or unexported fields
}

func CenterCropStep added in v0.5.0

func CenterCropStep(targetWidth, targetHeight int) *CenterCropPreprocessor

func (*CenterCropPreprocessor) Apply added in v0.5.0

type NormalizationStep added in v0.5.0

type NormalizationStep interface {
	Apply(r, g, b float32) (float32, float32, float32)
}

type PixelNormalizationPreprocessor added in v0.5.0

type PixelNormalizationPreprocessor struct {
	// contains filtered or unexported fields
}

func ImagenetPixelNormalizationStep added in v0.5.0

func ImagenetPixelNormalizationStep() *PixelNormalizationPreprocessor

func PixelNormalizationStep added in v0.5.0

func PixelNormalizationStep(mean, std [3]float32) *PixelNormalizationPreprocessor

func (*PixelNormalizationPreprocessor) Apply added in v0.5.0

type PreprocessStep added in v0.5.0

type PreprocessStep interface {
	Apply(img image.Image) (image.Image, error)
}

type RescalePreprocessor added in v0.5.0

type RescalePreprocessor struct{}

func RescaleStep added in v0.5.0

func RescaleStep() *RescalePreprocessor

func (*RescalePreprocessor) Apply added in v0.5.0

func (s *RescalePreprocessor) Apply(r, g, b float32) (float32, float32, float32)

type ResizePreprocessor added in v0.5.0

type ResizePreprocessor struct {
	// contains filtered or unexported fields
}

func ResizeStep added in v0.5.0

func ResizeStep(targetSize int) *ResizePreprocessor

func (*ResizePreprocessor) Apply added in v0.5.0

func (s *ResizePreprocessor) Apply(img image.Image) (image.Image, error)

Jump to

Keyboard shortcuts

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