Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Rust language bindings for TensorFlow

License

NotificationsYou must be signed in to change notification settings

tensorflow/rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SIG Rust TensorFlow

VersionBuild status

TensorFlow Rust provides idiomaticRust languagebindings forTensorFlow.

Notice: This project is still under active development and not guaranteed to have astable API.

Getting Started

Since this crate depends on the TensorFlow C API, it needs to be downloaded or compiled first. Thiscrate will automatically download or compile the TensorFlow shared libraries for you, but it is alsopossible to manually install TensorFlow and the crate will pick it up accordingly.

Prerequisites

If the TensorFlow shared libraries can already be found on your system, they will be used. If yoursystem is x86-64 Linux or Mac, a prebuilt binary will be downloaded, and no special prerequisitesare needed.

Otherwise, the following dependencies are needed to compile and build this crate, which involvescompiling TensorFlow itself:

  • git
  • bazel
  • Python Dependenciesnumpy,dev,pip andwheel
  • Optionally, CUDA packages to support GPU-based processing

The TensorFlow website provides detailed instructions on how to obtain and install said dependencies,so if you are unsure pleasecheck out the docsfor further details.

Some of the examples use TensorFlow code written in Python and require a full TensorFlowinstallation.

The minimum supported Rust version is 1.58.

Usage

Add this to yourCargo.toml:

[dependencies]tensorflow ="0.21.0"

and this to your crate root:

externcrate tensorflow;

Then runcargo build -j 1. The tensorflow-sys crate'sbuild.rsnow either downloads a pre-built, basic CPU only binary(the default)or compiles TensorFlow if forced to by an environment variable. If TensorFlowis compiled during this process, since the full compilation is very memoryintensive, we recommend using the-j 1 flag which tells cargo to use only onetask, which in turn tells TensorFlow to build with only one task. Though, ifyou have a lot of RAM, you can obviously use a higher value.

To include the especially unstable API (which is currently theexpr module),use--features tensorflow_unstable.

For now, please see theExamples for moredetails on how to use this binding.

Tensor Max Display

When printing or debugging a tensor, it will print every element by default, thiscan be modified by changing an environment variable:

TF_RUST_DISPLAY_MAX=5

Which will truncate the values if they exceed the limit:

let values:Vec<u64> =(0..100000).collect();let t =Tensor::new(&[2,50000]).with_values(&values).unwrap();dbg!(t);
t = Tensor<u64> {    values: [        [0, 1, 2, 3, 4, ...],        ...    ],    dtype: uint64,    shape: [2, 50000]}

GPU Support

To enable GPU support, use thetensorflow_gpu feature in your Cargo.toml:

[dependencies]tensorflow = { version = "0.21.0", features = ["tensorflow_gpu"] }

Manual TensorFlow Compilation

If you want to work against unreleased/unsupported TensorFlow versions or use a build optimized foryour machine, manual compilation is the way to go.

Seetensorflow-sys/README.md for details.

FAQ's

Why does the compiler say that parts of the API don't exist?

The especially unstable parts of the API (which is currently theexpr module) arefeature-gated behind the featuretensorflow_unstable to prevent accidentaluse. Seehttp://doc.crates.io/manifest.html#the-features-section.(We would prefer using an#[unstable] attribute, but thatdoesn't exist yet.)

How do I...?

Try thedocumentation first, and see if it answersyour question. If not, take a look at the examples folder. Note that there may not be an examplefor your exact question, but it may be answered by an example demonstrating something else.

If none of the above help, you can ask your question onTensorFlow Rust Google Group.

Contributing

Developers and users are welcome to join theTensorFlow Rust Google Group.

Please read thecontribution guidelines on how to contribute code.

This is not an official Google product.

RFCs areissues tagged with RFC.Check them out and comment. Discussions are welcomed. After all, that is the purpose ofRequest For Comment!

License

This project is licensed under the terms of theApache 2.0 license.


[8]ページ先頭

©2009-2025 Movatter.jp