Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

neuronal network exemple python

# Import the libraries required in this example:
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers

inputs = keras.Input(shape=(784,), name="digits")
x = layers.Dense(64, activation="relu", name="dense_1")(inputs)
x = layers.Dense(64, activation="relu", name="dense_2")(x)
outputs = layers.Dense(10, activation="softmax", name="predictions")(x)

model = keras.Model(inputs=inputs, outputs=outputs)

(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()

# Preprocess the data (NumPy arrays):
x_train = x_train.reshape(60000, 784).astype("float32") / 255
x_test = x_test.reshape(10000, 784).astype("float32") / 255

y_train = y_train.astype("float32")
y_test = y_test.astype("float32")

# Allocate 10,000 samples for validation:
x_val = x_train[-10000:]
y_val = y_train[-10000:]
x_train = x_train[:-10000]
y_train = y_train[:-10000]

model.compile(
    optimizer=keras.optimizers.RMSprop(),  # Optimizer
    # Minimize loss:
    loss=keras.losses.SparseCategoricalCrossentropy(),
    # Monitor metrics:
    metrics=[keras.metrics.SparseCategoricalAccuracy()],
)

print("Fit model on training data")
history = model.fit(
    x_train,
    y_train,
    batch_size=64,
    epochs=2,
    # Validation of loss and metrics
    # at the end of each epoch:
    validation_data=(x_val, y_val),
)

history.history

print("Evaluate model on test data")
results = model.evaluate(x_test, y_test, batch_size=128)
print("test loss, test acc:", results)

# Generate a prediction using model.predict() 
# and calculate it's shape:
print("Generate a prediction")
prediction = model.predict(x_test[:1])
print("prediction shape:", prediction.shape)
Comment

PREVIOUS NEXT
Code Example
Python :: pyqt5 close event 
Python :: find the most similar rows in two dataframes 
Python :: python check if class has function 
Python :: count frequency of characters in string 
Python :: compress tarfile python 
Python :: print alphabets in python 
Python :: how to convert cost to float in python 
Python :: python requests response get text 
Python :: pandas dataframe to parquet s3 
Python :: how to change the console background color in python 
Python :: generate list of consecutive numbers 
Python :: extend a list python 
Python :: odoo scaffold 
Python :: rotate image in pygame 
Python :: calculate days between two dates python 
Python :: colorbar min max matplotlib 
Python :: how to get index of closest value in list python 
Python :: convert list to generator python 
Python :: data frame list value change to string 
Python :: python classes 
Python :: Make a basic pygame window 
Python :: copyfile pyhon 
Python :: the following packages have unmet dependencies python3-tornado 
Python :: from array to tuple python 
Python :: hex python add 0 
Python :: fill zero behind number python 
Python :: how to check an element in a list in python 
Python :: beautiful soup documentation 
Python :: python define random variables name 
Python :: pandas create column if equals 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =