tensorflow 0.0.0




Pub Build status Gitter License

Tensorflow API for the Dart programming language.

The goal of this project is to provide first-class support for machine learning and data science in Dart, a strongly-typed language that runs across all platforms.

This project is still in its early stages, but will grow very quickly.

Installation #

This library uses native bindings, which (currently) are not easily distributed using Dart's Pub package manager.

Building the bindings, however, is easy and quick, as the build uses pre-built Tensorflow binaries, rather than re-building per user.

Prerequisites #

You'll need the following installed to run Tensorflow for Dart:

It's also strongly recommended to install the scripts command-line utility for Dart, which allows you to build the bindings in one step:

$ pub global activate scripts

Ensure that you have the path to Pub's global executables in your PATH environment variable.

On Windows, this is %APPDATA%\Pub\Cache\bin, whereas on UNIX-based systems, it should be ~/.pub-cache/bin.

Building as a Dependency #

If you are using package:tensorflow as a dependency in a Dart project, then you will need to build the native bindings. This process is made simple the tool/build.dart file included with this project.

Using the scripts tool, you can build the bindings in your Pub cache, and they will be available to all Dart projects on your system:

$ scripts get && scripts clean

As an added bonus, the files generated by CMake are cached, which means you likely only ever have to build them once.

Building by Itself #

If you are contributing to the project, you will certainly need to be able to build the project on the fly. Use the provided tool/build.dart script to build the project on-the-fly.

Basic Usage #

Importing Graphs #

This project supports loading and restoring models saved from other Tensorflow frontends, i.e. Python:

import 'package:tensorflow/tensorflow.dart' as tf;

void main() {
  // Using the `SavedModel` API:
  var model = new SavedModelBundle('example/saved_models');
  model.restore('variables.index');
  
  // Or, you can import from a `GraphDef` protocol buffer:
  var graph = new Graph.fromGraphDef(graphDef);
  graph['output'].run(feed: {'input': new Tensor.from('Hello, world!')});
}

Low Level API #

package:tensorflow/tensorflow.dart supports the entire low-level Tensorflow API. This can be used to perform a variety of complex mathematical operations, and also be used to compose higher-level functionality.

import 'package:tensorflow/tensorflow.dart' as tf;

void main() {
    var shape = new tf.Shape(6, 6);
  
    var x = tf.getVariable(
      'x',
      shape: shape,
      initializer: tf.randomUniform(
        tf.constant(shape),
        dtype: tf.DataType.DT_FLOAT,
      ),
    );
  
    x = tf.matMul(x, x);
  
    print(x.run());
}

example/main.dart

import 'package:tensorflow/tensorflow.dart' as tf;

main() {
  var hello = tf.constant('Hello, Tensorflow!');
  var result = hello.run();
  print('Tensorflow version: ${tf.version}');
  print('Result: $result');
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  tensorflow: ^0.0.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:tensorflow/tensorflow.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
25
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
6
Overall:
Weighted score of the above. [more]
14
Learn more about scoring.

We analyzed this package on Jul 13, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms:

Error(s) prevent platform classification:

Fix dependencies in pubspec.yaml.

Analysis issues and suggestions

Fix dependencies in pubspec.yaml.

Running pub upgrade failed with the following output:

ERR: The current Dart SDK version is 2.4.0.
 
 Because tensorflow depends on binary >=0.0.1 which requires SDK version >=1.8.0 <2.0.0, version solving failed.

Health suggestions

Format lib/src/dart/output.dart.

Run dartfmt to format lib/src/dart/output.dart.

Format lib/src/dart/saved_model_bundle.dart.

Run dartfmt to format lib/src/dart/saved_model_bundle.dart.

Format lib/src/proto/allocation_description.pb.dart.

Run dartfmt to format lib/src/proto/allocation_description.pb.dart.

Fix additional 84 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/proto/allocation_description.pbenum.dart (Run dartfmt to format lib/src/proto/allocation_description.pbenum.dart.)
  • lib/src/proto/allocation_description.pbjson.dart (Run dartfmt to format lib/src/proto/allocation_description.pbjson.dart.)
  • lib/src/proto/allocation_description.pbserver.dart (Run dartfmt to format lib/src/proto/allocation_description.pbserver.dart.)
  • lib/src/proto/any.pb.dart (Run dartfmt to format lib/src/proto/any.pb.dart.)
  • lib/src/proto/any.pbenum.dart (Run dartfmt to format lib/src/proto/any.pbenum.dart.)
  • lib/src/proto/any.pbjson.dart (Run dartfmt to format lib/src/proto/any.pbjson.dart.)
  • lib/src/proto/any.pbserver.dart (Run dartfmt to format lib/src/proto/any.pbserver.dart.)
  • lib/src/proto/attr_value.pb.dart (Run dartfmt to format lib/src/proto/attr_value.pb.dart.)
  • lib/src/proto/attr_value.pbenum.dart (Run dartfmt to format lib/src/proto/attr_value.pbenum.dart.)
  • lib/src/proto/attr_value.pbjson.dart (Run dartfmt to format lib/src/proto/attr_value.pbjson.dart.)
  • lib/src/proto/attr_value.pbserver.dart (Run dartfmt to format lib/src/proto/attr_value.pbserver.dart.)
  • lib/src/proto/cluster.pb.dart (Run dartfmt to format lib/src/proto/cluster.pb.dart.)
  • lib/src/proto/cluster.pbenum.dart (Run dartfmt to format lib/src/proto/cluster.pbenum.dart.)
  • lib/src/proto/cluster.pbjson.dart (Run dartfmt to format lib/src/proto/cluster.pbjson.dart.)
  • lib/src/proto/cluster.pbserver.dart (Run dartfmt to format lib/src/proto/cluster.pbserver.dart.)
  • lib/src/proto/config.pb.dart (Run dartfmt to format lib/src/proto/config.pb.dart.)
  • lib/src/proto/config.pbenum.dart (Run dartfmt to format lib/src/proto/config.pbenum.dart.)
  • lib/src/proto/config.pbjson.dart (Run dartfmt to format lib/src/proto/config.pbjson.dart.)
  • lib/src/proto/config.pbserver.dart (Run dartfmt to format lib/src/proto/config.pbserver.dart.)
  • lib/src/proto/cost_graph.pb.dart (Run dartfmt to format lib/src/proto/cost_graph.pb.dart.)
  • lib/src/proto/cost_graph.pbenum.dart (Run dartfmt to format lib/src/proto/cost_graph.pbenum.dart.)
  • lib/src/proto/cost_graph.pbjson.dart (Run dartfmt to format lib/src/proto/cost_graph.pbjson.dart.)
  • lib/src/proto/cost_graph.pbserver.dart (Run dartfmt to format lib/src/proto/cost_graph.pbserver.dart.)
  • lib/src/proto/debug.pb.dart (Run dartfmt to format lib/src/proto/debug.pb.dart.)
  • lib/src/proto/debug.pbenum.dart (Run dartfmt to format lib/src/proto/debug.pbenum.dart.)
  • lib/src/proto/debug.pbjson.dart (Run dartfmt to format lib/src/proto/debug.pbjson.dart.)
  • lib/src/proto/debug.pbserver.dart (Run dartfmt to format lib/src/proto/debug.pbserver.dart.)
  • lib/src/proto/function.pb.dart (Run dartfmt to format lib/src/proto/function.pb.dart.)
  • lib/src/proto/function.pbenum.dart (Run dartfmt to format lib/src/proto/function.pbenum.dart.)
  • lib/src/proto/function.pbjson.dart (Run dartfmt to format lib/src/proto/function.pbjson.dart.)
  • lib/src/proto/function.pbserver.dart (Run dartfmt to format lib/src/proto/function.pbserver.dart.)
  • lib/src/proto/graph.pb.dart (Run dartfmt to format lib/src/proto/graph.pb.dart.)
  • lib/src/proto/graph.pbenum.dart (Run dartfmt to format lib/src/proto/graph.pbenum.dart.)
  • lib/src/proto/graph.pbjson.dart (Run dartfmt to format lib/src/proto/graph.pbjson.dart.)
  • lib/src/proto/graph.pbserver.dart (Run dartfmt to format lib/src/proto/graph.pbserver.dart.)
  • lib/src/proto/meta_graph.pb.dart (Run dartfmt to format lib/src/proto/meta_graph.pb.dart.)
  • lib/src/proto/meta_graph.pbenum.dart (Run dartfmt to format lib/src/proto/meta_graph.pbenum.dart.)
  • lib/src/proto/meta_graph.pbjson.dart (Run dartfmt to format lib/src/proto/meta_graph.pbjson.dart.)
  • lib/src/proto/meta_graph.pbserver.dart (Run dartfmt to format lib/src/proto/meta_graph.pbserver.dart.)
  • lib/src/proto/node_def.pb.dart (Run dartfmt to format lib/src/proto/node_def.pb.dart.)
  • lib/src/proto/node_def.pbenum.dart (Run dartfmt to format lib/src/proto/node_def.pbenum.dart.)
  • lib/src/proto/node_def.pbjson.dart (Run dartfmt to format lib/src/proto/node_def.pbjson.dart.)
  • lib/src/proto/node_def.pbserver.dart (Run dartfmt to format lib/src/proto/node_def.pbserver.dart.)
  • lib/src/proto/op_def.pb.dart (Run dartfmt to format lib/src/proto/op_def.pb.dart.)
  • lib/src/proto/op_def.pbenum.dart (Run dartfmt to format lib/src/proto/op_def.pbenum.dart.)
  • lib/src/proto/op_def.pbjson.dart (Run dartfmt to format lib/src/proto/op_def.pbjson.dart.)
  • lib/src/proto/op_def.pbserver.dart (Run dartfmt to format lib/src/proto/op_def.pbserver.dart.)
  • lib/src/proto/resource_handle.pb.dart (Run dartfmt to format lib/src/proto/resource_handle.pb.dart.)
  • lib/src/proto/resource_handle.pbenum.dart (Run dartfmt to format lib/src/proto/resource_handle.pbenum.dart.)
  • lib/src/proto/resource_handle.pbjson.dart (Run dartfmt to format lib/src/proto/resource_handle.pbjson.dart.)
  • lib/src/proto/resource_handle.pbserver.dart (Run dartfmt to format lib/src/proto/resource_handle.pbserver.dart.)
  • lib/src/proto/rewriter_config.pb.dart (Run dartfmt to format lib/src/proto/rewriter_config.pb.dart.)
  • lib/src/proto/rewriter_config.pbenum.dart (Run dartfmt to format lib/src/proto/rewriter_config.pbenum.dart.)
  • lib/src/proto/rewriter_config.pbjson.dart (Run dartfmt to format lib/src/proto/rewriter_config.pbjson.dart.)
  • lib/src/proto/rewriter_config.pbserver.dart (Run dartfmt to format lib/src/proto/rewriter_config.pbserver.dart.)
  • lib/src/proto/saver.pb.dart (Run dartfmt to format lib/src/proto/saver.pb.dart.)
  • lib/src/proto/saver.pbenum.dart (Run dartfmt to format lib/src/proto/saver.pbenum.dart.)
  • lib/src/proto/saver.pbjson.dart (Run dartfmt to format lib/src/proto/saver.pbjson.dart.)
  • lib/src/proto/saver.pbserver.dart (Run dartfmt to format lib/src/proto/saver.pbserver.dart.)
  • lib/src/proto/step_stats.pb.dart (Run dartfmt to format lib/src/proto/step_stats.pb.dart.)
  • lib/src/proto/step_stats.pbenum.dart (Run dartfmt to format lib/src/proto/step_stats.pbenum.dart.)
  • lib/src/proto/step_stats.pbjson.dart (Run dartfmt to format lib/src/proto/step_stats.pbjson.dart.)
  • lib/src/proto/step_stats.pbserver.dart (Run dartfmt to format lib/src/proto/step_stats.pbserver.dart.)
  • lib/src/proto/tensor.pb.dart (Run dartfmt to format lib/src/proto/tensor.pb.dart.)
  • lib/src/proto/tensor.pbenum.dart (Run dartfmt to format lib/src/proto/tensor.pbenum.dart.)
  • lib/src/proto/tensor.pbjson.dart (Run dartfmt to format lib/src/proto/tensor.pbjson.dart.)
  • lib/src/proto/tensor.pbserver.dart (Run dartfmt to format lib/src/proto/tensor.pbserver.dart.)
  • lib/src/proto/tensor_description.pb.dart (Run dartfmt to format lib/src/proto/tensor_description.pb.dart.)
  • lib/src/proto/tensor_description.pbenum.dart (Run dartfmt to format lib/src/proto/tensor_description.pbenum.dart.)
  • lib/src/proto/tensor_description.pbjson.dart (Run dartfmt to format lib/src/proto/tensor_description.pbjson.dart.)
  • lib/src/proto/tensor_description.pbserver.dart (Run dartfmt to format lib/src/proto/tensor_description.pbserver.dart.)
  • lib/src/proto/tensor_shape.pb.dart (Run dartfmt to format lib/src/proto/tensor_shape.pb.dart.)
  • lib/src/proto/tensor_shape.pbenum.dart (Run dartfmt to format lib/src/proto/tensor_shape.pbenum.dart.)
  • lib/src/proto/tensor_shape.pbjson.dart (Run dartfmt to format lib/src/proto/tensor_shape.pbjson.dart.)
  • lib/src/proto/tensor_shape.pbserver.dart (Run dartfmt to format lib/src/proto/tensor_shape.pbserver.dart.)
  • lib/src/proto/types.pb.dart (Run dartfmt to format lib/src/proto/types.pb.dart.)
  • lib/src/proto/types.pbenum.dart (Run dartfmt to format lib/src/proto/types.pbenum.dart.)
  • lib/src/proto/types.pbjson.dart (Run dartfmt to format lib/src/proto/types.pbjson.dart.)
  • lib/src/proto/types.pbserver.dart (Run dartfmt to format lib/src/proto/types.pbserver.dart.)
  • lib/src/proto/versions.pb.dart (Run dartfmt to format lib/src/proto/versions.pb.dart.)
  • lib/src/proto/versions.pbenum.dart (Run dartfmt to format lib/src/proto/versions.pbenum.dart.)
  • lib/src/proto/versions.pbjson.dart (Run dartfmt to format lib/src/proto/versions.pbjson.dart.)
  • lib/src/proto/versions.pbserver.dart (Run dartfmt to format lib/src/proto/versions.pbserver.dart.)
  • lib/tensorflow.dart (Run dartfmt to format lib/tensorflow.dart.)

Maintenance issues and suggestions

Fix platform conflicts. (-20 points)

Error(s) prevent platform classification:

Fix dependencies in pubspec.yaml.

Make sure dartdoc successfully runs on your package's source files. (-10 points)

Dependencies were not resolved.

Provide a file named CHANGELOG.md. (-20 points)

Changelog entries help developers follow the progress of your package. See the example generated by stagehand.

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Package is getting outdated. (-14.25 points)

The package was last published 59 weeks ago.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <3.0.0

Admin