tensorflow-0.1.0.0: TensorFlow bindings.

Safe HaskellNone
LanguageHaskell2010

TensorFlow.Build

Contents

Synopsis

Graph node types

newtype ControlNode

A type of graph node which has no outputs. These nodes are valuable for causing side effects when they are run.

Constructors

ControlNode 

data Unique

Instances

Ops

opAttr :: Attribute a => Text -> Lens' OpDef a

opInputs :: Lens' OpDef [Output]

The Build monad

data GraphState

Instances

Monad m => MonadState GraphState (BuildT m) 

data BuildT m a

An action for building nodes in a TensorFlow graph. Used to manage build state internally as part of the Session monad.

Instances

MonadTrans BuildT 
TensorKind Build 
Monad m => MonadState GraphState (BuildT m) 
Monad m => Monad (BuildT m) 
Functor m => Functor (BuildT m) 
Monad m => Applicative (BuildT m) 
MonadIO m => MonadIO (BuildT m) 
MonadThrow m => MonadThrow (BuildT m) 
MonadMask m => MonadMask (BuildT m) 
MonadCatch m => MonadCatch (BuildT m) 
Monad m => MonadBuild (BuildT m) 
TensorTypes as => PureResult (TensorList Build as) 
PureResult (Tensor Build a) 

type Build = BuildT Identity

An action for building nodes in a TensorFlow graph.

class Monad m => MonadBuild m where

Lift a Build action into a monad, including any explicit op renderings.

Methods

build :: Build a -> m a

addInitializer :: MonadBuild m => ControlNode -> m ()

Registers the given node to be executed before the next run.

hoistBuildT :: (forall a. m a -> n a) -> BuildT m b -> BuildT n b

This is Control.Monad.Morph.hoist sans the dependency.

evalBuildT :: Monad m => BuildT m a -> m a

runBuildT :: BuildT m a -> m (a, GraphState)

asGraphDef :: Build a -> GraphDef

Produce a GraphDef proto representation of the nodes that are rendered in the given Build action.

flushInitializers :: Monad m => BuildT m [NodeName]

Get all the initializers that have accumulated so far, and clear that buffer.

flushNodeBuffer :: MonadBuild m => m [NodeDef]

Get all the NodeDefs that have accumulated so far, and clear that buffer.

Creating and looking up Ops

getOrAddOp :: OpDef -> Build NodeName

Render the given op if it hasn't been rendered already, and return its name.

addNewOp :: OpDef -> Build NodeName

Add a new node for a given OpDef. This is used for making "stateful" ops which are not safe to dedup (e.g, "variable" and "assign").

encodeOutput :: Output -> Text

Turn an Output into a string representation for the TensorFlow foreign APIs.

Modifying all nodes in a Build action

withStateLens :: MonadBuild m => Lens' GraphState a -> (a -> a) -> m b -> m b

Modify some part of the state, run an action, and restore the state after that action is done.

withDevice :: MonadBuild m => Maybe Device -> m a -> m a

Set a device for all nodes rendered in the given Build action (unless further overridden by another use of withDevice).

withNameScope :: MonadBuild m => Text -> m a -> m a

Prepend a scope to all nodes rendered in the given Build action.

withNodeDependencies :: MonadBuild m => Set NodeName -> m a -> m a

Add control inputs to all nodes rendered in the given Build action.