or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

tessl/pypi-tensorflow

An end-to-end open source platform for machine learning

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/tensorflow@2.20.x

To install, run

npx @tessl/cli install tessl/pypi-tensorflow@2.20.0

0

# TensorFlow

1

2

An end-to-end open source platform for machine learning that provides a comprehensive ecosystem of tools, libraries, and community resources for both research and production deployment. TensorFlow supports stable APIs for Python and C++, along with experimental APIs for other languages, enabling developers to build and deploy ML-powered applications efficiently across various hardware accelerators (CPUs, GPUs, TPUs) and distributed training environments.

3

4

## Package Information

5

6

- **Package Name**: tensorflow

7

- **Language**: Python (with C++ core)

8

- **Installation**: `pip install tensorflow`

9

- **Version**: 2.20.0

10

11

## Core Imports

12

13

```python

14

import tensorflow as tf

15

```

16

17

For Keras high-level API:

18

19

```python

20

from tensorflow import keras

21

```

22

23

For specific modules:

24

25

```python

26

from tensorflow.keras import layers, models, optimizers

27

from tensorflow.data import Dataset

28

import tensorflow.nn as nn

29

```

30

31

## Basic Usage

32

33

```python

34

import tensorflow as tf

35

import numpy as np

36

37

# Create tensors

38

x = tf.constant([1.0, 2.0, 3.0])

39

y = tf.constant([4.0, 5.0, 6.0])

40

41

# Basic operations

42

z = tf.add(x, y)

43

print(z) # tf.Tensor([5. 7. 9.], shape=(3,), dtype=float32)

44

45

# Create a simple neural network with Keras

46

model = tf.keras.Sequential([

47

tf.keras.layers.Dense(128, activation='relu', input_shape=(784,)),

48

tf.keras.layers.Dropout(0.2),

49

tf.keras.layers.Dense(10, activation='softmax')

50

])

51

52

# Compile the model

53

model.compile(optimizer='adam',

54

loss='sparse_categorical_crossentropy',

55

metrics=['accuracy'])

56

57

# Create sample data

58

X_train = np.random.random((1000, 784))

59

y_train = np.random.randint(10, size=(1000,))

60

61

# Train the model

62

model.fit(X_train, y_train, epochs=5, batch_size=32)

63

```

64

65

## Architecture

66

67

TensorFlow's architecture is built around several key components:

68

69

- **Tensors**: Multi-dimensional arrays that flow through computational graphs

70

- **Operations**: Mathematical computations performed on tensors

71

- **Graphs**: Computational graphs that define the flow of data and operations

72

- **Sessions**: Runtime environments for executing graphs (TF 1.x) or eager execution (TF 2.x)

73

- **Keras**: High-level API for building and training neural networks

74

- **Estimators**: High-level API for distributed training and evaluation

75

76

The framework supports both eager execution (default in TF 2.x) for immediate operation evaluation and graph mode for optimized production deployment.

77

78

## Capabilities

79

80

### Core Tensor Operations

81

82

Fundamental tensor creation, manipulation, and mathematical operations that form the foundation of TensorFlow computations.

83

84

```python { .api }

85

def constant(value, dtype=None, shape=None, name="Const"): ...

86

def Variable(initial_value, trainable=None, validate_shape=True,

87

caching_device=None, name=None, variable_def=None, dtype=None,

88

import_scope=None, constraint=None, synchronization=tf.VariableSynchronization.AUTO,

89

aggregation=tf.VariableAggregation.NONE, shape=None,

90

experimental_enable_variable_lifting=True): ...

91

def convert_to_tensor(value, dtype=None, dtype_hint=None, name=None): ...

92

def cast(x, dtype, name=None): ...

93

def reshape(tensor, shape, name=None): ...

94

def transpose(a, perm=None, conjugate=False, name="transpose"): ...

95

def zeros(shape, dtype=tf.float32, name=None): ...

96

def ones(shape, dtype=tf.float32, name=None): ...

97

```

98

99

[Core Operations](./core.md)

100

101

### Math Operations

102

103

Comprehensive mathematical operations including arithmetic, trigonometric, linear algebra, and statistical functions.

104

105

```python { .api }

106

def add(x, y, name=None): ...

107

def subtract(x, y, name=None): ...

108

def multiply(x, y, name=None): ...

109

def divide(x, y, name=None): ...

110

def matmul(a, b, transpose_a=False, transpose_b=False, adjoint_a=False,

111

adjoint_b=False, a_is_sparse=False, b_is_sparse=False, output_type=None,

112

grad_a=False, grad_b=False, name=None): ...

113

def reduce_sum(input_tensor, axis=None, keepdims=None, name=None): ...

114

def reduce_mean(input_tensor, axis=None, keepdims=None, name=None): ...

115

```

116

117

[Math Operations](./math.md)

118

119

### Neural Network Operations

120

121

Core neural network operations including activations, convolutions, pooling, normalization, and loss functions.

122

123

```python { .api }

124

def relu(features, name=None): ...

125

def softmax(logits, axis=None, name=None): ...

126

def conv2d(input, filters, strides, padding, use_cudnn_on_gpu=True, data_format="NHWC",

127

dilations=[1,1,1,1], name=None): ...

128

def max_pool2d(input, ksize, strides, padding, data_format="NHWC", name=None): ...

129

def batch_normalization(x, mean, variance, offset, scale, variance_epsilon, name=None): ...

130

def softmax_cross_entropy_with_logits(labels, logits, axis=-1, name=None): ...

131

```

132

133

[Neural Network Operations](./nn.md)

134

135

### Keras High-Level API

136

137

High-level neural network building blocks including models, layers, optimizers, losses, and metrics for rapid prototyping and production.

138

139

```python { .api }

140

class Sequential(Model): ...

141

class Model: ...

142

class Dense(Layer): ...

143

class Conv2D(Layer): ...

144

class LSTM(Layer): ...

145

class Adam(Optimizer): ...

146

class SGD(Optimizer): ...

147

```

148

149

[Keras API](./keras.md)

150

151

### Data Processing

152

153

Dataset creation, transformation, and preprocessing pipeline operations for efficient data handling and training workflows.

154

155

```python { .api }

156

class Dataset:

157

@staticmethod

158

def from_tensor_slices(tensors, name=None): ...

159

@staticmethod

160

def from_tensors(tensors, name=None): ...

161

def map(self, map_func, num_parallel_calls=None, deterministic=None, name=None): ...

162

def batch(self, batch_size, drop_remainder=False, num_parallel_calls=None,

163

deterministic=None, name=None): ...

164

def shuffle(self, buffer_size, seed=None, reshuffle_each_iteration=None, name=None): ...

165

def repeat(self, count=None, name=None): ...

166

```

167

168

[Data Processing](./data.md)

169

170

### Image Processing

171

172

Comprehensive image manipulation, transformation, and computer vision operations for preprocessing and augmentation.

173

174

```python { .api }

175

def decode_image(contents, channels=None, dtype=tf.uint8, name=None, expand_animations=True): ...

176

def resize(images, size, method=ResizeMethod.BILINEAR, preserve_aspect_ratio=False,

177

antialias=False, name=None): ...

178

def random_flip_left_right(image, seed=None): ...

179

def random_brightness(image, max_delta, seed=None): ...

180

def convert_image_dtype(image, dtype, saturate=False, name=None): ...

181

```

182

183

[Image Processing](./image.md)

184

185

### Model Saving and Loading

186

187

Complete model serialization, checkpointing, and deployment utilities for production and inference.

188

189

```python { .api }

190

def save(obj, export_dir, signatures=None, options=None): ...

191

def load(export_dir, tags=None, options=None): ...

192

class Checkpoint:

193

def __init__(self, **kwargs): ...

194

def save(self, file_prefix, session=None): ...

195

def restore(self, save_path): ...

196

```

197

198

[Model Management](./saved-model.md)

199

200

### Distribution Strategies

201

202

Multi-device and multi-worker training strategies for scaling machine learning workloads across GPUs and TPUs.

203

204

```python { .api }

205

class MirroredStrategy(Strategy): ...

206

class MultiWorkerMirroredStrategy(Strategy): ...

207

class TPUStrategy(Strategy): ...

208

class ParameterServerStrategy(Strategy): ...

209

```

210

211

[Distribution](./distribute.md)

212

213

### Automatic Differentiation

214

215

Gradient computation and automatic differentiation functionality for training neural networks.

216

217

```python { .api }

218

class GradientTape:

219

def __init__(self, persistent=False, watch_accessed_variables=True): ...

220

def watch(self, tensor): ...

221

def gradient(self, target, sources, output_gradients=None,

222

unconnected_gradients=UnconnectedGradients.NONE): ...

223

def gradient(target, sources, grad_ys=None, name="gradients",

224

gate_gradients=False, aggregation_method=None,

225

stop_gradients=None, unconnected_gradients=UnconnectedGradients.NONE): ...

226

```

227

228

### Random Operations

229

230

Random number generation and sampling operations for stochastic computations.

231

232

```python { .api }

233

def random_normal(shape, mean=0.0, stddev=1.0, dtype=tf.float32, seed=None, name=None): ...

234

def random_uniform(shape, minval=0, maxval=None, dtype=tf.float32, seed=None, name=None): ...

235

def random_shuffle(value, seed=None, name=None): ...

236

def set_seed(seed): ...

237

```

238

239

### Configuration and System

240

241

System configuration, device management, and runtime settings.

242

243

```python { .api }

244

def list_physical_devices(device_type=None): ...

245

def list_logical_devices(device_type=None): ...

246

def experimental_set_memory_growth(device, enable): ...

247

def experimental_get_memory_info(device): ...

248

```

249

250

### Input/Output Operations

251

252

File system operations, data serialization, and I/O utilities.

253

254

```python { .api }

255

def read_file(filename, name=None): ...

256

def write_file(filename, contents, name=None): ...

257

def matching_files(pattern, name=None): ...

258

def decode_raw(input_bytes, out_type, little_endian=True, fixed_length=None, name=None): ...

259

```

260

261

## Types

262

263

```python { .api }

264

class Tensor:

265

"""Multi-dimensional array with uniform data type."""

266

@property

267

def shape(self): ...

268

@property

269

def dtype(self): ...

270

@property

271

def device(self): ...

272

def numpy(self): ...

273

274

class Variable(Tensor):

275

"""Mutable tensor for storing model parameters."""

276

def assign(self, value, use_locking=None, name=None, read_value=True): ...

277

def assign_add(self, delta, use_locking=None, name=None, read_value=True): ...

278

279

class Operation:

280

"""Computation node in a TensorFlow graph."""

281

@property

282

def name(self): ...

283

@property

284

def type(self): ...

285

@property

286

def inputs(self): ...

287

@property

288

def outputs(self): ...

289

290

# Data types

291

DType = tf.DType

292

float16 = tf.float16

293

float32 = tf.float32

294

float64 = tf.float64

295

int8 = tf.int8

296

int16 = tf.int16

297

int32 = tf.int32

298

int64 = tf.int64

299

uint8 = tf.uint8

300

uint16 = tf.uint16

301

uint32 = tf.uint32

302

uint64 = tf.uint64

303

bool = tf.bool

304

string = tf.string

305

complex64 = tf.complex64

306

complex128 = tf.complex128

307

308

# Enumerations

309

class VariableSynchronization:

310

"""Variable synchronization modes for distributed training."""

311

NONE = "VariableSynchronization.NONE"

312

ON_WRITE = "VariableSynchronization.ON_WRITE"

313

ON_READ = "VariableSynchronization.ON_READ"

314

AUTO = "VariableSynchronization.AUTO"

315

316

class VariableAggregation:

317

"""Variable aggregation modes for distributed training."""

318

NONE = "VariableAggregation.NONE"

319

SUM = "VariableAggregation.SUM"

320

MEAN = "VariableAggregation.MEAN"

321

ONLY_FIRST_REPLICA = "VariableAggregation.ONLY_FIRST_REPLICA"

322

323

class UnconnectedGradients:

324

"""Gradient computation modes for unconnected inputs."""

325

NONE = "UnconnectedGradients.NONE"

326

ZERO = "UnconnectedGradients.ZERO"

327

```