This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def randomInit(input_layer_size, hidden_layer_size, num_labels): | |
# Parâmetros da primeira camada (incluindo bias) | |
# As matrizes têm formato (num_entradas, num_saidas) | |
size1 = (hidden_layer_size, input_layer_size+1) | |
theta1_ini = np.random.normal(0, .1, size=size1) | |
# Parâmetros da primeira camada (incluindo bias) | |
size2 = (num_labels, hidden_layer_size+1) | |
theta2_ini = np.random.normal(0, .1, size=size2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Mudando o formato das entradas para que cada imagem seja uma lista, ao invés de uma matriz | |
x_train = x_train.reshape(x_train.shape[0], 28*28) | |
x_test = x_test.reshape(x_test.shape[0], 28*28) | |
# Converte os valores para float, para que eles possam ter parte decimal. | |
x_train = x_train.astype('float32') | |
x_test = x_test.astype('float32') | |
# Divide pelo valor RGB máximo, para que a entrada tenha valores entre 0 e 1. | |
x_train /= 255 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Cada linha da matriz identidade corresponde a uma das labels | |
mapping = np.identity(10, dtype=int) | |
y_train_classif = y_train | |
y_test_classif = y_test | |
y_train = np.array([mapping[y] for y in y_train]) | |
y_test = np.array([mapping[y] for y in y_test]) | |
print(y_train_classif[0], y_train[0]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sigmoid(z): | |
return 1/(1 + np.exp(-z)) | |
def sigmoidGrad(z): | |
return (sigmoid(z))*(1-sigmoid(z)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow.compat.v1 as tf | |
tf.disable_v2_behavior() | |
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# MATPLOTLIB | |
import matplotlib.pyplot as plt | |
import matplotlib.image as mpimg | |
# lê o arquivo (note que em matplotlib deve ser em png) | |
img = mpimg.imaread('<nome_do_arquivo>.png') | |
print(img) | |
imgplot = plt.imshow(img) # mostra a imagem |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.