PyTorch Image Models (timm) 技術指南

timm

  • PyTorch Image Models (timm) 技術指南
      • 功能概述
    • 一、引言
    • 二、timm 庫概述
    • 三、安裝 timm 庫
    • 四、模型加載與推理示例
      • 4.1 通用推理流程
      • 4.2 具體模型示例
        • 4.2.1 ResNeXt50-32x4d
        • 4.2.2 EfficientNet-V2 Small 模型
        • 4.2.3 DeiT-3 large 模型
        • 4.2.4 RepViT-M2 模型
        • 4.2.5 ResNet-RS-101
        • 4.2.6 Vision Transformer (ViT)
        • 4.2.7 Swin Transformer
        • 4.2.8 Swin Transformer V2
        • 4.2.9 Swin Transformer V2 Cr
        • 4.2.10 Levit
      • 4.3 加載自定義模型
      • 4.4 提取模型的中間特征
      • 4.5 凍結模型的部分層
      • 4.6 創建模型時指定輸入圖像尺寸
      • 4.7 數據預處理階段調整圖像尺寸
      • 4.8 調整輸出分類個數
      • 4.9 綜合示例
        • 更多模型說明
    • 五、timm 庫近期更新
      • 5.1 2025 年 2 月 21 日更新
      • 5.2 其他更新
    • 六、分布式訓練支持
    • 七、學習率調度器
      • 7.1 余弦退火調度器(CosineLRScheduler)
      • 7.2 多步學習率調度器(MultiStepLRScheduler)
    • 八、總結
    • 九、參考資料

PyTorch Image Models (timm) 技術指南

timm(PyTorch Image Models)是一個廣泛使用的 PyTorch 庫,它集合了大量的圖像模型、層、實用工具、優化器、調度器、數據加載器/增強器以及參考訓練/驗證腳本。以下是對 timm 庫的詳細介紹,包括功能、模型案例、加載與使用示例以及相關教程的信息。

功能概述

  1. 豐富的圖像模型:包含眾多預訓練的圖像分類、目標檢測、語義分割等模型,如 ResNet、EfficientNet、ViT 等。
  2. 實用工具:提供了一系列用于模型訓練、驗證和推理的實用工具,如優化器、調度器、數據加載器和增強器等。
  3. 模型構建與管理:支持輕松構建和管理不同類型的模型,包括模型的初始化、權重加載和保存等。
  4. 分布式訓練:支持分布式訓練,方便在多個 GPU 或節點上進行高效訓練。

一、引言

在深度學習領域,圖像分類、目標檢測等任務常常需要使用預訓練的圖像模型。PyTorch Image Models (timm) 是一個功能強大的庫,它提供了大量預訓練的圖像模型,涵蓋了各種架構,方便開發者快速搭建和訓練自己的模型。本文將詳細介紹 timm 庫的使用,包括模型加載、推理以及近期更新的模型和功能。

二、timm 庫概述

timm 是一個基于 PyTorch 的圖像模型庫,它收集了眾多先進的圖像模型,如 ResNet、ViT、Swin Transformer 等,并提供了預訓練的權重。通過 timm,開發者可以輕松地加載這些模型,進行圖像分類、特征提取等任務。

三、安裝 timm 庫

在使用 timm 之前,需要先安裝該庫。可以使用以下命令進行安裝:

pip install timm

四、模型加載與推理示例

4.1 通用推理流程

以下是一個通用的使用 timm 加載模型并進行推理的示例代碼:

import torch
import timm
from PIL import Image
from torchvision import transforms# 加載預訓練模型
model = timm.create_model('model_name', pretrained=True)
model.eval()# 定義圖像預處理轉換
transform = transforms.Compose([transforms.Resize(256),transforms.CenterCrop(224),transforms.ToTensor(),transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])# 加載圖像
image = Image.open('path_to_your_image.jpg')
image = transform(image).unsqueeze(0)# 進行推理
with torch.no_grad():output = model(image)# 獲取預測結果
_, predicted_idx = torch.max(output, 1)
print(f"Predicted class index: {predicted_idx.item()}")

在上述代碼中,'model_name' 需要替換為具體的模型名稱,'path_to_your_image.jpg' 需要替換為實際的圖像文件路徑。

4.2 具體模型示例

4.2.1 ResNeXt50-32x4d
import torch
import timm
from PIL import Image
from torchvision import transforms# 加載預訓練的 ResNeXt50-32x4d 模型
model = timm.create_model('resnext50_32x4d', pretrained=True)
model.eval()# 定義圖像預處理轉換
transform = transforms.Compose([transforms.Resize(256),transforms.CenterCrop(224),transforms.ToTensor(),transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])# 加載圖像
image = Image.open('path_to_your_image.jpg')
image = transform(image).unsqueeze(0)# 進行推理
with torch.no_grad():output = model(image)# 獲取預測結果
_, predicted_idx = torch.max(output, 1)
print(f"ResNeXt50-32x4d Predicted class index: {predicted_idx.item()}")
4.2.2 EfficientNet-V2 Small 模型
import torch
import timm
from PIL import Image
from torchvision import transforms# 加載預訓練的 EfficientNet-V2 Small 模型
model = timm.create_model('efficientnetv2_s', pretrained=True)
model.eval()# 定義圖像預處理轉換
transform = transforms.Compose([transforms.Resize(256),transforms.CenterCrop(224),transforms.ToTensor(),transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])# 加載圖像
image = Image.open('path_to_your_image.jpg')
image = transform(image).unsqueeze(0)# 進行推理
with torch.no_grad():output = model(image)# 獲取預測結果
_, predicted_idx = torch.max(output, 1)
print(f"EfficientNet-V2 Small Predicted class index: {predicted_idx.item()}")
4.2.3 DeiT-3 large 模型
import torch
import timm
from PIL import Image
from torchvision import transforms# 加載預訓練的 DeiT-3 large 模型
model = timm.create_model('deit3_large_patch16_384', pretrained=True)
model.eval()# 定義圖像預處理轉換,注意輸入尺寸為 384x384
transform = transforms.Compose([transforms.Resize(384),transforms.CenterCrop(384),transforms.ToTensor(),transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])# 加載圖像
image = Image.open('path_to_your_image.jpg')
image = transform(image).unsqueeze(0)# 進行推理
with torch.no_grad():output = model(image)# 獲取預測結果
_, predicted_idx = torch.max(output, 1)
print(f"DeiT-3 large Predicted class index: {predicted_idx.item()}")
4.2.4 RepViT-M2 模型
import torch
import timm
from PIL import Image
from torchvision import transforms# 加載預訓練的 RepViT-M2 模型
model = timm.create_model('repvit_m2', pretrained=True)
model.eval()# 定義圖像預處理轉換
transform = transforms.Compose([transforms.Resize(256),transforms.CenterCrop(224),transforms.ToTensor(),transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])# 加載圖像
image = Image.open('path_to_your_image.jpg')
image = transform(image).unsqueeze(0)# 進行推理
with torch.no_grad():output = model(image)# 獲取預測結果
_, predicted_idx = torch.max(output, 1)
print(f"RepViT-M2 Predicted class index: {predicted_idx.item()}")
4.2.5 ResNet-RS-101
import torch
import timm
from PIL import Image
from torchvision import transforms# 加載預訓練的 ResNet-RS-101 模型
model = timm.create_model('resnetrs101', pretrained=True)
model.eval()# 定義圖像預處理轉換
transform = transforms.Compose([transforms.Resize(256),transforms.CenterCrop(224),transforms.ToTensor(),transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])# 加載圖像
image = Image.open('path_to_your_image.jpg')
image = transform(image).unsqueeze(0)# 進行推理
with torch.no_grad():output = model(image)# 獲取預測結果
_, predicted_idx = torch.max(output, 1)
print(f"ResNet-RS-101 Predicted class index: {predicted_idx.item()}")
4.2.6 Vision Transformer (ViT)
import torch
import timm
from PIL import Image
from torchvision import transforms# 加載預訓練的 ViT-Base/32 模型
model = timm.create_model('vit_base_patch32_224', pretrained=True)
model.eval()# 定義圖像預處理轉換
transform = transforms.Compose([transforms.Resize(256),transforms.CenterCrop(224),transforms.ToTensor(),transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])# 加載圖像
image = Image.open('path_to_your_image.jpg')
image = transform(image).unsqueeze(0)# 進行推理
with torch.no_grad():output = model(image)# 獲取預測結果
_, predicted_idx = torch.max(output, 1)
print(f"ViT-Base/32 Predicted class index: {predicted_idx.item()}")
4.2.7 Swin Transformer
import torch
import timm
from PIL import Image
from torchvision import transforms# 加載預訓練的 Swin Transformer 模型
model = timm.create_model('swin_base_patch4_window7_224', pretrained=True)
model.eval()# 定義圖像預處理轉換
transform = transforms.Compose([transforms.Resize(256),transforms.CenterCrop(224),transforms.ToTensor(),transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])# 加載圖像
image = Image.open('path_to_your_image.jpg')
image = transform(image).unsqueeze(0)# 進行推理
with torch.no_grad():output = model(image)# 獲取預測結果
_, predicted_idx = torch.max(output, 1)
print(f"Swin Transformer Predicted class index: {predicted_idx.item()}")
4.2.8 Swin Transformer V2
import torch
import timm
from PIL import Image
from torchvision import transforms# 加載預訓練的 Swin Transformer V2 模型
model = timm.create_model('swinv2_base_window12_192_22k', pretrained=True)
model.eval()# 定義圖像預處理轉換
transform = transforms.Compose([transforms.Resize(256),transforms.CenterCrop(224),transforms.ToTensor(),transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])# 加載圖像
image = Image.open('path_to_your_image.jpg')
image = transform(image).unsqueeze(0)# 進行推理
with torch.no_grad():output = model(image)# 獲取預測結果
_, predicted_idx = torch.max(output, 1)
print(f"Swin Transformer V2 Predicted class index: {predicted_idx.item()}")
4.2.9 Swin Transformer V2 Cr
import torch
import timm
from PIL import Image
from torchvision import transforms# 加載預訓練的 Swin Transformer V2 Cr 模型
model = timm.create_model('swinv2_cr_base_224', pretrained=True)
model.eval()# 定義圖像預處理轉換
transform = transforms.Compose([transforms.Resize(256),transforms.CenterCrop(224),transforms.ToTensor(),transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])# 加載圖像
image = Image.open('path_to_your_image.jpg')
image = transform(image).unsqueeze(0)# 進行推理
with torch.no_grad():output = model(image)# 獲取預測結果
_, predicted_idx = torch.max(output, 1)
print(f"Swin Transformer V2 Cr Predicted class index: {predicted_idx.item()}")
4.2.10 Levit
import torch
import timm
from PIL import Image
from torchvision import transforms# 加載預訓練的 Levit 模型
model = timm.create_model('levit_256', pretrained=True)
model.eval()# 定義圖像預處理轉換
transform = transforms.Compose([transforms.Resize(256),transforms.CenterCrop(224),transforms.ToTensor(),transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])# 加載圖像
image = Image.open('path_to_your_image.jpg')
image = transform(image).unsqueeze(0)# 進行推理
with torch.no_grad():output = model(image)# 獲取預測結果
_, predicted_idx = torch.max(output, 1)
print(f"Levit Predicted class index: {predicted_idx.item()}")

4.3 加載自定義模型

如果你需要加載自定義的模型,可以使用 timm.create_model 函數,并指定模型的名稱和相關參數:

import timm# 創建自定義的 EfficientNet 模型
model = timm.create_model('efficientnet_b0', pretrained=False, num_classes=10)
print(model)

4.4 提取模型的中間特征

import torch
import timm# 加載預訓練的模型
model = timm.create_model('resnet18', pretrained=True, features_only=True)# 生成隨機輸入
x = torch.randn(1, 3, 224, 224)# 提取中間特征
features = model(x)
for i, feat in enumerate(features):print(f"Feature {i} shape: {feat.shape}")

4.5 凍結模型的部分層

import torch
import timm
from timm.utils.model import freeze# 加載預訓練的模型
model = timm.create_model('resnet18', pretrained=True)# 凍結模型的前幾層
submodules = [n for n, _ in model.named_children()]
freeze(model, submodules[:submodules.index('layer2') + 1])# 檢查凍結情況
print(model.layer2[0].conv1.weight.requires_grad)  # 輸出: False
print(model.layer3[0].conv1.weight.requires_grad)  # 輸出: True

在使用 timm 庫加載預訓練模型后,我們經常需要根據具體的任務需求調整模型的參數,例如輸入圖像尺寸、輸出分類個數等。下面將結合提供的代碼片段詳細介紹如何進行這些參數的調整。

4.6 創建模型時指定輸入圖像尺寸

部分模型在創建時可以通過 img_size 參數指定輸入圖像的尺寸。以下是一個使用 SwinTransformer 模型的示例:

import timm
import torch# 加載預訓練的 SwinTransformer 模型,并指定輸入圖像尺寸為 384x384
model = timm.create_model('swin_base_patch4_window7_224', pretrained=True, img_size=(384, 384))
model.eval()# 隨機生成一個符合指定尺寸的輸入張量進行測試
input_tensor = torch.randn(1, 3, 384, 384)
with torch.no_grad():output = model(input_tensor)
print("Output shape:", output.shape)

在上述代碼中,我們通過 img_size=(384, 384) 指定了輸入圖像的尺寸為 384x384。

4.7 數據預處理階段調整圖像尺寸

除了在創建模型時指定輸入圖像尺寸,還需要在數據預處理階段將輸入圖像調整為指定的尺寸。可以使用 torchvision.transforms 來實現這一點,示例如下:

from torchvision import transforms
from PIL import Image# 定義圖像預處理轉換,將圖像調整為 384x384
transform = transforms.Compose([transforms.Resize((384, 384)),transforms.ToTensor(),transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])# 加載圖像
image = Image.open('path_to_your_image.jpg')
image = transform(image).unsqueeze(0)# 進行推理
with torch.no_grad():output = model(image)
print("Output shape:", output.shape)

在這個示例中,我們使用 transforms.Resize((384, 384)) 將輸入圖像調整為 384x384 的尺寸。

4.8 調整輸出分類個數

輸出分類個數的調整通常在創建模型時通過 num_classes 參數來實現。以下是一個使用 MetaFormer 模型的示例:

import timm# 加載預訓練的 MetaFormer 模型,并指定輸出分類個數為 10
model = timm.create_model('metaformer', pretrained=True, num_classes=10)
model.eval()# 隨機生成一個輸入張量進行測試
input_tensor = torch.randn(1, 3, 224, 224)
with torch.no_grad():output = model(input_tensor)
print("Output shape:", output.shape)

在上述代碼中,我們通過 num_classes=10 指定了模型的輸出分類個數為 10。

4.9 綜合示例

下面是一個綜合示例,展示了如何同時調整輸入圖像尺寸和輸出分類個數:

import timm
import torch
from torchvision import transforms
from PIL import Image# 加載預訓練的 SwinTransformer 模型,調整輸入圖像尺寸為 384x384,輸出分類個數為 10
model = timm.create_model('swin_base_patch4_window7_224', pretrained=True, img_size=(384, 384), num_classes=10)
model.eval()# 定義圖像預處理轉換,將圖像調整為 384x384
transform = transforms.Compose([transforms.Resize((384, 384)),transforms.ToTensor(),transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])# 加載圖像
image = Image.open('path_to_your_image.jpg')
image = transform(image).unsqueeze(0)# 進行推理
with torch.no_grad():output = model(image)
print("Output shape:", output.shape)

在這個綜合示例中,我們同時調整了輸入圖像尺寸和輸出分類個數,并進行了圖像預處理和推理操作。

通過以上方法,我們可以根據具體的任務需求靈活調整預訓練模型的輸入圖像尺寸和輸出分類個數。

更多模型說明

除了上述示例中的模型,timm 庫還包含了許多其他的模型,如 Aggregating Nested Transformers、BEiT、Big Transfer ResNetV2 (BiT) 等。你可以在 timm 的官方文檔 https://huggingface.co/docs/timm 中找到完整的模型列表。

要使用其他模型,只需將 timm.create_model 函數中的模型名稱替換為你想要使用的模型名稱即可。例如,要使用 BEiT 模型,可以使用以下代碼:

import torch
import timm
from PIL import Image
from torchvision import transforms# 加載預訓練的 BEiT 模型
model = timm.create_model('beit_base_patch16_224', pretrained=True)
model.eval()# 定義圖像預處理轉換
transform = transforms.Compose([transforms.Resize(256),transforms.CenterCrop(224),transforms.ToTensor(),transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])# 加載圖像
image = Image.open('path_to_your_image.jpg')
image = transform(image).unsqueeze(0)# 進行推理
with torch.no_grad():output = model(image)# 獲取預測結果
_, predicted_idx = torch.max(output, 1)
print(f"BEiT Predicted class index: {predicted_idx.item()}")

五、timm 庫近期更新

5.1 2025 年 2 月 21 日更新

  • 新增 SigLIP 2 ViT 圖像編碼器:可從 https://huggingface.co/collections/timm/siglip-2-67b8e72ba08b09dd97aecaf9 獲取。
  • 新增 ‘SO150M2’ ViT 權重:使用 SBB 配方訓練,在 ImageNet 上取得了很好的效果。例如,vit_so150m2_patch16_reg1_gap_448.sbb_e200_in12k_ft_in1k 的 top-1 準確率達到 88.1%。
  • 更新 InternViT - 300M ‘2.5’ 權重
  • 發布 1.0.15 版本

5.2 其他更新

在 2025 年 1 月至 2024 年 10 月期間,timm 庫還進行了許多其他更新,包括添加新的優化器(如 Kron Optimizer、MARS 優化器等)、支持新的模型(如 convnext_nano、AIM - v2 編碼器等)、修復一些 bug 以及改進代碼結構等。

六、分布式訓練支持

timm 庫還提供了分布式訓練的支持,相關代碼在 timm/utils/distributed.py 中。以下是一些關鍵函數的介紹:

  • reduce_tensor:用于在分布式環境中對張量進行規約操作。
  • distribute_bn:確保每個節點具有相同的運行時 BN 統計信息。
  • init_distributed_device:初始化分布式訓練設備。

以下是一個簡單的分布式訓練初始化示例:

import torch
from timm.utils.distributed import init_distributed_deviceargs = type('', (), {})()  # 創建一個空的參數對象
device = init_distributed_device(args)
print(f"Device: {device}, World size: {args.world_size}, Rank: {args.rank}")

七、學習率調度器

timm 庫提供了多種學習率調度器,可在 timm/scheduler 目錄下找到相關代碼。以下是一些常見的調度器及其使用示例:

7.1 余弦退火調度器(CosineLRScheduler)

import torch
import timm
from timm.scheduler.scheduler_factory import create_scheduler# 定義優化器
optimizer = torch.optim.SGD(model.parameters(), lr=0.01)# 定義調度器參數
scheduler_args = type('', (), {'sched': 'cosine','epochs': 100,'decay_epochs': 30,'warmup_epochs': 5
})()# 創建調度器
scheduler, num_epochs = create_scheduler(scheduler_args, optimizer)# 訓練循環
for epoch in range(num_epochs):# 訓練代碼...scheduler.step(epoch)

7.2 多步學習率調度器(MultiStepLRScheduler)

import torch
import timm
from timm.scheduler.scheduler_factory import create_scheduler# 定義優化器
optimizer = torch.optim.SGD(model.parameters(), lr=0.01)# 定義調度器參數
scheduler_args = type('', (), {'sched': 'multistep','epochs': 100,'decay_milestones': [30, 60],'decay_rate': 0.1,'warmup_epochs': 5
})()# 創建調度器
scheduler, num_epochs = create_scheduler(scheduler_args, optimizer)# 訓練循環
for epoch in range(num_epochs):# 訓練代碼...scheduler.step(epoch)

八、總結

PyTorch Image Models (timm) 是一個非常實用的圖像模型庫,它提供了豐富的預訓練模型和便捷的使用接口,同時支持分布式訓練和多種學習率調度器。通過本文的介紹,你可以快速上手 timm 庫,進行圖像分類等任務的開發。希望本文對你有所幫助,祝你在深度學習領域取得更好的成果!

九、參考資料

  • timm 官方文檔:https://huggingface.co/docs/timm
  • timm 代碼庫:https://github.com/rwightman/pytorch-image-models

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/82933.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/82933.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/82933.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

openEuler安裝MySql8(tar包模式)

操作系統版本: openEuler release 22.03 (LTS-SP4) MySql版本: 下載地址: https://dev.mysql.com/downloads/mysql/ 準備安裝: 關閉防火墻: 停止防火墻 #systemctl stop firewalld.service 關閉防火墻 #systemc…

從零開始的數據結構教程(六) 貪心算法

🍬 標題一:貪心核心思想——發糖果時的最優分配策略 貪心算法 (Greedy Algorithm) 是一種簡單直觀的算法策略。它在每一步選擇中都采取在當前狀態下最好或最優(即最有利)的選擇,從而希望得到一個全局最優解。這就像你…

CPP中CAS std::chrono 信號量與Any類的手動實現

前言 CAS(Compare and Swap) 是一種用于多線程同步的原子指令。它通過比較和交換操作來確保數據的一致性和線程安全性。CAS操作涉及三個操作數:內存位置V、預期值E和新值U。當且僅當內存位置V的值與預期值E相等時,CAS才會將內存位…

Axure設計案例——科技感對比柱狀圖

想讓數據對比展示擺脫平淡無奇,瞬間抓住觀眾的眼球嗎?那就來看看這個Axure設計的科技感對比柱狀圖案例!科技感設計風格運用獨特元素打破傳統對比柱狀圖的常規,營造出一種極具沖擊力的視覺氛圍。每一組柱狀體都仿佛是科技戰場上的士…

怒更一波免費聲音克隆和AI配音功能

寶子們! 最近咱軟件TransDuck的免費聲音克隆和AI配音功能被大家用爆啦!感謝各位自來水瘋狂安利!! DD這里也是收到好多用戶提的寶貴建議!所以,連夜肝了波更新! 這次重點更新使用克隆音色進行A…

UDP協議原理與Java編程實戰:無連接通信的奧秘

1.UDP協議核心原理 1. 無連接特性:快速通信的基石 UDP(User Datagram Protocol,用戶數據報協議)是TCP/IP協議族中無連接的輕量級傳輸層協議。與TCP的“三次握手”建立連接不同,UDP通信無需提前建立鏈路,發送…

vue-seamless-scroll 結束從頭開始,加延時后滾動

今天遇到一個大屏需求: 1??初始進入頁面停留5秒,然后開始滾動 2??最后一條數據出現在最后一行時候暫停5秒,然后返回1?? 依次循環,發現vue-seamless-scroll的方法 ScrollEnd是監測最后一條數據消失在第一行才回調&#xff…

[Protobuf] 快速上手:安全高效的序列化指南

標題:[Protobuf] (1)快速上手 水墨不寫bug 文章目錄 一、什么是protobuf?二、protobuf的特點三、使用protobuf的過程?1、定義消息格式(.proto文件)(1)指定語法版本(2)package 聲明符 2、使用protoc編譯器生成代碼&…

uniapp調用java接口 跨域問題

前言 之前在Windows10本地 調試一個舊項目,手機移動端用的是Uni-app,vue的版本是v2。后端是java spring-boot。運行手機移動端的首頁請求后臺接口老是提示錯誤信息。 錯誤信息如下: Access to XMLHttpRequest at http://localhost:8080/api/…

[ Qt ] | Qlabel使用

目錄 屬性 setTextFormat 插入圖片 設置圖片根據窗口大小實時變化 邊框和對其方式 ?編輯 設置縮進 設置伙伴 Qlabel可以用來顯式圖片和文字 屬性 text textFormat Qlabel獨有的機制:buddy setTextFormat 插入圖片 設置圖片根據窗口大小實時變化 Qt中表…

Springboot 項目一啟動就獲取HttpSession

在 Spring Boot 項目中,HttpSession 是有狀態的,通常只有在用戶發起 HTTP 請求并建立會話后才會創建。因此,在項目啟動時(即應用剛啟動還未處理任何請求)是無法獲取到 HttpSession 的。 方法一:使用 HttpS…

Step9—Ambari Web UI 初始化安裝 (Ambari3.0.0)

Ambari Web UI 安裝 如果還不會系統性的部署,或者前置內容不熟悉,建議從Step1 開始閱讀。不通版本針對于不同操作系統可能存在差異!這里我也整理好了 https://doc.janettr.com/install/manual/ 1. 進入 Ambari Web UI 并登錄 在瀏覽器中訪…

熱門大型語言模型(LLM)應用開發框架

我們來深入探索這些強大的大型語言模型(LLM)應用開發框架,并且我會嘗試用文本形式描述一些核心的流程圖,幫助您更好地理解它們的工作機制。由于我無法直接生成圖片,我會用文字清晰地描述流程圖的各個步驟和連接。 Lang…

機器學習數據降維方法

1.數據類型 2.如何選擇降維方法進行數據降維 3.線性降維:主成分分析(PCA)、線性判別分析(LDA) 4.非線性降維 5.基于特征選擇的降維 6.基于神經網絡的降維 數據降維是將高維數據轉換為低維表示的過程,旨在保…

太陽系運行模擬程序-html動畫

太陽系運行模擬程序-html動畫 by AI: <!DOCTYPE html> <html lang"zh"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>交互式太陽系…

2025年全國青少年信息素養大賽 scratch圖形化編程挑戰賽 小低組初賽 內部集訓模擬題解析

2025年信息素養大賽初賽scratch模擬題解析 博主推薦 所有考級比賽學習相關資料合集【推薦收藏】 scratch資料 Scratch3.0系列視頻課程資料零基礎學習scratch3.0【入門教學 免費】零基礎學習scratch3.0【視頻教程 114節 免費】 歷屆藍橋杯scratch國賽真題解析歷屆藍橋杯scr…

grid網格布局

使用flex布局的痛點 如果使用justify-content: space-between;讓子元素兩端對齊&#xff0c;自動分配中間間距&#xff0c;假設一行4個&#xff0c;如果每一行都是4的倍數那沒任何問題&#xff0c;但如果最后一行是2、3個的時候就會出現下面的狀況&#xff1a; /* flex布局 兩…

通義靈碼2.5——基于MCP實現我的12306火車票智能查詢小助手

本文因排版顯示問題&#xff0c;為保證閱讀體驗&#xff0c;請大家訪問&#xff1a; 通義靈碼2.5——基于MCP打造我的12306火車票智能查詢小助手-CSDN博客 前沿技術應用全景圖 本項目作為通義靈碼2.5的標桿實踐案例&#xff0c;展現了AI輔助開發在復雜業務系統中的革命性突破…

Unity Button 交互動畫

在UGUI的Button組件中&#xff0c;有一個過渡動畫表現的功能。可以對按鈕的不同交互狀態添加交互反饋動畫&#xff0c;來提高玩家的交互體驗。 交互狀態 名稱 描述 Normal 正常情況 Highlighted 高亮顯示&#xff0c;例如鼠標觸碰到按鈕點擊范圍 Pressed 按鈕被按下的時…

釘釘熱點實時推送助理-思路篇

以下是針對熱點實時推送助理的功能描述&#xff0c;結合機器學習技術棧與用戶場景的通俗化解釋&#xff1a; 快速體驗的話直接用釘釘掃描下方二維碼體驗 1. 核心功能 &#xff08;1&#xff09;熱點抓取引擎 類比&#xff1a;像蜘蛛爬取全網信息&#xff08;網絡爬蟲信息抽取…