Yolo Vision Shenzhen
Shenzhen
Iscriviti ora
Glossario

Sigmoide

Learn how the Sigmoid function acts as a squashing activation function in deep learning. Explore its role in binary classification and [YOLO26](https://docs.ultralytics.com/models/yolo26/) models.

La funzione sigmoide è un componente matematico fondamentale ampiamente utilizzato nei campi del machine learning (ML) e del deep learning (DL). Spesso definita come "funzione di schiacciamento", accetta come input qualsiasi numero reale e lo mappa su un valore compreso tra 0 e 1. Questa caratteristica curva a forma di "S" la rende incredibilmente utile per convertire i risultati grezzi del modello in probabilità interpretabili. Nel contesto di una rete neurale (NN), la funzione sigmoide agisce come funzione di attivazione, introducendo una non linearità che consente ai modelli di apprendere modelli complessi al di là delle semplici relazioni lineari. Sebbene sia stata in gran parte sostituita da altre funzioni nei livelli nascosti profondi, rimane una scelta standard per i livelli di output nelle attività di classificazione binaria .

La meccanica del sigmoide nell'intelligenza artificiale

Fondamentalmente, la funzione sigmoide trasforma i dati di input, spesso denominati logit, in un intervallo normalizzato. Questa trasformazione è fondamentale per le attività il cui obiettivo è prevedere la probabilità di un evento. Limitando l'output tra 0 e 1, la funzione fornisce un punteggio di probabilità chiaro.

  • Regressione logistica: nella modellizzazione statistica tradizionale, Sigmoid è il motore alla base della regressione logistica. Consente ai data scientist di stimare la probabilità di un risultato binario, ad esempio se un cliente abbandonerà o rimarrà.
  • Classificazione binaria: per le reti neurali progettate per distinguere tra due classi (ad esempio, "gatto" e "cane"), l'ultimo strato spesso impiega un'attivazione sigmoide. Se l'output è superiore a una soglia (comunemente 0,5), il modello prevede la classe positiva.
  • Classificazione multi-etichetta: A differenza dei problemi multi-classe in cui le classi sono mutuamente esclusive, i compiti multi-etichetta consentono a un'immagine o a un testo di appartenere a più categorie contemporaneamente. In questo caso, Sigmoid viene applicato in modo indipendente a ciascun nodo di output, consentendo a un modello di detect "macchina" e una "persona" nella stessa scena senza conflitti.

Key Differences from Other Activation Functions

While Sigmoid was once the default for all layers, researchers discovered limitations like the vanishing gradient problem, where gradients become too small to update weights effectively in deep networks. This led to the adoption of alternatives for hidden layers.

  • Sigmoid vs. ReLU (Rectified Linear Unit): ReLU is computationally faster and avoids vanishing gradients by outputting the input directly if positive, and zero otherwise. It is the preferred choice for hidden layers in modern architectures like YOLO26, whereas Sigmoid is reserved for the final output layer in specific tasks.
  • Sigmoid vs. Softmax: Both map outputs to a 0-1 range, but they serve different purposes. Sigmoid treats each output independently, making it ideal for binary or multi-label tasks. Softmax forces all outputs to sum to 1, creating a probability distribution used for multi-class classification where only one class is correct.

Applicazioni nel mondo reale

The utility of the Sigmoid function extends across various industries where probability estimation is required.

  1. Medical Diagnosis: AI models used in medical image analysis often use Sigmoid outputs to predict the probability of a disease being present in an X-ray or MRI scan. For example, a model might output 0.85, indicating an 85% likelihood of a tumor, aiding doctors in early detection.
  2. Spam Detection: Email filtering systems utilize natural language processing (NLP) models with Sigmoid classifiers to determine if an incoming message is "spam" or "not spam." The model analyzes keywords and metadata, outputting a score that determines whether the email lands in the inbox or the junk folder.

Attuazione pratica

You can observe how Sigmoid transforms data using PyTorch, a popular library for building deep learning models. This simple example demonstrates the "squashing" effect on a range of input values.

import torch
import torch.nn as nn

# Create a Sigmoid layer
sigmoid = nn.Sigmoid()

# Define input data (logits) ranging from negative to positive
input_data = torch.tensor([-5.0, -1.0, 0.0, 1.0, 5.0])

# Apply Sigmoid to squash values between 0 and 1
output = sigmoid(input_data)

print(f"Input: {input_data}")
print(f"Output: {output}")
# Output values near 0 for negative inputs, 0.5 for 0, and near 1 for positive inputs

For those looking to train models that utilize these concepts without writing low-level code, the Ultralytics Platform offers an intuitive interface to manage datasets and train state-of-the-art models like YOLO26. By handling the architectural complexities automatically, it allows users to focus on gathering high-quality training data for their specific computer vision applications.

Unitevi alla comunità di Ultralytics

Entra nel futuro dell'AI. Connettiti, collabora e cresci con innovatori globali

Iscriviti ora