This file contains 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 torch | |
import torch.nn as nn | |
import numpy as np | |
from sklearn.utils.class_weight import compute_class_weight | |
from imblearn.over_sampling import SMOTE | |
# Dados de exemplo: classe 0: 1000 amostras, classe 1: 100 amostras | |
y_train = np.array([0]*1000 + [1]*100) | |
# 1. Pesos nas classes |
This file contains 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
from sklearn.metrics import precision_score, recall_score, f1_score, confusion_matrix | |
def avaliar_desempenho(y_true, y_pred): | |
""" | |
Avalia o desempenho do modelo de classificação de veículos usando precisão, recall e F1-score. | |
Parâmetros: | |
y_true (list ou array): Rótulos reais (verdadeiros). | |
y_pred (list ou array): Rótulos previstos pelo modelo. | |
This file contains 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 torch | |
import torch.nn as nn | |
import torch.nn.utils.prune as prune | |
import torch.quantization | |
# Exemplo de um modelo simples (CNN) | |
class SimpleCNN(nn.Module): | |
def __init__(self): | |
super(SimpleCNN, self).__init__() | |
self.conv = nn.Conv2d(in_channels=3, out_channels=16, kernel_size=3, stride=1, padding=1) |
This file contains 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 numpy as np | |
import cv2 | |
import seaborn as sns | |
import matplotlib.pyplot as plt | |
def gerar_mapa_calor(imagem, coordenadas_veiculos, tamanho_mapa=(500, 500), raio=15): | |
""" | |
Gera um mapa de calor baseado nas coordenadas dos veículos detectados. | |
Args: |
This file contains 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 numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
def suavizar_serie_temporal(dados, janela=3): | |
""" | |
Aplica um filtro de suavização (média móvel) a uma série temporal de dados. | |
Args: | |
dados (pd.Series ou list): A série temporal de dados de tráfego. |
This file contains 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 pandas as pd | |
from sklearn.model_selection import train_test_split | |
from sklearn.linear_model import LogisticRegression | |
from sklearn.preprocessing import StandardScaler | |
from sklearn.metrics import accuracy_score | |
def prever_congestionamento(df): | |
""" | |
Previsão de congestionamento com base em dados históricos de tráfego. | |
This file contains 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 cv2 | |
import numpy as np | |
from matplotlib import pyplot as plt | |
# Carregar a imagem de tráfego | |
imagem = cv2.imread('caminho/para/imagem_de_trafego.jpg') | |
# Converter a imagem para escala de cinza | |
imagem_cinza = cv2.cvtColor(imagem, cv2.COLOR_BGR2GRAY) |
This file contains 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 torch | |
from torch.utils.data import Dataset, DataLoader | |
from torchvision import transforms | |
from PIL import Image | |
import os | |
# Definir a classe do Dataset personalizado | |
class VehicleDataset(Dataset): | |
def __init__(self, imagens_dir, rotulos_file, transform=None): | |
""" |
This file contains 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 torch | |
from torchvision import transforms | |
from PIL import Image | |
import matplotlib.pyplot as plt | |
# Função para realizar data augmentation | |
def augmentacao_imagem(imagem): | |
# Definindo uma sequência de transformações | |
transformacao = transforms.Compose([ | |
transforms.RandomRotation(degrees=30), # Rotaciona a imagem até 30 graus |
This file contains 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 calcular_velocidade_media(dados): | |
# Inicializar variáveis para somar a distância total e o tempo total | |
distancia_total = 0 | |
tempo_total = 0 | |
# Iterar sobre a lista de dados | |
for dado in dados: | |
distancia_total += dado['distancia'] | |
tempo_total += dado['tempo'] | |
NewerOlder