1
## 1. What is TensorFlow?
TensorFlow is an open source library developed by Google for machine learning and artificial intelligence tasks. It allows complex deep learning models to be built.
---
##
2. Installing TensorFlow To begin with, you need to install the library. Use the following command in your terminal: ```bash pip install tensorflow ``` Make sure you have a recent version of Python (3.7 or higher) installed. ##
3. Importing TensorFlow After installing, import TensorFlow into your Python project: ```py import tensorflow as tf print("Versão do TensorFlow:", tf.__version__) ``` --- ##
4. Building a Simple Model Let's create a basic example of a neural network to predict a linear function, such as `y = 2x - 1`. ```py import numpy as np import tensorflow as tf from tensorflow import keras # Input (x) and output (y) data x_train = np.array([-1.0, 0.0, 1.0, 2.0, 3.0, 4.0], dtype=float) y_train = np.array([-3.0, -1.0, 1.0, 3.0, 5.0, 7.0], dtype=float) # Building the model model = keras.Sequential([ keras.layers.Dense(units=1, input_shape=[1]) ]) # Compiling the model model.compile(optimizer='sgd', loss='mean_squared_error') # Training the model model.fit(x_train, y_train, epochs=500) # Making a prediction print(model.predict([10.0])) ``` --- ##
5. Code explanation - keras.Sequential: Creates a linear stack of layers. - Dense: A densely connected (neural) layer. - optimizer: The algorithm that adjusts the weights during training (in this case, sgd - gradient descent). - loss: The loss function to measure the model's accuracy during training. - fit: Trains the model for a number of epochs, adjusting the weights based on the input data. --- ##
6. Next steps - Try working with different model architectures. - Add more layers and neurons for more complex models. - Explore techniques such as convolutional neural networks (CNNs) for image recognition. This is a starting point for you to begin experimenting with AI using TensorFlow. If you want to delve deeper, you can explore the TensorFlow Playground or follow the official documentation and tutorials on the TensorFlow website.
2. Installing TensorFlow To begin with, you need to install the library. Use the following command in your terminal: ```bash pip install tensorflow ``` Make sure you have a recent version of Python (3.7 or higher) installed. ##
3. Importing TensorFlow After installing, import TensorFlow into your Python project: ```py import tensorflow as tf print("Versão do TensorFlow:", tf.__version__) ``` --- ##
4. Building a Simple Model Let's create a basic example of a neural network to predict a linear function, such as `y = 2x - 1`. ```py import numpy as np import tensorflow as tf from tensorflow import keras # Input (x) and output (y) data x_train = np.array([-1.0, 0.0, 1.0, 2.0, 3.0, 4.0], dtype=float) y_train = np.array([-3.0, -1.0, 1.0, 3.0, 5.0, 7.0], dtype=float) # Building the model model = keras.Sequential([ keras.layers.Dense(units=1, input_shape=[1]) ]) # Compiling the model model.compile(optimizer='sgd', loss='mean_squared_error') # Training the model model.fit(x_train, y_train, epochs=500) # Making a prediction print(model.predict([10.0])) ``` --- ##
5. Code explanation - keras.Sequential: Creates a linear stack of layers. - Dense: A densely connected (neural) layer. - optimizer: The algorithm that adjusts the weights during training (in this case, sgd - gradient descent). - loss: The loss function to measure the model's accuracy during training. - fit: Trains the model for a number of epochs, adjusting the weights based on the input data. --- ##
6. Next steps - Try working with different model architectures. - Add more layers and neurons for more complex models. - Explore techniques such as convolutional neural networks (CNNs) for image recognition. This is a starting point for you to begin experimenting with AI using TensorFlow. If you want to delve deeper, you can explore the TensorFlow Playground or follow the official documentation and tutorials on the TensorFlow website.
You must log in or # to comment.