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 

Fields

unControlNode :: Op
 

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) 

render :: Tensor v a -> Build (Tensor v a)

Render a Tensor, fixing its name, scope, device and control inputs from the Build context. Also renders any dependencies of the Tensor that weren't already rendered.

This operation is idempotent; render >=> render === render. However, rendering a (previously un-rendered) Tensor in two different contexts may result in two different Tensors.

renderNodeName :: Tensor v a -> Build NodeName

Render a Tensor and get its node's name.

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 
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) 
OpResult a => BuildOp (Build a) 

type Build = BuildT Identity

An action for building nodes in a TensorFlow graph.

addInitializer :: ControlNode -> Build ()

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 :: Monad m => BuildT m [NodeDef]

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

Creating and looking up Ops

getOrAddOp :: Op -> Build NodeName

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

addNewOp :: OpDef -> Build NodeDef

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").

renderOutput :: Output -> Build Text

Render an Output and return a string representation for the TensorFlow foreign APIs.

Modifying all nodes in a Build action

colocateWith :: forall a v b. Tensor v b -> Build a -> Build a

Places all nodes rendered in the given Build action on the same device as the given Tensor (see also withDevice). Make sure that the action has side effects of rendering the desired tensors. A pure return would not have the desired effect.

withStateLens :: MonadState s m => Lens' s 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 :: Maybe Device -> Build a -> Build a

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

withNameScope :: Text -> Build a -> Build a

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

withNodeDependencies :: Set NodeName -> Build a -> Build a

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

Internal Summary related bits.

addSummary :: SummaryTensor -> Build ()

Records the given summary action in Build for retrieval with collectAllSummaries. The summary op is required to produce a Summary protocol buffer in string form. For safety, use the pre-composed functions: Logging.scalarSummary and Logging.histogramSummary.

type SummaryTensor = Tensor Value ByteString

Synonym for the tensors that return serialized Summary proto.

collectAllSummaries :: Monad m => BuildT m [SummaryTensor]

Retrieves the summary ops collected thus far. Typically this only happens once, but if buildWithSummary is used repeatedly, the values accumulate.