Documentation ¶
Overview ¶
Package tfgo simplifies the usage of the Tensorflow's go bindings wrapping the most common methods as methods of new and logically separated objects. These objects handle the naming issues (that could happen when describing a tf.Graph) in a transparent way. Also, additional features are added. Why this package is required is explained in this blog post: https://pgaleone.eu/tensorflow/go/2017/05/29/understanding-tensorflow-using-go/
Index ¶
- func Batchify(scope *op.Scope, tensors []tf.Output) tf.Output
- func Cast(scope *op.Scope, value tf.Output, dtype tf.DataType) tf.Output
- func Const(scope *op.Scope, value interface{}) tf.Output
- func Exec(scope *op.Scope, tensors []tf.Output, feedDict map[tf.Output]*tf.Tensor, ...) []*tf.Tensor
- func IsClose(scope *op.Scope, a, b tf.Output, relTol, absTol tf.Output) tf.Output
- func IsFloat(dtype tf.DataType) bool
- func IsInteger(dtype tf.DataType) bool
- func MaxValue(dtype tf.DataType) float64
- func MinValue(dtype tf.DataType) float64
- func NewRoot() *op.Scope
- func NewScope(root *op.Scope) *op.Scope
- type Model
- type Tensor
- func (tensor *Tensor) Add(tfout tf.Output) *Tensor
- func (tensor *Tensor) Cast(dtype tf.DataType) *Tensor
- func (tensor *Tensor) Check()
- func (tensor *Tensor) Clone() *Tensor
- func (tensor *Tensor) Dtype() tf.DataType
- func (tensor *Tensor) MatMul(tfout tf.Output) *Tensor
- func (tensor *Tensor) Mul(tfout tf.Output) *Tensor
- func (tensor *Tensor) Pow(y tf.Output) *Tensor
- func (tensor *Tensor) Scope() *op.Scope
- func (tensor *Tensor) Shape32(firstDimension bool) []int32
- func (tensor *Tensor) Shape64(firstDimension bool) []int64
- func (tensor *Tensor) Sqrt() *Tensor
- func (tensor *Tensor) Square() *Tensor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Exec ¶
func Exec(scope *op.Scope, tensors []tf.Output, feedDict map[tf.Output]*tf.Tensor, options *tf.SessionOptions) []*tf.Tensor
Exec creates the computation graph from the scope, then executes the operations required to compute each element of tensors. Node in the graph can be overwritten with feedDict. The session options can be specified using the session parameter. Returns the evaluated tensors. Panics on error.
func IsClose ¶
IsClose defines the isclose operation between a and b. Returns a conditional node that is true when a is close to b. relTol is the relative tolerance absTol is the absolute tolerance
Types ¶
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model represents a trained model
func ImportModel ¶
func ImportModel(serializedModel, prefix string, options *tf.SessionOptions) (model *Model)
ImportModel creates a new *Model, loading the graph from the serialized representation. This operation creates a session with specified `options` Panics if the model can't be loaded
func LoadModel ¶
func LoadModel(exportDir string, tags []string, options *tf.SessionOptions) (model *Model)
LoadModel creates a new *Model, loading it from the exportDir. The graph loaded is identified by the set of tags specified when exporting it. This operation creates a session with specified `options` Panics if the model can't be loaded
func (*Model) Exec ¶
func (model *Model) Exec(tensors []tf.Output, feedDict map[tf.Output]*tf.Tensor) (results []*tf.Tensor)
Exec executes the nodes/tensors that must be present in the loaded model feedDict values to feed to placeholders (that must have been saved in the model definition) panics on error
type Tensor ¶
type Tensor struct { // Root: Each tensor maintains a pointer to the graph root Root *op.Scope // Path is the current Tensor full path Path *op.Scope // Output is the Tensor content Output tf.Output }
Tensor is an high level abstraction for the tf.Output structure, associating a scope to the Tensor
func NewTensor ¶
NewTensor creates a *Tensor from a tf.Output Place the cloned tensor within the specified scope
func (*Tensor) Add ¶
Add defines the add operation between the tensor and tfout `tfout` dtype is converted to tensor.Dtype() before adding
func (*Tensor) Check ¶
func (tensor *Tensor) Check()
Check checks if the previous operation caused an error and thus tensor.Path.Err is not nil. If it's not, panics because we're defining the graph in a wrong way
func (*Tensor) Clone ¶
Clone returns a copy of the current tensor in a new scope Clone is used to create a different tensor from the output of an operation. The new node is placed at the same level of the current tensor it can be seen as a twin tensor
func (*Tensor) MatMul ¶
MatMul defines the matrix multiplication operation between the tensor and `tfout`. `tfout` dtype is converted to tensor.Dtype() before multiplying
func (*Tensor) Mul ¶
Mul defines the multiplication operation between the tensor and `tfout`. It's the multiplication element-wise with broadcasting support. `tfout` dtype is converted to tensor.Dtype() before multiplying
func (*Tensor) Pow ¶
Pow defines the pow operation x^y, where x are the tensor values y dtype is converted to tensor.Dtype() before executing Pow
func (*Tensor) Shape32 ¶
Shape32 returns the shape of the tensor as []int32. If firstDimension is true a 4 elements slice is returned. Otherwise a 3 elements slice is returned.
func (*Tensor) Shape64 ¶
Shape64 returns the shape of the tensor as []int64. If firstDimension is true a 4 elements slice is returned. Otherwise a 3 elements slice is returned.