model

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package model provides model serialization (save/load) for go-tensorflow, analogous to tf.keras.models.save_model / load_model.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToFloat64

func BytesToFloat64(b [8]byte) float64

BytesToFloat64 converts 8 bytes to a float64.

func Float64ToBytes

func Float64ToBytes(f float64) [8]byte

Float64ToBytes converts a float64 to its 8-byte binary representation.

func LoadWeights

func LoadWeights(path string) ([]float64, error)

LoadWeights reads model weights from a binary file.

func SaveCheckpoint

func SaveCheckpoint(ckpt *Checkpoint, weights []float64, dir string) error

SaveCheckpoint saves a checkpoint to disk.

func SaveConfig

func SaveConfig(config *ModelConfig, path string) error

SaveConfig writes a model configuration to a JSON file.

func SaveModel

func SaveModel(config *ModelConfig, weights []float64, dir string) error

SaveModel saves both config and weights to a directory.

func SaveWeights

func SaveWeights(weights []float64, path string) error

SaveWeights writes model weights to a binary file. Format: [uint64 count][float64 values...]

Types

type Checkpoint

type Checkpoint struct {
	Epoch   int     `json:"epoch"`
	Loss    float64 `json:"loss"`
	Weights string  `json:"weights_file"`
}

Checkpoint saves a training checkpoint with epoch and loss info.

func LoadCheckpoint

func LoadCheckpoint(path string) (*Checkpoint, error)

LoadCheckpoint loads a checkpoint from disk.

type LayerConfig

type LayerConfig struct {
	Type   string         `json:"type"`
	Params map[string]any `json:"params"`
}

LayerConfig describes a single layer's configuration for serialization.

type ModelConfig

type ModelConfig struct {
	Name         string        `json:"name"`
	Version      string        `json:"version"`
	Layers       []LayerConfig `json:"layers"`
	LearningRate float64       `json:"learning_rate,omitempty"`
	LossFunction string        `json:"loss_function,omitempty"`
}

ModelConfig describes the full model architecture for serialization.

func LoadConfig

func LoadConfig(path string) (*ModelConfig, error)

LoadConfig reads a model configuration from a JSON file.

func LoadModel

func LoadModel(dir string) (*ModelConfig, []float64, error)

LoadModel loads both config and weights from a directory.

Jump to

Keyboard shortcuts

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