TensorFlow CPU

2.21.0 · active · verified Sat Apr 11

TensorFlow-cpu is the CPU-optimized variant of TensorFlow, an open-source machine learning framework developed by Google. It is designed for high-performance numerical computation, suitable for training and deploying machine learning models without GPU acceleration. The current version is 2.21.0, and it follows a frequent release cadence, typically aligning with the main TensorFlow project's minor and patch updates every few months.

Warnings

Install

Imports

Quickstart

This quickstart code verifies the installed TensorFlow version, checks if CPU devices are recognized, and performs a basic tensor operation to confirm that TensorFlow is functioning correctly on the CPU.

import tensorflow as tf

# Verify TensorFlow version
print(f"TensorFlow Version: {tf.__version__}")

# Verify CPU device is recognized
cpu_devices = tf.config.list_physical_devices('CPU')
print(f"CPU Devices: {cpu_devices}")

if cpu_devices:
    print(f"TensorFlow is configured to use CPU: {cpu_devices[0].name}")
    # Perform a simple operation to confirm functionality
    a = tf.constant([[1.0, 2.0], [3.0, 4.0]])
    b = tf.constant([[1.0, 1.0], [1.0, 1.0]])
    print(f"Result of a + b:\n{a + b}")
else:
    print("No CPU devices found by TensorFlow. Check installation.")

view raw JSON →