tensorflow-0.1.0.0: TensorFlow bindings.

Safe HaskellNone
LanguageHaskell2010

TensorFlow.Core

Contents

Description

The core functionality of TensorFlow.

Unless you are defining ops, you do not need to import other modules from this package.

Basic ops are provided in the tensorflow-ops and tensorflow-core-ops packages.

Synopsis

Session

data Options Source

Customization for session. Use the lenses to update: sessionTarget, sessionTracer, sessionConfig.

sessionConfig :: Lens' Options ConfigProto Source

Uses the specified config for the created session.

sessionTarget :: Lens' Options ByteString Source

Target can be: "local", ip:port, host:port. The set of supported factories depends on the linked in libraries.

sessionTracer :: Lens' Options Tracer Source

Uses the given logger to monitor session progress.

runSession :: Session a -> IO a Source

Run Session actions in a new TensorFlow session.

runSessionWithOptions :: Options -> Session a -> IO a Source

Run Session actions in a new TensorFlow session created with the given option setter actions (sessionTarget, sessionConfig).

Building graphs

build :: Build a -> Session a Source

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

buildAnd :: (a -> Session b) -> Build a -> Session b Source

Helper combinator for doing something with the result of a Build action. Example usage:

buildAnd run :: Fetchable t a => Build t -> Session a

buildWithSummary :: forall a. Build a -> Session (a, [SummaryTensor]) Source

Lift a Build action into a Session, including any explicit op renderings. Returns the merged summary ops which can be used for logging, see build for a convenient wrapper.

Running graphs

class Nodes t => Fetchable t a Source

Types that tensor representations (e.g. Tensor, ControlNode) can be fetched into.

Includes collections of tensors (e.g. tuples).

Minimal complete definition

getFetch

Instances

(~) * a () => Fetchable ControlNode a Source 
Fetchable t a => Fetchable [t] [a] Source 
(TensorType a, (~) * a a') => Fetchable (Tensor v a) (Scalar a') Source 
(TensorType a, (~) * a a') => Fetchable (Tensor v a) (Vector a') Source 
(Fetchable t1 a1, Fetchable t2 a2) => Fetchable (t1, t2) (a1, a2) Source 
(Fetchable t1 a1, Fetchable t2 a2, Fetchable t3 a3) => Fetchable (t1, t2, t3) (a1, a2, a3) Source 

newtype Scalar a Source

Constructors

Scalar 

Fields

unScalar :: a
 

Instances

class Nodes t Source

Types that contain ops which can be run.

Minimal complete definition

getNodes

Instances

Nodes ControlNode Source 
Nodes t => Nodes [t] Source 
(Nodes t1, Nodes t2) => Nodes (t1, t2) Source 
Nodes (Tensor v a) Source 
(Nodes t1, Nodes t2, Nodes t3) => Nodes (t1, t2, t3) Source 

run :: Fetchable t a => t -> Session a Source

Run a subgraph t, rendering any dependent nodes that aren't already rendered, and fetch the corresponding values for a.

run_ :: Nodes t => t -> Session () Source

Run a subgraph t, rendering and extending any dependent nodes that aren't already rendered. This behaves like run except that it doesn't do any fetches.

data Feed Source

A pair of a Tensor and some data that should be fed into that Tensor when running the graph.

feed :: Tensor v a -> TensorData a -> Feed Source

Create a Feed for feeding the given data into a Tensor when running the graph.

Note that if a Tensor is rendered, its identity may change; so feeding the rendered Tensor may be different than feeding the original Tensor.

runWithFeeds :: Fetchable t a => [Feed] -> t -> Session a Source

Run a subgraph t, rendering any dependent nodes that aren't already rendered, feed the given input values, and fetch the corresponding result values for a.

runWithFeeds_ :: Nodes t => [Feed] -> t -> Session () Source

Run a subgraph t, rendering any dependent nodes that aren't already rendered, feed the given input values, and fetch the corresponding result values for a. This behaves like runWithFeeds except that it doesn't do any fetches.

Async

asyncProdNodes Source

Arguments

:: Nodes t 
=> t

Node to evaluate concurrently.

-> Session () 

Starts a concurrent thread which evaluates the given Nodes forever until runSession exits or an exception occurs. Graph extension happens synchronously, but the resultant run proceeds as a separate thread.

Build

type Build = BuildT Identity Source

An action for building nodes in a TensorFlow graph.

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.

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.

asGraphDef :: Build a -> GraphDef Source

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

Tensor

data ControlNode Source

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

data Tensor v a Source

A named output of a TensorFlow operation.

The type parameter a is the type of the elements in the Tensor. The parameter v is either Value or Ref, depending on whether the graph is treating this op output as an immutable Value or a stateful Ref (e.g., a variable). Note that a Tensor Ref can be casted into a Tensor Value via value.

Instances

data TensorKind v where Source

This class provides a runtime switch on whether a Tensor should be treated as a Value or as a Ref.

tensorAttr :: Attribute attr => Text -> Traversal' (Tensor v a) attr Source

Lens for the attributes of a tensor.

Only valid if the tensor has not yet been rendered. If the tensor has been rendered, the traversal will be over nothing (nothing can be read or written).

value :: Tensor v a -> Tensor Value a Source

Cast a 'Tensor *' into a 'Tensor Value'. Common usage is to cast a Ref into Value. This behaves like a no-op.

tensorFromName :: TensorKind v -> Text -> Tensor v a Source

Create a Tensor for a given name. This can be used to reference nodes in a GraphDef that was loaded via addGraphDef. TODO(judahjacobson): add more safety checks here.

Element types

data TensorData a Source

Data about a tensor that is encoded for the TensorFlow APIs.

class TensorType a where Source

The class of scalar types supported by tensorflow.

Methods

decodeTensorData :: TensorData a -> Vector a Source

Decode the bytes of a TensorData into a Vector.

encodeTensorData :: Shape -> Vector a -> TensorData a Source

Encode a Vector into a TensorData.

The values should be in row major order, e.g.,

element 0: index (0, ..., 0) element 1: index (0, ..., 1) ...

newtype Shape Source

Shape (dimensions) of a tensor.

Constructors

Shape [Int64] 

type OneOf ts a = (TensorType a, TensorTypes ts, NoneOf (AllTensorTypes \\ ts) a) Source

A Constraint specifying the possible choices of a TensorType.

We implement a Constraint like OneOf '[Double, Float] a by turning the natural representation as a conjunction, i.e.,

   a == Double || a == Float

into a disjunction like

    a /= Int32 && a /= Int64 && a /= ByteString && ...

using an enumeration of all the possible TensorTypes.

type family a /= b :: Constraint Source

A constraint checking that two types are different.

Equations

a /= a = TypeError a ~ ExcludedCase 
a /= b = () 

Op combinators

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.

newtype Device Source

A device that a node can be assigned to. There's a naming convention where the device names are constructed from job and replica names.

Constructors

Device 

Fields

deviceName :: Text
 

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.

named :: TensorType a => Text -> Tensor v a -> Tensor v a Source

Returns a Tensor with a given name and the same shape and contents as the input.

TODO(judahjacobson): This breaks when used with uninitialize Tensor Refs, since RefIdentity doesn't have SetAllowsUninitializedInput(). Look into whether we can change that op.

Dependencies

withControlDependencies :: Nodes t => t -> Build a -> Build a Source

Modify a Build action, such that all new ops rendered in it will depend on the nodes in the first argument.

group :: Nodes t => t -> Build ControlNode Source

Create an op that groups multiple operations.

When this op finishes, all ops in the input n have finished. This op has no output.

Misc

identity :: TensorType a => Tensor v a -> Tensor v a Source

Returns a Tensor with the same shape and contents as the input.

noOp :: ControlNode Source

Does nothing. Only useful as a placeholder for control edges.