Skip to content

Instantly share code, notes, and snippets.

@CharlyJazz
Created January 30, 2020 20:06
Show Gist options
  • Select an option

  • Save CharlyJazz/2ce173f06765c92e12c91c4e49c092c6 to your computer and use it in GitHub Desktop.

Select an option

Save CharlyJazz/2ce173f06765c92e12c91c4e49c092c6 to your computer and use it in GitHub Desktop.
import torch
class SLP(torch.nn.Module)
"""
SLP Significa Single Layer Perceptron
"""
def __init__(self, input_shape, output_shape, device=torch.device("cpu")):
"""
:param input_shape: Tamano o forma de los inputs de entrada
:param output_shape: Tamano o forma de los inputs de entrada
:param device: El dispositivo ('cpu', 'cuda') que la SLP debe utilizar para almacenar los inputs a cada iteracion
"""
super(SLP, self).__init__()
self.device = device
self.input_shape = input_shape[0]
self.hidden_shape = 40
self.linear1 = torch.nn.Linear(self.input_shape, self.hidden_shape)
self.out = torch.nn.Linear(self.hidden_shape, self.output_shape)
def forward(self, x):
x = torch.from_numpy(x).float().to(self.device)
# RECTIFY LINEAR UNIT FUNCTION DE ACTIVATION relu
# la func relu es el maximo entre o y x
x = torch.nn.functional.relu(self.linear1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment