- This topic has 3 replies, 2 voices, and was last updated 3 years, 4 months ago by .
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- You must be logged in to reply to this topic.
Home › Forums › Fórum Deep Learning de A à Z com PyTorch e Python › Avaliação do número de camadas
Tagged: base de dados e rede neural (Classificação binária – base breast cancer), Projeto #3: Bibliotecas
Olá, poderia exemplificar como ficaria a classe classificador_torch na situação em que se deseja analisar o número de camadas ocultas ideal? No vídeo, o professor fala sobre definir o recebimento de um parâmetro a mais pela classe e fazer um for no init para fazer essa avaliação, mas fiquei meio perdido como seria essa construção.
Olá Vinícius,
Você pode fazer algo assim:
class classificador_torch(nn.Module):
def __init__(self, activation, neurons, n_hidden_layers, initializer):
super().__init__()
self.input_layer = nn.Linear(30, neurons)
initializer(self.input_layer.weight)
self.hidden_layers = [nn.Linear(neurons, neurons) for _ in range(n_hidden_layers)]
for layer in self.hidden_layers:
initializer(layer.weight)
self.activation = activation
self.output_layer = nn.Linear(neurons, 1)
def forward(self, X):
X = self.input_layer(X)
X = self.activation(X)
for layer in self.hidden_layers:
X = layer(X)
X = self.activation(X)
X = self.output_layer(X)
return X
Fiquei com uma dúvida em um trecho do código: no for _ in range(5), no lugar desse 5 não era pra estar o n_hidden_layers?
Isso mesmo, meu engano, agora está corrigido.