Install TensorFlow Federated

There are a few ways to set up your environment to use TensorFlow Federated (TFF):

Install TensorFlow Federated using pip

1. Install the Python development environment.

sudoaptupdate
sudoaptinstallpython3-devpython3-pip# Python 3

2. Create a virtual environment.

python3-mvenv"venv"
source"venv/bin/activate"
pipinstall--upgrade"pip"

3. Install the released TensorFlow Federated Python package.

pipinstall--upgradetensorflow-federated

4. Test Tensorflow Federated.

python-c"import tensorflow_federated as tff; print(tff.tensorflow_computation(lambda: 'Hello World')())"

Build the TensorFlow Federated Python package from source

Building a TensorFlow Federated Python package from source is helpful when you want to:

  • Make changes to TensorFlow Federated and test those changes in a component that uses TensorFlow Federated before those changes are submitted or released.
  • Use changes that have been submitted to TensorFlow Federated but have not been released.

1. Install the Python development environment.

sudoaptupdate
sudoaptinstallpython3-devpython3-pip# Python 3

2. Install Bazel.

Install Bazel, the build tool used to compile Tensorflow Federated.

3. Clone the Tensorflow Federated repository.

gitclonehttps://github.com/google-parfait/tensorflow-federated.git
cd"tensorflow-federated"

4. Create a virtual environment.

python3-mvenv"venv"
source"venv/bin/activate"
pipinstall--upgrade"pip"
pipinstallnumpy

5. Build the TensorFlow Federated Python package.

mkdir"/tmp/tensorflow_federated"
bazelrun//tools/python_package:build_python_package--\
--output_dir="/tmp/tensorflow_federated"

6. Exit the virtual environment

deactivate

7. Create a new project.

mkdir"/tmp/project"
cd"/tmp/project"

8. Create a new virtual environment.

python3-mvenv"venv"
source"venv/bin/activate"
pipinstall--upgrade"pip"

9. Install the TensorFlow Federated Python package.

pipinstall--upgrade"/tmp/tensorflow_federated/"*".whl"

10. Test Tensorflow Federated.

python-c"import tensorflow_federated as tff; print(tff.tensorflow_computation(lambda: 'Hello World')())"

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年01月30日 UTC.