tensorflow-0.1.0.0: TensorFlow bindings.

Safe HaskellNone
LanguageHaskell2010

TensorFlow.Build

Contents

Synopsis

Graph node types

newtype ControlNode Source

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
 

Ops

The Build monad

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

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 Source

Render a Tensor and get its node's name.

data BuildT m a Source

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

type Build = BuildT Identity Source

An action for building nodes in a TensorFlow graph.

addInitializer :: ControlNode -> Build () Source

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

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

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

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

asGraphDef :: Build a -> GraphDef Source

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

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

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

flushNodeBuffer :: Monad m => BuildT m [NodeDef] Source

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

Creating and looking up Ops

getOrAddOp :: Op -> Build NodeName Source

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

addNewOp :: OpDef -> Build NodeDef Source

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 Source

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 Source

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 Source

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 Source

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 Source

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

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

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

Internal Summary related bits.

addSummary :: SummaryTensor -> Build () Source

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 Source

Synonym for the tensors that return serialized Summary proto.

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

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