SmartEngine  1.6.0
Classes | Public Member Functions | Static Public Member Functions | Properties | List of all members
SmartEngine.NeuralNetworks.Graph Class Reference

A graph is a collection of buffers and nodes that together form a neural network. The graph is created from a json definition file. After creation, the contents of the graph can be loaded from or saved to disk. More...

Inheritance diagram for SmartEngine.NeuralNetworks.Graph:
SmartEngine.Resource SmartEngine.Object SmartEngine.ISerializable SmartEngine.Disposable

Classes

class  CInfo
 Constructor info More...
 

Public Member Functions

 Graph (CInfo cinfo)
 
Context GetContext ()
 Returns the context associated with the graph More...
 
Graph DeepCopy ()
 Copies the internal structure of the graph into a new graph More...
 
Graph Instance ()
 Creates a copy of this graph with all internal weights referenced to this graph. More...
 
unsafe void BindComponentInputs (ComponentInputBinding[] bindings)
 Binds the component inputs in the graph to the specified set of nodes. Any component inputs not included will be bound to buffer inputs. More...
 
void CopyWeightsFrom (Graph graph, float percent=1.0f)
 Copies the neuron layer weights from the specified graph into this graph. The specified graph must have the same exact structure as this graph. More...
 
void SetRandomWeights ()
 Initialize the weights of all trainable layers to random values. More...
 
GetNode< T > (string name)
 Returns the specified node as the specified type. Null is returned if the node is not found or is of a different type. More...
 
GraphNode GetOutputNode (int index)
 Returns an output node of the graph as a GraphNode. The nodes are ordered in the appearance in the graph definition or the order they were added manually. More...
 
void AddNode (GraphNode node)
 Adds a node to the graph. This will be considered an output node until a node connecting to this one is added to the graph. More...
 
float GetWeightStandardDeviation ()
 Returns the average standard deviation of all trainable weights in the graph. More...
 
void ResetNeuronLayers ()
 Calls Reset() on all trainable layers in the graph. This is only necessary for LSTM neuron layers. More...
 
void StepNeuronLayers (bool autoReset=true)
 Calls Step() on all trainable layers in the graph. This is only necessary for LSTM neuron layers. More...
 
- Public Member Functions inherited from SmartEngine.Resource
SerializationResult Load (string appendName=null)
 Load this object from disk. More...
 
SerializationResult Save (string appendName=null)
 Save this object to disk. More...
 
SerializationResult Serialize (MemoryBuffer buffer)
 Write the contents of this object to a buffer. More...
 
SerializationResult Serialize (out byte[] data)
 Write the contents of this object to a byte array. More...
 
SerializationResult Deserialize (MemoryBuffer buffer)
 Fill this object with contents from a buffer. More...
 
SerializationResult Deserialize (byte[] data)
 Fill this object with contents from a byte array. More...
 
- Public Member Functions inherited from SmartEngine.Object
void AddRef ()
 Increments the internal reference count on this object. It is not common to use this method directly. More...
 
void Release ()
 Decrements the internal reference count on this object. It is not common to use this method directly. More...
 
- Public Member Functions inherited from SmartEngine.Disposable
void Dispose ()
 Cleans up any internal state. It is not safe to use an object after it has been disposed. More...
 

Static Public Member Functions

static Graph CreateFromDefinitionString (CInfo cinfo, string graphDefinition)
 Creates a new graph from a graph definition json string More...
 
static Graph CreateFromResource (CInfo cinfo, string resourceName=null)
 Creates and loads a new Graph from a resource. More...
 

Properties

string Name [get]
 Returns the name of the graph. More...
 
int SequenceLength [get, set]
 Gets or sets the desired sequence length for this graph. This is after how many steps the graph should be reset. Only applicable to graphs that need to be stepped (such as LSTMs). More...
 
- Properties inherited from SmartEngine.Resource
string ResourceName [get]
 Returns the name of this resource passed to the constructor. More...
 
SerializationResult LastLoadResult [get]
 Returns the result of the last call to Load(). Useful for checking loaded data state after creation. More...
 

Detailed Description

A graph is a collection of buffers and nodes that together form a neural network. The graph is created from a json definition file. After creation, the contents of the graph can be loaded from or saved to disk.

When loading from a resource, two assets will try to load. One will be the resourceName + "Definition", which should be a json text asset. The other will be resourceName + "Data", which will be the graph data. The definition is required, but the data can be missing on creation.

Member Function Documentation

◆ AddNode()

void SmartEngine.NeuralNetworks.Graph.AddNode ( GraphNode  node)

Adds a node to the graph. This will be considered an output node until a node connecting to this one is added to the graph.

Parameters
node

◆ BindComponentInputs()

unsafe void SmartEngine.NeuralNetworks.Graph.BindComponentInputs ( ComponentInputBinding[]  bindings)

Binds the component inputs in the graph to the specified set of nodes. Any component inputs not included will be bound to buffer inputs.

This should only be called once before first evaluation. It is not necessary to call this if the graph is used as a graph component or added as a standard graph model to a graph manager.

Called automatically by IGraphComponent upon creation.

Any created buffer inputs will have the name "[Comp Input Name]Buffer" and will be added to the graph. (Ex: "MyCompInput" would have a buffer "MyCompInputBuffer" that can be queried through normal means)

Parameters
bindings
bindingCount

◆ CopyWeightsFrom()

void SmartEngine.NeuralNetworks.Graph.CopyWeightsFrom ( Graph  graph,
float  percent = 1.0f 
)

Copies the neuron layer weights from the specified graph into this graph. The specified graph must have the same exact structure as this graph.

Parameters
graph

◆ CreateFromDefinitionString()

static Graph SmartEngine.NeuralNetworks.Graph.CreateFromDefinitionString ( CInfo  cinfo,
string  graphDefinition 
)
static

Creates a new graph from a graph definition json string

Parameters
cinfo
graphDefinition
Returns

◆ CreateFromResource()

static Graph SmartEngine.NeuralNetworks.Graph.CreateFromResource ( CInfo  cinfo,
string  resourceName = null 
)
static

Creates and loads a new Graph from a resource.

Parameters
cinfo
folder
name
Returns

◆ DeepCopy()

Graph SmartEngine.NeuralNetworks.Graph.DeepCopy ( )

Copies the internal structure of the graph into a new graph

Returns

◆ GetContext()

Context SmartEngine.NeuralNetworks.Graph.GetContext ( )

Returns the context associated with the graph

Returns

◆ GetNode< T >()

T SmartEngine.NeuralNetworks.Graph.GetNode< T > ( string  name)

Returns the specified node as the specified type. Null is returned if the node is not found or is of a different type.

Template Parameters
T
Parameters
name
Returns
Type Constraints
T :GraphNode 

◆ GetOutputNode()

GraphNode SmartEngine.NeuralNetworks.Graph.GetOutputNode ( int  index)

Returns an output node of the graph as a GraphNode. The nodes are ordered in the appearance in the graph definition or the order they were added manually.

Parameters
index
Returns

◆ GetWeightStandardDeviation()

float SmartEngine.NeuralNetworks.Graph.GetWeightStandardDeviation ( )

Returns the average standard deviation of all trainable weights in the graph.

Returns

◆ Instance()

Graph SmartEngine.NeuralNetworks.Graph.Instance ( )

Creates a copy of this graph with all internal weights referenced to this graph.

◆ ResetNeuronLayers()

void SmartEngine.NeuralNetworks.Graph.ResetNeuronLayers ( )

Calls Reset() on all trainable layers in the graph. This is only necessary for LSTM neuron layers.

◆ SetRandomWeights()

void SmartEngine.NeuralNetworks.Graph.SetRandomWeights ( )

Initialize the weights of all trainable layers to random values.

◆ StepNeuronLayers()

void SmartEngine.NeuralNetworks.Graph.StepNeuronLayers ( bool  autoReset = true)

Calls Step() on all trainable layers in the graph. This is only necessary for LSTM neuron layers.

Parameters
autoResetIf true, ResetNeuronLayers() will automatically be called periodically based on the sequence length.

Property Documentation

◆ Name

string SmartEngine.NeuralNetworks.Graph.Name
get

Returns the name of the graph.

◆ SequenceLength

int SmartEngine.NeuralNetworks.Graph.SequenceLength
getset

Gets or sets the desired sequence length for this graph. This is after how many steps the graph should be reset. Only applicable to graphs that need to be stepped (such as LSTMs).